Data

Variables

We can create variables using := which both declares new variables and assigns values to them. The variable name goes on the left and the value goes on the right, e.g.

x := 42

Variables in Ra have some differences from other programming languages. One of the main ones is that we can create relation variables (relvars), e.g.

planet := {planet_name:str,  orbit_period:float, gravity:float}{
          ["Mercury",        88,                 0.38],
          ["Venus",          224.7,              0.91],
          ["Earth",          365.25,             1.00],
          ["Mars",           687,                0.38],
          ["Jupiter",        4331,               2.36],
          ["Saturn",         10747,              0.92],
          ["Uranus",         30589,              0.89],
          ["Neptune",        59800,              1.12],
}
planet
┌─────────────┬──────────────┬─────────┐
│ planet_name │ orbit_period │ gravity │
├─────────────┼──────────────┼─────────┤
│ Earth       │       365.25 │    1.00 │
│ Jupiter     │      4331.00 │    2.36 │
│ Mars        │       687.00 │    0.38 │
│ Mercury     │        88.00 │    0.38 │
│ Neptune     │     59800.00 │    1.12 │
│ Saturn      │     10747.00 │    0.92 │
│ Uranus      │     30589.00 │    0.89 │
│ Venus       │       224.70 │    0.91 │
└─────────────┴──────────────┴─────────┘

And we can then use these variables in relation expressions (ignore the new syntax for now, it will be explained soon), e.g.

planet[orbit_period < 500]{planet_name}
┌─────────────┐
│ planet_name │
├─────────────┤
│ Earth       │
│ Mercury     │
│ Venus       │
└─────────────┘

Here are some things to note about variables in Ra:

Storage details

Ra persists global relvar values to disk files, currently as <table>s in HTML files in the schema folder (the one Ra was started in). Although storing data in HTML files has some space overheads, there are some benefits to using HTML: