TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

All about lambda functions in RethinkDB queries

74 pointsby mglukhovskyabout 12 years ago

6 comments

otabout 12 years ago
So if my understanding is correct, the RethinkDB driver translates a Python function object into its "abstract interpretation" by invoking the function on a proxy object x that defines operators such that (simplifying) x.__op__() returns Op(x). Recursively, this yields the computation tree of the function. This looks very similar to what is done in C++ metaprogramming through "expression templates", a technique that is taken to its extremes in libraries such as Boost.Proto. C# solves this more cleanly by having in the language an explicit concept of "expression trees" that are given as arguments of LINQ queries.<p>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?
评论 #5760827 未加载
thomabout 12 years ago
Well this is just lovely! It's so similar and such a good fit for what we're doing in Delver (we build very similar abstract queries out of natural language, but for compilation into SQL etc) that it makes me want to force everyone to use RethinkDB. Our lives are maybe a little easier cos we do it in Clojure so it's s-expressions in, s-expressions out.<p>Can't see much evidence of a clojure driver yet? Is there an existing project we could contribute to?
评论 #5761591 未加载
评论 #5761608 未加载
carterschonwaldabout 12 years ago
and thus we learn that RethinkDB is an elaborate scheme to get programmers to learn Higher Order Abstract Syntax techniques, not just have a neat db :)<p>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.
kclayabout 12 years ago
This will help in the Scala driver I've been developing
评论 #5760715 未加载
JulianMorrisonabout 12 years ago
That is genius.<p>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?
评论 #5760745 未加载
评论 #5761857 未加载
评论 #5760762 未加载
评论 #5761395 未加载
hoodoofabout 12 years ago
Deeply painful for the novice developer, good for the computer scientist.
评论 #5760801 未加载
评论 #5760879 未加载