News for hackers. Stuff that matters.
Re:All about lambda functions in RethinkDB queries by JulianMorrison on Thursday May 23, 2013 @09:31PM (#5760724)
That is genius.

I have to wonder though, how they plan to do it in less dynamic languages? Just spell out the s-expr and forget about using the language's own syntax?

Re:All about lambda functions in RethinkDB queries by vyrotek on Thursday May 23, 2013 @09:37PM (#5760745)
This looks a lot like LINQ. C# is probably one of those "less dynamic languages" but has had this for years. It powers a lot of ORMs and other frameworks that need a queryable expression language. It supports writing custom 'providers' so that you can write LINQ against almost anything.

http://msdn.microsoft.com/en-us/library/bb397933.aspx

Re:All about lambda functions in RethinkDB queries by mfenniak on Thursday May 23, 2013 @11:10PM (#5761067)
I'm the author of a .NET RethinkDB client (https://github.com/mfenniak/rethinkdb-net), and I can add that RethinkDB's lambda functions were very easy to implement in .NET by using C#'s expression tree feature (http://msdn.microsoft.com/en-us/library/bb397951.aspx). With that feature, a lambda can automatically be converted to an AST by creating a function that takes an Expression<Func<...>> parameter, which can easily be traversed and converted into RethinkDB's expression tree.

Expression trees were introduced at the same time as LINQ, to support LINQ.

Re:All about lambda functions in RethinkDB queries by wmrowan on Friday May 24, 2013 @04:52AM (#5761857)
That's a good question. I've given some thought to how we might build drivers in languages that don't support lambda functions and unfortunately, there don't seem to be any good answers.

The actual underlying S-expression syntax for ReQL lambda functions is pretty ugly by itself and I'm glad that so far we haven't had to expose it. The python `lambda x,y: x + y` actually gets compiled to something like the following: `(func [1,2] (add (var 1) (var 2)))`. Variable references have to be constructed manually no matter how you do it. With native lambda functions though you can at least hide those constructions behind the scenes and bind them to the function's formal arguments.

Fortunately though both C++ and Java, the two "traditional" languages we would most like to support, have either just (in C++11) or are about to (in Java 8) introduce lambda functions rendering the point moot.

Re:All about lambda functions in RethinkDB queries by JulianMorrison on Friday May 24, 2013 @05:50AM (#5761978)
It wouldn't be hard to have a very shallow translation from a lisp-alike syntax - to borrow Clojure's: "(fn [a b] (+ a b))". Named parameters translate trivially to (var n).
Re:All about lambda functions in RethinkDB queries by kclay on Thursday May 23, 2013 @09:41PM (#5760762)
With Scala in use a lot of implicit conversions, works pretty well for the most part you just have to wrap the left side in a Expr(x) for it to work
Re:All about lambda functions in RethinkDB queries by cshesse on Friday May 24, 2013 @01:24AM (#5761395)
In the go driver, it does basically what the Javascript one does and just takes an Expression object, with methods like .Add(<Expression>) and .Mul(<Expression>) that also return Expressions