Om

From the SETL Wiki

Jump to: navigation, search

om, an abbreviation for omega, represents the absence of a value in SETL. Syntactically, it may appear in a program anywhere that a literal could appear.

Examples of expressions with no values:

  • An uninitialised variable (including a wr parameter of a procedure)
  • A key that is absent from a map
  • A tuple element whose index is greater than the size of the tuple
  • The "result" of a procedure call that does not return a value

e.g. after

var a, b, c, d, m, t;

sqrtMap := {[1, 1], [4, 2], [9, 3], [16, 4], [25, 5]};
b := sqrtMap(2);

t := ['a', 'b', 'c'];
c := t(4);

d := p();

proc p();
  print("Hello, world!");
end proc;

a, b, c and d are all om.

In general an expression having no value (for whatever reason) is equivalent to it having a value of om.

Similarly, assigning om to a variable is equivalent to unsetting the variable and assigning om to a map reference is equivalent to removing the key from the map, e.g. after

v := om;

m := {[1, 1], [2, 4]};
m(1) := om;

v is uninitialised and m has the value {[2, 4]}, the key 1 having been removed.

Another thing you can do with om is test it for equality with a variable, e.g.

var a, b, c, m;

b := om;
c := {[1, 2]};
d := c(1);
e := c(2);

print(a = om, b = om, c /= om, d /= om, e = om);

outputs #T #T #T #T #T

However, om differs from "proper" values in some ways:

  • It cannot be an element of a set
  • Even when it represents a hole in a 2-element tuple, it cannot be a key in a map, e.g.
    m := {[1, 2], [om, 4]};
    print(is_map(m));
    
    outputs #F.
Personal tools