Ra

The relational language

Introducing Ra

Ra is a new programming language designed from the ground up to make working with data simpler, more consistent, and more powerful. Ra has relations as first-class data structures. This means cleaner, more algebraic operations, fewer pitfalls, and a language that lets you declare what you want instead of making you build nested loops to extract it.

Find the suppliers with a STATUS less than 30
S[STATUS < 30]
SNOSNAMESTATUSCITY
S1Smith20London
S2Jones10Paris
S4Clark20London
For each city, show the number of suppliers
S{CITY}{*, suppliers:=count(!!S)}
suppliersCITY
1Athens
2London
2Paris

By eliminating problems — like nulls and duplicate rows — Ra enables more reliable and maintainable applications. No more wrestling with ORMs, juggling string-based queries, or dealing with edge cases from three-valued 'logic' that simply shouldn't exist. Just expressive, predictable, and efficient relational programming.

Ra isn’t ready for public testing just yet, but if you're interested in a better way to work with data, stay tuned.

Find suppliers who supply all parts
S[(!!SP){PNO} = P{PNO}]
SNOSNAMESTATUSCITY
S1Smith20London
SQL equivalent
SELECT * FROM S 
    WHERE NOT EXISTS (
      SELECT PNO FROM SP 
      WHERE SP.SNO = S.SNO 
      EXCEPT 
      SELECT PNO FROM P)
    AND NOT EXISTS (
      SELECT PNO FROM P 
      EXCEPT 
      SELECT PNO FROM P 
      WHERE SP.SNO = S.SNO)
        
Find suppliers who supply the heaviest part
S &~ SP(quota(P, 1, {-WEIGHT}){PNO})
SNOSNAMESTATUSCITY
S1Smith20London
SQL equivalent
SELECT * FROM S
    WHERE EXISTS (
      SELECT PNO FROM SP
      JOIN
      (SELECT PNO FROM P AS PX
      WHERE (
        SELECT COUNT(*)
        FROM P AS PY
        WHERE PX.WEIGHT < PY.WEIGHT
      ) < 1) AS HEAVIEST 
      ON SP.PNO = HEAVIEST.PNO)
        
Find the lightest parts and show their supplier details plus a total quantity per part
group(S & SP & quota(P, 2, {WEIGHT, PNO})~{CITY}, {SNO, SNAME, STATUS, CITY, QTY}, suppliers)
        {*, tqty:=sum(suppliers, QTY)}
tqtyPNOPNAMECOLORWEIGHTsuppliers
500P5CamBlue12
SNOSNAMESTATUSCITYQTY
S1Smith20London100
S4Clark20London400
600P1NutRed12
SNOSNAMESTATUSCITYQTY
S1Smith20London300
S2Jones10Paris300
SQL equivalent
¯\_(ツ)_
A terminal REPL sample

Ra is inspired by "Databases, Types, and The Relational Model: The Third Manifesto", a book by Chris Date and Hugh Darwen.

The language is under development but is already showing some potential. On this site I'll highlight the features and progress made, though the syntax is subject to change.

Hello, world

Create main.ra

main := {} begin
    print("Hello, world")
end
$ ra hello.ra
Hello, world