All about lambda functions in RethinkDB queries
rethinkdb.com
rethinkdb.com
I wonder if this imposes any limitations on the functions that can be written. For example, how are if, for statements handled? What happens if I do "lambda x: y + x" where "y" is an object that defines __add__? If these cases are not handled, is a well-defined exception raised?
We overload operators when we can (unfortunately no operator overloading for Javascript folks) and it works really well.
You don't always get a great exception, but most of the time this turns out to be fine. Novices don't need to worry about this too much, and we found that as people get more into ReQL, they pick everything up extremely quickly, and they rarely confuse things or make mistakes.
I've looked at this problem before (and ran away screaming every time), but the approach I tended towards was func_code disassembly, pretty much for the reasons you mention. Was this ever considered?
From a purely theoretical POV, I do like the idea of disassembly better, but unfortunately we couldn't make this work and remain pragmatic.
Can't see much evidence of a clojure driver yet? Is there an existing project we could contribute to?
We've done a lot of work to make building a client driver for RethinkDB easier: we use Protobufs, have built some testing tools (e.g. https://github.com/neumino/rethinkdb-driver-development), have a Google group for driver developers (https://groups.google.com/forum/?fromgroups#!forum/rethinkdb... ), and our engineers love helping people build new drivers.
EDIT: and of course @mglukhovsky beat me to it!
Hoas, and its sibling PHOAS, are great ways of embedding a mini language inside another language, they're especially powerful in language like Haskell, Scala, Idris, and the like.
db("tablename").filter( x => x.name == "foo" )
and be able to translate that to the relevant query, but I can't really think of a way without using Macros or reflection.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?
Expression trees were introduced at the same time as LINQ, to support LINQ.
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.
Novices can do most things without having to understand any of these issues, and even very advanced users don't ever have to learn this if they don't want to.
Disclaimer: I'm one of the people responsible for designing ReQL.
Maybe try renaming "ReQL" to ThinkSimpleQuery and the other one to ThinkBigQuery. Something more self explanatory.
This post covers all aspects of lambda functions in ReQL from
concept to implementation and is meant for third party driver
developers and those interested in functional programming and
programming language design. For a more practical guide to using
ReQL please see our docs where you can find FAQs, screencasts, an
API reference, as well as various tutorials and examples.