At 01:16 PM 1/26/02 -0700, Tom Christiansen wrote: >There is another way to resolve the ambiguity of foo meaning either >"foo" or foo() depending on current subroutine visibility. This >would also extend then to issue of $hash{foo} meaning either >$hash{foo()} or $hash{"foo"}. Just use parens.
I like this. >In my experience, many programmers would prefer that all functions >(perhaps restricted to only those of no arguments to appease >hysterical cetaceans?) mandatorily take (even empty) parens. Count me among the crazed whales/mad dolphins/whatever you were referring to. It would make it easier to explain to beginners the rules for calling functions by eliminating a qualification ("You can leave empty parens off only if perl has already seen a definition or a declaration"), and it wouldn't kill me to put empty parens on argumentless function calls. > % perl -MO=Deparse,-p -e 'push @foo, fred +1, -2' > push(@foo, ('fred' + 1), -2); > >Do you see what I'm talking about? The reader unfamiliar with the >particular context coercion templates of the functions used in code >like > > use SpangleFrob; > frob @foo, spangle +1, -2; > >can have no earthly idea how that will even *parse*. This situation >seems at best, unfortunate. It seems less of a pain than the string/function ambiguity, though. I've been frequently annoyed by having to quote, say -title: start_html('-title' => "Vole Sanctuary") in CGI.pm function calls when everything else is bare, and embarrassed at explaining to readers why. On the other hand, if someone uses SpangleFrob you'd think that they would have a clue how many arguments spangle and frob expected, so they should have less reason to be confused. Usually the worst trouble a programmer gets into by leaving too many parens off is: print join "|", sort @foo, "\n"; On the other other hand, I seem to recall something about how Perl 6 should be easier to parse, and this issue is the poster child for the "Only perl can parse Perl" camp. Does the price of easier parseability have to be "oatmeal mixed with fingernail clippings"? -- Peter Scott Pacific Systems Design Technologies