Google 그룹스는 더 이상 새로운 유즈넷 게시물 또는 구독을 지원하지 않습니다. 과거의 콘텐츠는 계속 볼 수 있습니다.

Slight inconsistency

조회수 11회
읽지 않은 첫 메시지로 건너뛰기

Tom Neff

읽지 않음,
1990. 4. 23. 오후 10:18:4990. 4. 23.
받는사람
This compiles:

print ()[0];

This doesn't:

print '-',()[0];

Any idea why?

Brandon S. Allbery KB8JRR

읽지 않음,
1990. 4. 25. 오후 7:19:1190. 4. 25.
받는사람
As quoted from <15...@bfmny0.UU.NET> by tn...@bfmny0.UU.NET (Tom Neff):
+---------------

| This compiles: print ()[0];
| This doesn't: print '-',()[0];
+---------------

It's the usual... the former is parsed as (print())[0], the latter as
(print(('-'),(()[0]))). The latter contains (()[0]), which is obviously
not a sensible expression.

Remember that operations like "print" are parsed as functions with optional
parentheses about the argument list. So "print ()" is parsed as "print" with
an empty argument list, i.e. no arguments. "print ()" == "(print)".

++Brandon
--
Brandon S. Allbery KB8JRR, all...@NCoast.ORG (Internet), BALLBERY (MCI Mail)
ALLBERY (Delphi), uunet!cwjcc.cwru.edu!ncoast!allbery (UUCP), BrandonA (A-OL)

Larry Wall

읽지 않음,
1990. 4. 25. 오후 12:20:3090. 4. 25.
받는사람
In article <15...@bfmny0.UU.NET> tn...@bfmny0.UU.NET (Tom Neff) writes:
: This compiles:

How 'bout, 'cuz the syntax doesn't all subscripting a null list? The
first one happens to compile because a print () is transmogrified by
the tokener into a (print), so it looks to the parser like

(print)[0];

There are probably better ways to do that, but it would make the parser
more complex. I do, occasionally, struggle feebly against complexity... :-)

Larry

새 메시지 0개