[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [Proposal] Lua-y lambda syntax
- From: steve donovan <steve.j.donovan@...>
- Date: Sat, 29 Apr 2017 09:02:30 +0200
On Sat, Apr 29, 2017 at 1:36 AM, Jay Carlson <nop@nop.com> wrote:
> My favorite method (but alas the one I use least) is to parse a string at runtime and turn it into a Lua function. So taking the Wikipedia LINQ C# example, it would look something like:
>
> results = linq[[
> from c in SomeCollection
> where c.SomeProperty < 10
> select new {c.SomeProperty, c.OtherProperty} ]]
>
> for result in ipairs(results) do
> print(result)
> end
I did something like this for constructing queries for columnar data:
http://stevedonovan.github.io/Penlight/api/manual/06-data.md.html#Reading_Columnar_Data
(see the examples for pl.data)
The trick was to convert the pseudo-SQL into equivalent Lua, which is
then loaded. Gotta love eval() in all its forms ;)
As for macros, I was a believer. But experience suggests that ad-hoc
syntax has to be very carefully designed - harder than writing good
libraries. Design sense is relatively rare in the universe.