[
https://issues.apache.org/jira/browse/TINKERPOP-1232?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15237240#comment-15237240
]
Marko A. Rodriguez commented on TINKERPOP-1232:
-----------------------------------------------
Here is a simple example of how the "String builder"-model would work in a
language (model 3). The language would have a class that has the same method
API as {{GraphTraversal}}, but it concatenates strings. Look how {{repeat()}}
works. Super simple. Thus, the requirement for concatenation and nesting is
provided and we can enable Gremlin (without any JVM interactions) in any
language.
{code}
public class Test {
String s;
public Test(final String source) {
s = source;
}
public Test() {
s = "";
}
public Test V() {
s = s + ".V()";
return this;
}
public Test outE(final String label) {
s = s + ".outE(\"${label}\")";
return this;
}
public Test repeat(final Test test) {
s = s + ".repeat(${test.toString()})";
return this;
}
public String toString() {
return s;
}
}
{code}
In action...
{code}
gremlin> g = new Test("g");
==>g
gremlin> g.V().outE("knows")
==>g.V().outE("knows")
gremlin>
gremlin> g = new Test("g");
==>g
gremlin> g.V().repeat(new Test().outE("knows"))
==>g.V().repeat(.outE("knows"))
gremlin>
{code}
Of course, we would create some sort of {{__}}-static class in the host
language to replace {{new Test()}} so its pretty. Also, we would have to be
smart about {{.}} usage, but this is all simple stuff. The basic idea is there
and it "just works." I suppose that hardest part at this point is, submitting
the traversal. This is where [~spmallette] comes in. Given a Gremlin-Groovy
string traversal, how do I get that to Gremlin Server and get results back?
> Write a tutorial demonstrating the 3 ways to write a Gremlin language variant.
> ------------------------------------------------------------------------------
>
> Key: TINKERPOP-1232
> URL: https://issues.apache.org/jira/browse/TINKERPOP-1232
> Project: TinkerPop
> Issue Type: Improvement
> Components: documentation
> Affects Versions: 3.1.1-incubating
> Reporter: Marko A. Rodriguez
>
> Talking with [~rustyrazorblade] about collaborating on a Gremlin tutorial for
> language designers. Here is what we came up with.
> We will use Python as the host language and demonstrate 3 ways to create
> Gremlin-Python.
> * Using Jython: With Jython you have direct access to the JVM and thus can
> call {{GraphTraversal}} methods directly. We can expose some Python sugar
> here and there to show why its good to have a language specific variant. See
> Gremlin-Scala for inspiration.
> * Using JNI: With Python, we have a {{PythonTraversal}} Python class. That
> class then uses Java Gateway to interact (via proxy) with {{GraphTraversal}}.
> This was done in the past as an experiment with R using rJava.
> * Using String: With Python, we have a {{PythonTraversal}} Python class where
> {{out("knows")}} simply appends {{"out(\"knows\")"}} to a string builder. The
> result can then be a String sent to a {{RemoteConnection}} for evaluation.
> These three models are the three ways in which any language can embed
> Gremlin.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)