You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/10/19 21:54:32 UTC

tinkerpop git commit: added the gremlin-groovy-drawing.png to the doc images. Also, added two new sections to gremlin-variants.asciidoc -- Gremlin-Java and Gremlin-Groovy. Will fill out Gremlin-Groovy more over the course of this release.

Repository: tinkerpop
Updated Branches:
  refs/heads/tp32 2b47fa709 -> 3160242bb


added the gremlin-groovy-drawing.png to the doc images. Also, added two new sections to gremlin-variants.asciidoc -- Gremlin-Java and Gremlin-Groovy. Will fill out Gremlin-Groovy more over the course of this release.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/3160242b
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/3160242b
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/3160242b

Branch: refs/heads/tp32
Commit: 3160242bb28187f90359e406738abd2dfa54b248
Parents: 2b47fa7
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 19 15:54:25 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 19 15:54:25 2016 -0600

----------------------------------------------------------------------
 docs/src/reference/gremlin-variants.asciidoc  |  45 +++++++++++++++++++++
 docs/static/images/gremlin-groovy-drawing.png | Bin 0 -> 133892 bytes
 2 files changed, 45 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3160242b/docs/src/reference/gremlin-variants.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index 24c81b5..853b087 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -37,6 +37,51 @@ with Apache TinkerPop. For information on how to build a Gremlin language varian
 please review the link:http://tinkerpop.apache.org/docs/current/tutorials/gremlin-language-variants/[Gremlin Language Variants]
 tutorial.
 
+[[gremlin-java]]
+Gremlin-Java
+------------
+
+image:gremlin-java-drawing.png[width=130,float=right] Apache TinkerPop's Gremlin-Java implements Gremlin within the Java8
+language and can be used by any Java8 compliant virtual machine. Gremlin-Java is considered the canonical, reference
+implementation of Gremlin and serves as the foundation by which all other Gremlin language variants should emulate.
+
+The Lambda Solution
+~~~~~~~~~~~~~~~~~~~
+
+Supporting link:https://en.wikipedia.org/wiki/Anonymous_function[anonymous functions] across languages is difficult as
+most language do not support lambda introspection and thus, code analysis. In Gremlin-Java, Java8 lambdas can be leveraged.
+
+[source,java]
+g.V().out("knows").map(t -> t.get().value("name") + " is the friend name") <1>
+g.V().out("knows").sideEffect(System.out::println) <2>
+g.V().as("a").out("knows").as("b").select("b").by((Function<Vertex, Integer>) v -> v.<String>value("name").length()) <3>
+
+<1> A Java8 function is used to map a `Traverser<S>` to an object `E`.
+<2> Gremlin steps that take consumer arguments can be passed Java8 method references.
+<3> Gremlin-Java may sometimes require explicit lambda typing when types can not be automatically inferred.
+
+When sending traversals over the wire via a `RemoteConnection`, the static methods of `Lambda` should be used
+and should denote a particular JSR-223 `ScriptEngine`. `Lambda` creates a string-based lambda that is then converted
+into a lambda/closure/anonymous-function/etc. by the respective lambda language's JSR-223 `ScriptEngine` implementation.
+
+[source,java]
+g.V().out("knows").map(Lambda.function("it.get().value('name') + ' is the friend name'"))
+g.V().out("knows").sideEffect(Lambda.consumer("println it"))
+g.V().as("a").out("knows").as("b").select("b").by(Lambda.<Vertex,Integer>function("it.value('name').length()"))
+
+[[gremlin-groovy]]
+Gremlin-Groovy
+--------------
+
+image:gremlin-groovy-drawing.png[width=130,float=right] Apache TinkerPop's Gremlin-Groovy implements Gremlin within the
+link:http://groovy.apache.org[Apache Groovy] language. As a JVM-based language variant, Gremlin-Groovy is backed by
+Gremlin-Java constructs. Moreover, given its scripting nature, Gremlin-Groovy serves as the language of
+<<gremlin-console,Gremlin Console>>.
+
+WARNING: In Groovy, `as`, `in`, and `not` are reserved words. Gremlin-Groovy does not allow these steps to be called
+statically from the anonymous traversal `__` and therefore, must always be prefixed with `__.` For instance:
+`g.V().as('a').in().as('b').where(__.not(__.as('a').out().as('b')))`
+
 [[gremlin-python]]
 Gremlin-Python
 --------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3160242b/docs/static/images/gremlin-groovy-drawing.png
----------------------------------------------------------------------
diff --git a/docs/static/images/gremlin-groovy-drawing.png b/docs/static/images/gremlin-groovy-drawing.png
new file mode 100644
index 0000000..f13b0b9
Binary files /dev/null and b/docs/static/images/gremlin-groovy-drawing.png differ