[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: gremlin in lua
- From: Xavier Wang <weasley.wx@...>
- Date: Sun, 4 Mar 2012 17:09:31 +0800
what about this:
g:v(1):out('knows'):filter [[age < 30]]
use : to replace . to get native lua OO support, and pass a string to
filter, in a filter you can do this:
function filter(self, chunk)
local f = assert(load("return function(_ENV) return "..chunk.."end"))()
-- used like this:
-- if f(it) then ... end
end
2012/3/4 Jak Sprats <jaksprats@gmail.com>:
> 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.
>
> 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
>
> thanks,
> jak
>
>