lua-users home
lua-l archive

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


On Tue, Apr 28, 2015 at 11:43 AM, Coda Highland <chighland@gmail.com> wrote:
> On Tue, Apr 28, 2015 at 9:26 AM, Javier Guerra Giraldez
> <javier@guerrag.com> wrote:
>> On Tue, Apr 28, 2015 at 10:44 AM, Coda Highland <chighland@gmail.com> wrote:
>>> Speaking of meta-programming: There's always the option to introduce
>>> try/catch/end syntax in a preprocessor. :P
>>
>> it's also very doable with anonymous functions (untested, and might be
>> better with xpcall):
>>
>> local function onrets(catch, ok, res1, ...)
>>    if ok then
>>       return res1, ...
>>    else
>>       return catch(res1)
>>    end
>> end
>>
>> function try(f,catch)
>>    return onrets(catch, pcall(f()))
>> end
>>
>>
>> ----- use as:
>>
>> try(function()
>>
>>     -- this is the 'try' part
>>
>> end,function(err)
>>
>>     -- and on any error, this will be called
>>
>> end)
>>
>>
>> if the 'try' part returns successfully, this will return all its
>> values.  if it signals an error, the 'catch' part is called.  any
>> returns from the catch part would be passed to the original caller, if
>> it signals a new error, it would be propagated out of the whole
>> expression.
>>
>> --
>> Javier
>>
>
> Sure, something like that was my assumption as to what the syntax
> would expand into after preprocessing, or perhaps inlined instead of
> wrapped through another function to reduce the overhead a little bit.
>
> /s/ Adam
>
[appoligies for off-topic comment]

I really like the macro approach because as a side (or perhaps the
primary) benefit: you'd have macros[1]

I currently believe that an integrated macro library, written with the
same wisdom and care that Lua was authored with, is the most exciting
possibility for future Lua.

It is vaccination the inevitable death march towards Language
Bloat.[2]  Lua has avoided this thanks to the development model.
However, perhaps PUC/Rio could ensure their legacy by providing us
with macros before they retire. :)

-Andrew

[1] I need to become familiar with LuaMacro. However, a macro is such
an important dependency and I hesitate to add one that is not in
extremely wide use. I also hold out hope for a more integrated /
blessed solution, but LuaMacro still remains on my "todo" list.

[2] Related: All DSLs evolve into Turing-Complete Crap.
I'm not sure what the pithy "All Languages evolve into..." equivalent
would be...