in reply to logic behind the print function
The original poster is, it seems, confused by two things: first, that the result of a (successful) print is 1, and not the thing printed. Second, that the parentheses around (5+2) delimit the arguments sent to the inner 'print' call. Both of these are obvious to more seasoned Perl programmers, but not to newbies.
It is my irreverent but humble duty to report that Perl 6 'fixes' the second of these points of confusion, by having print(5+2) and print (5+2) (note the space) mean different things. In the first instance, (5+2) is parsed as an argument list with one argument, 5+2. In the second instance, because of the space after print, the parser expects a non-parenthesized list of arguments, and finds (5+2)+10.
So, a Perl 6 inplementation prints "171": "17" for the correct result of the calculation (5+2)+10, and "1" for the outer print of the return value of the inner print.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: logic behind the print function
by masak (Scribe) on Dec 29, 2009 at 16:24 UTC |