print ()[0];
This doesn't:
print '-',()[0];
Any idea why?
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)
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