At 3:24 AM +0000 12/12/02, Simon Cozens wrote:
It's even more interesting when you add function calls into things, like:[EMAIL PROTECTED] (Deborah Ariel Pickett) writes: > Can we dictate that parentheses are optional in this case, and demandparentheses in all others?You see, the problem is that if we don't know what method we're going to call until way after we've parsed the code, (which I hope we've just proved above) we don't know how many parameters it's going to take. And if we don't know how many parameters it's going to take until we run it, we have next to zero chance of working out how many parameters it's going to take when we compile it. Which was the basis of my semi-serious notion of caching the whole set of possible parses.
$foo = bar $x, $y, foo();
Since that may be either:
$foo = bar($x, $y), foo()
in which case it's in scalar context, or
$foo = bar($x, $y, foo())
in which case it's in list context (sort of)
The fun thing is that, potentially, you need to actually *call* foo() to figure out what context to call foo in. (Since, depending on what it returns, you may dispatch to different bar subs, which may or may not actually need what foo returns, thus changing its context)
Ruby blocks that get passed to functions can only appear in a few well-known places, and always at the end of the parameter list. (Something's twigging my brain to make me think that the syntax for those blocks is distinct enough to tell at compile time what block type it is, but it's late and I may be mis-remembering) It still can't handle the infix block stuff that sort/map/grep want.Except that this all sprung from my idea of having a block passed directly to a method without the other arguments being involved. (Which would work without parens, optional or otherwise. (because it works exactly this way in languages like Ruby (but most Perl 5 people can't get their heads around that (which is why this idea is facing a dead end.))))
Still, since all blocks are closures, it's not actually a problem for parrot, since this:
foo $x, $y, {some_code()};
isn't a big deal--the only question is whether we pass in the PMC for that closure to foo, or call it and pass in the results. (Or, I suppose, figure out whether foo should do something bizarrely multimethod)
--
Dan
--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
[EMAIL PROTECTED] have teddy bears and even
teddy bears get drunk