4 ms·
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
by JulianMorrison 13y ago
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?
- vyrotek 13y agoThis 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 http://msdn.microsoft.com/en-us/library/bb397933.aspx
- mfenniak 13y agoI'm the author of a .NET RethinkDB client (https://github.com/mfenniak/rethinkdb-net 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 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.
- kclay 13y agoWith 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
- cshesse 13y agoIn 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
- wmrowan 13y agoThat'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.
- JulianMorrison 13y agoIt 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).