Differences between SETL implementations

From the SETL Wiki

Jump to: navigation, search

There are some subtle differences between the various implementations of SETL, that are likely to confuse a programmer attempting to port code from one implementation to another. This page is an incomplete list of such differences. If you discover more please add them!

Implementation-specific features (e.g. language extensions, extra built-in functions) are covered elsewhere.

Contents

[edit] Syntactic differences

Starting with the obvious ones...

[edit] Strings

In CIMS SETL and SETL-S, string literals are enclosed in single quotes, e.g. 'Hello, World'.
In SETL2, string literals are enclosed in double quotes, e.g. "Hello, World!".
In GNU SETL, both are valid.

[edit] Procedures

  • In SETL-S all procedure must be forward-declared at the beginning of a program. All other implementations make 2 or more passes through the source code and scan for procedure names on the first pass, thus they do not require these forward declarations.
  • In CIMS SETL, SETL-S and GNU SETL, proc is a synonym for procedure. In SETL2, it isn't.

[edit] from and similar operators

CIMS SETL and SETL2 allow an assignment using the from, fromb or frome operator to be used in an expression context, e.g.

t := [1, 2, 3];
print(x fromb t);
print(x);
print(t);

outputs:

1
1
[2 3]

SETL-S and GNU SETL do not permit this syntax.

[edit] Types

[edit] Sets

It is not normally possible to construct a set that has om as an element. For example "{om}" and "{} with om" both evaluate to the empty set. However in SETL2 the range operator can return a set containing om, if given a map containing a one-element tuple, e.g. "range({[1], [2, 3]})" yields {om, 3}.

[edit] Primitives

[edit] Overloading of primitives

  • SETL2 permits the argument of arb to be a tuple. None of the other implementations permit anything other than a set.

[edit] Redefinition of primitives

In SETL2, most of SETL's unary operators are demoted to (predefined) procedures. These include all of the standard math functions, e.g. sin, abs, even etc. The built-in definitions can be overridden by the programmer defining a procedure of the same name. Exceptions are pow, not, arb, domain and range, which are still unary operators in SETL2.


[edit] Run-time behavioural differences

There are some slight differences in the implementations of some of the set primitives, regarding their behaviour when given om as an argument:

Operator / function Expression Results Alternative
SETL-S SETL2 GNU SETL
{} (set former) {om} error {} {} {e: e in [x]}
with s with om error s s s with/ [x]
less s less om s s error s less/ [x]
in om in [1, om, 2] error true true (exists i in [1 .. #t] | t(i) = x)
om in {} error false false x /= om and x in s

The "alternative" column above gives an expression which may be used instead if it is unknown whether x is om or not.

Personal tools