[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lightweight function syntax (again) Re: [ANN] Lua 5.2.0 (alpha-rc2) now available
- From: Antonio Vieiro <antonio@...>
- Date: Mon, 22 Nov 2010 21:26:26 +0100
I'm sorry I missed this thread. What's this about? I see all this
complex and superfluous, isn't it? Is it a contest to make things more
difficult to understand? We have Perl for that, haven't we?
I do like the way things works in Lua.
In fact I'd prefer using parenthesis even for single arguments, so I'd
rather write print("Hello") instead of print "Hello". It's easier to
parse as well.
2010/11/21 Mark Hamburg <firstname.lastname@example.org>:
> On Nov 20, 2010, at 5:18 AM, Pierre-Yves Gérardy wrote:
>> My favourite syntax so far is
>> @[ a,b => a+b ]
>> @[; dostuff() ]
> That's probably one of the best proposed syntaxes I've seen to date.
> A C# inspired possibility but I haven't checked the grammar is:
> ( arg list ) => expression
> ( arg list ) => do statements end
> Though in that case, we could presumably also use the | token and avoid syntactic ambiguity:
> | arg list | expression
> | arg list | do statements end
> I agree that 'function' gets a bit too heavy weight visually when trying to do more functional-ish programming. (I've been digging into reactive frameworks lately.) But in any of these cases, we need to figure out syntactic precedence. I would guess that it would sit at about the same level as table construction.
> The other feature needed is treating these like tables and strings and allowing them to be used for parenthesis free function calling:
> myStream:map @[ x => x * x ]
> :filter @[ x => x % 2 == 0 ]
> :subscribe @[ x => do
> total = total + x
> log:writef( "%d %d", x, total )
> end ]
> That example, however, leads to the question: Where was 'total' declared and initialized?
> Finally, in any of these use cases, it's worth remembering the distinction between blocks and functions when it comes to return and break. This is something that Smalltalk and I think Ruby dealt with but other languages only stumble onto later. (Smalltalk has two return operators. One returns a value from the block. The other returns from the context in which the block was created.) Any Lua solution should probably try to guide people toward thinking of these as lightweight functions rather than as blocks of code.