
Related: Pure Ruby Relational Algebra Engine - flipandtwist
https://github.com/seansellek/related
======
mmanfrin
Oooh, this is nice. While learning ML, I was stumbling a bit with python,
wishing that Ruby were a good language for working with datasets.

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`?

~~~
davexunit
Ruby's syntax is one of the worst I've seen. Ambiguous, hard to parse, and
inextensible.

[http://programmingisterrible.com/post/42432568185/how-to-
par...](http://programmingisterrible.com/post/42432568185/how-to-parse-ruby)

~~~
regularfry
It's awful to work on, and wonderful to work with. Awful for machines, great
for humans.

~~~
davexunit
I write Ruby for a living and I completely disagree. S-expressions are the
gold standard.

------
joemi
I like that it doesn't have any dependencies. Makes it easier to read and
understand the source, casually (one of my favorite pastimes during lunch
breaks lately).

------
lukeholder
See also: Axiom[0] and rom-rb[1] (which did use axiom I believe), although, I
don't know what does or doesn't make them 'pure' relational algebra libraries.

[0] [https://github.com/dkubb/axiom](https://github.com/dkubb/axiom)

[1] [http://rom-rb.org/](http://rom-rb.org/)

------
kristianp
Reminds me a bit of Project:M36 Relational Algebra Engine, written in Haskell.
No nulls allowed.

[https://github.com/agentm/project-m36](https://github.com/agentm/project-m36)

[https://news.ycombinator.com/item?id=11465145](https://news.ycombinator.com/item?id=11465145)

~~~
eru
At Standard Chartered they are using relations as data structures in their
Haskell-like language.

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.)

~~~
dons
We have a typed version now - it's awesome

~~~
eru
Yeah, I've heard the praise. I tried to rally Gergo into porting the idea to
GHC. (Using the new pluggable constraint solvers in GHC seems like the best
bet.)

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.

------
cmrdporcupine
Very nice. I'm not a Ruby person, but I'm glad to see someone flying the
relational flag.

------
d4mi3n
This is neat. It's nice to see learning tools like this in a language like
Ruby, as many implementations of relational algebra codebases in ruby are
pretty complicated (see ActiveRecord/ARel and Sequel).

------
catnaroek
How does this compare to a pure, recursion-free subset of Prolog? Not counting
cosmetic differences, e.g., in Prolog, relation arguments are positional,
whereas in the relational model, attributes have names.

~~~
rntz
Prolog allows unification, which doesn't have a parallel in relational
algebra. I'm not sure how much more power this gives you without recursion,
though.

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.

~~~
catnaroek
Computing natural joins requires unification.

~~~
rntz
Natural joins only require equality testing. General unification is stronger.
Prolog can unify [X,3|T] with [2,Y,4,5] to find X = 2, Y = 3, T = [4,5], for
example.

~~~
catnaroek
What you're talking about requires compound data types in the first place
(e.g., lists in your example), whereas in the relational model, attributes are
normally assumed to range over primitive types.

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.

------
jasonm23
Excellent piece of work.

------
coltonv
I'm a big fan of ruby but doesn't saying "Pure ruby" kind of detract from
rather than improve a libraries value? Ideally it would have rust/C bindings
for all the computationally difficult stuff.

~~~
flipandtwist
The reason I said that is because a lot of the other libraries I found, like
Arel or Sequel, just build off of SQL to interact with databases. And the
problem with that is that SQL is a terrible way to get a handle on relational
algebra. It is entirely based on RA operations, yes, but it is so high level
you barely feel connected to what's actually happening.

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.

