Related: Pure Ruby Relational Algebra Engine
github.com
github.com
For all the faults people find with ruby's performance, I don't think much can be found wrong with its syntax; it is such a wonderful language to code with.
Might I suggest aliasing `<<` to `add_tuple`?
Aliasing that is a great suggestion. It's actually implemented here: https://github.com/seansellek/Related/blob/master/lib/relate...
I think I should document those aliases a bit better ;)
http://programmingisterrible.com/post/42432568185/how-to-par...
It works very well. (The biggest hurdle for a really nice integration is IMHO stuff like typing the join operator. But even the dynamically-typed only version was useful.)
I still remember when I hadn't had any clue about functional programming, and I was moving from stuff like QBasic and C to Python. I thought dicts were awesome. And they are---by comparison to only having arrays.
Relations do everything dicts do, but you don't have to decide on the structure beforehand. Exactly the same argument that Codd had.
If you're interested in connections between relational algebra (and SQL, and databases) and logic programming, you should look at Datalog, which is a restricted subset of Prolog that is akin to relational algebra plus fixed points (transitive closure, for example). In particular, Datalog forbids compound terms (like lists) and recursion in a negated position.
I think Datalog without recursion/fixed-points is precisely as powerful as relational algebra, but I don't have a proof handy.
But, even in the absence of compound data types, the answer to a Prolog query may contain free variable, whereas the answer to SQL query may not. So you do have a point.
(You don't need to be recursion free. Just restrict your recursion very carefully.)
Eg for data interchange compare json vs evaluating any random javascript expression. The latter is strictly more powerful than the former. The former is better.
Or an example in the other direction: imagine Haskell-Prime, like Haskell, but you can mutate every variable. Strictly more powerful, but awful. (Or imagine adding GOTO to your favourite programming language.)
Wrong. The power of Haskell mostly comes from how easy it is to reason about code. Your proposed Haskell-Prime would be less powerful in this sense.
Not good when you're trying to learn basic operations and how they interact with each other.
That's the only reason I said "pure". Wasn't really coming from a point of view of performance or compatibility.
And also, while not terribly relevant in this specific case, deployment is easier if you don't have to build native libraries.
Sometimes it's worth going to C bindings for runtime speed, sometimes it's better to keep it purely native for development speed or other reasons.