[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: gremlin in lua
- From: "Robert G. Jakabosky" <bobby@...>
- Date: Sat, 3 Mar 2012 19:46:09 -0800
On Saturday 03, Jak Sprats wrote:
> Hi Lua mailing list,
>
> I used Lua to create a GraphDB within my experimental DB, here is a
> writeup:
> http://jaksprats.wordpress.com/2012/02/28/lightweight-oltp-data-platform/
>
> I want to add support for the graph traversal language Gremlin:
> https://github.com/tinkerpop/gremlin/wiki
>
> The following:
> g.v(1).out('knows').filter{it.age < 30}
> is a gremlin traversal, that
> 1.) starts at node1
> 2.) finds all outgoing nodes w/ relationship 'knows'
> 3.) and then filters, them returning only those w/ attribute 'age' less
> than 30
>
> Being clever w/ __index, __newindex, & __call, I can figure out how to turn
> this nested table call into a series of graph function traversal
> directives. The part that I can not figure out, & may not be possible in
> Lua, is the handling of the closure '{it.age < 30}'. This closure is
> denoted by '{}' which I do not believe is overridable in Lua, and the
> contents 'it.age < 30' contains real code, so they need to be evaluated.
>
> Is there any magic that can turn '{it.age < 30}' into something like
> 'function step_3(it) return it.age < 30; end'
>
> I dont think there is.
No. The value returned by the comparison meta methods (__lt, __le, __eq) is
converted to a boolean value. Also the type of the two operands need to be
the same.
> If there is not, does anyone have any suggestions on how to best implement
> a minimally modified Gremlin syntax that would fit smoothly into Lua's
> syntax
filter{ it.age '<' '30' }
or
filter{ it.age, '<', 30 }
Also take a look at LPeg [1] for more ideas on syntax.
1. http://www.inf.puc-rio.br/~roberto/lpeg/
--
Robert G. Jakabosky