The SETL Programming Language



G22.3110-001 Fall 2000

Contents

  1. Introduction
  2. An Introductory Example
  3. Assignment Statements & Expressions involving integers, reals, and strings
  4. Errors & Omega
  5. Tuples
  6. Sets
  7. Maps
  8. Conditional
  9. Loops
  10. Input-output: cf. SETL report
  11. Stop and null statements
  12. Using the interpreter
  13. Example Programs


Introduction


An Introductory Example

program printprimes;
­­ This program prints out a list of prime numbers
-- which includes all primesless than a parameter
-- value which is specified as input data.
    read(n);   ­­ read input parameter
    primes := { }; -­ set of primes output so far
    p := 2;    ­­ initial value to test
               ­­ Loop to test successive values
    while p < n loop    ­­ loop as long as p less than n
        ifnot (exists t in primes | p mod t = 0) then
        print(p);   ­­ no divisors, it's a prime
        primes with:= p;­­ add it to set of primes
        endif;
        p := p + 1;     ­­ move to next test value
    endloop;
end printprimes;


Assignment Statements & Expressions involving integers, reals, and strings

identifier := expression;


Errors & Omega


Tuples


Sets


Maps


Conditional

case expr
when expr1 => block1
when expr2 => block2
.
.
otherwise => blocke
end case;
If expr is equal to one of expr1, ..., the corresponding block is executed. A more general form is:
Boolean Procedures
even(i)         Operand is even
odd(i)          Operand is odd
is_integer(v)   Operand is integer type
is_real(v)      Operand is real type
is_tuple(v)     Operand is tuple type
is_set(v)       Operand is set type
is_map(v)       Operand is map (set of pairs)
is_string(v)    Operand is string
is_atom(v)      Operand is atom
is_boolean(v)   Operand is boolean
is_procedure(v) Operand is procedure
The equality and inequality comparisons may be used to compare values of any type for exact identity, including testing for equality with om.


Loops

bop/ exprs    means  e1 bop e2 bop e3 ...
             result is om if tuple or set is empty
expre bop/ exprs means expre bop e1 bop e2 ...
             result is value of expre if tuple or set is empty
Examples:
+/ t       ­­ sum of values in tuple
0+/ t      ­­ same, but 0 rather than om for [ ]
*/ [a in s | 3 in a]  -- inters. sets that contain 3
" "+/ t    ­­ builds string from tuple of chars


Input-output: cf. SETL report.


Stop and null statements

case i
  when 1,3,5 => print(i);
  when 2,4,7 => print(i+1);
  when 0,6,9 => null; ­­ do nothing in these cases
  otherwise => print("no good");
end case;

Using the interpreter


See the manual pages for more information on the stll, stlc, and stlx commands.


Example programs


[Back to top]