An Invitation to SETL

Link: This article gives an easy to follow introduction to the SETL language. SETL has been around since 1970 and excels at manipulating sets.

Being a mathematician, I've always dreamt of a programming language that would make use of the powerful formalism of Set Theory. Two years ago, I started looking for an open-source software tool to use in an elementary Set Theory class. I had a hard time finding any on the Net, but in the end I found the object of my dreams: a structured, general-purpose, open-source programming language that implements as closely as possible the Set Theory formal language.

(Previous LtU discussion)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

*hem hem*

from sets import Set
s = Set([1,2,3,4,5])
t = Set([3,4,5,6])
print s | t # union
print s - t # difference
print s & t # intersection
print s ^ t # symmetric difference

and so on. I actually got this by just randomly trying 'import sets' and dir()'ing to see what was in there. Why 'SETL'? ;-)


numbers = Set(xrange(-10, 11))
evens = Set([x for x in numbers if (x % 2) == 0])
odds = numbers - evens

Q Language

Q (KDB+, has similarly nice set logic...but not for free:

s:1 2 3 4 5
t:3 4 5 6
s,t // join sets
s union t // distinct union
s except t // difference
s inter t // intersection

numbers:-10 + key 20
evens:numbers where not numbers mod 2
odds:numbers except evens

SETL and Python Convergence

I used SETL as a graduate student and NYU and really liked it -- especially for experimental development of complex algorithms. I’ve followed Python over the years and it seemed to me, especially with the introduction of list comprehensions and the new Set type that Python was essentially becoming very SETL-like.

With its large active user community and open source tools I would probably choose Python over SETL today, but credit where it is due: SETL was first and way beyond its time. Also the “make closures easy” tradition of Smalltalk, Scheme, Ruby, Nice, Groovy, and so on offers an alternative with similar expressive power and ease of use.