The $_g reserved variable

4 views
Skip to first unread message

Marko A. Rodriguez

unread,
Jan 3, 2010, 1:04:57 PM1/3/10
to gremli...@googlegroups.com
Hi everyone,

The Gremlin function library comes with a set of graph functions [ http://wiki.github.com/tinkerpop/gremlin/gremlin-function-library#graph_functions ]. All of these graph functions require the first argument to be a graph object. In order to make the call to these functions more concise, I have created a new reserved variable called $_g. This variable can only be set to an object that implement the Graph.java interface.

Now, this $_g variable can be assigned a graph and in such cases, it is not required to provide a graph parameter to any graph functions in the Gremlin function library or elsewhere (e.g. Sesame function library). Here are some examples of how it works:

         \,,,/
         (o o)
-----oOOo-(_)-oOOo-----
gremlin> $_g := tg:open()
==>tinkergraph[vertices:0]
gremlin> g:load('src/test/resources/com/tinkerpop/gremlin/model/parser/graph-example-1.xml')
==>true
gremlin> $_ := g:id('1')
==>v[1]
gremlin> $v := g:key('name','marko')[1]
==>v[1]
gremlin> g:add-v()
==>v[0]
gremlin> g:add-v()
==>v[7]
gremlin> $_g/V
==>v[3]
==>v[2]
==>v[1]
==>v[0]
==>v[7]
==>v[6]
==>v[5]
==>v[4]
gremlin> g:add-e(g:add-v(), 'respects', g:add-v())
==>e[10][8-respects->9]
gremlin> $_g/E
==>e[7][1-knows->2]
==>e[9][1-created->3]
==>e[8][1-knows->4]
==>e[12][6-created->3]
==>e[10][4-created->5]
==>e[11][4-created->3]
==>e[10][8-respects->9]
gremlin> g:clear()
==>true
gremlin> $_g
==>tinkergraph[vertices:0]
gremlin> 


Finally, I added the reserved variable to the wiki Cheat Sheet [ http://wiki.github.com/tinkerpop/gremlin/cheat-sheet ].

Hopefully this makes it "cleaner" to code in Gremlin.

Take care,
Marko.

Reply all
Reply to author
Forward
0 new messages