[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lightweight function syntax: no need to change Lua
- From: Romulo <romuloab@...>
- Date: Mon, 29 Nov 2010 00:10:28 -0200
But then, the whole discussion of being short, concise and elegant
falls apart. There is no much point to type a lot, have performance
penalties and look weird all at the same time (unless you are Java).
On 11/28/10, RJ Russell <russellsprouts2@gmail.com> wrote:
> On Sun, Nov 28, 2010 at 12:42 AM, David Kastrup <dak@gnu.org> wrote:
>> Dirk Laurie <dpl@sun.ac.za> writes:
>>
>>> The following syntax:
>>>
>>> ('a,b,c')('a+b+c') == function(a,b,c) return a+b+c end
>>>
>>> is available after doing this chunk:
>>>
>>> getmetatable("").__call =
>>> function(arg,res)
>>> if #arg>0 then return load(arg.."=...; return "..res)
>>> else return load("return "..res)
>>> end
>>> end
>>>
>>> Dirk
>>> (Apologies if someone has already pointed out this obvious trick.
>>> I started reading the discussion somewhere in the middle.)
>>
>> It won't exactly work well in the context of closures.
>>
>> --
>> David Kastrup
>>
>>
>>
>
> It could work in 5.2 though, right?
>
> If we use the debug library upvaluejoin function.
> I don't have Lua 5.2 compiled on hand, so I can't test it, but I think
> that that will work.
> We might have to do this:
> function test()
> local d=56
> return ('a,b,c')(_ENV,'print(a,b,c,d)')
> end
> test()(1,2,3)-->should print 1,2,3,56
>
>
--
Sent from my mobile device