lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Nov 21, 2010 at 4:52 PM, Mark Hamburg <mark@grubmah.com> wrote:
> On Nov 20, 2010, at 5:18 AM, Pierre-Yves Gérardy wrote:
>
>> My favourite syntax so far is
>>
>>    @[ a,b => a+b ]
>>
>> and
>>
>>    @[; 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
>
> And
>
>        ( 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.
>
> Mark

So @[ bla => ble ] would be syntactic sugar for:

   function (bla) return ble end

and @[ bla; ble => bli ] would by syntactic sugar for this?

   function (bla) ble; return bli end

That would be quite nice...

I use Gavin Wraith's patch sometimes
(http://www.wra1th.plus.com/lua/book/rb04.html), mainly because I
understand its implementation completely - it's less than 10 extra
lines added to llex.c - but very few other people seem to like it...

  Cheers,
    Eduardo Ochs
    eduardoochs@gmail.com
    http://angg.twu.net/