Navigation
Synopsis An unordered collection of values without duplicates.
Description A set is a collection of values with the following properties:
  • The set maybe empty.
  • The values in the list are unordered.
  • A value can only occur once.
  • The set has a size that is equal to the number of values in the set.
In Rascal, sets are surrounded by braces { and } and the elements are separated by commas. Each set has a type of the form set[T], where T is the smallest common type of all set elements. See Rascal:Values/Set for a description of sets and their operators and Rascal:Prelude/Set for functions on sets.
Examples

Sets in daily life

  • A cutlery set consisting of knife, fork and the like.
  • A crowd of people.
  • A stamp collection (but be aware that the duplicates will disappear!)
cutlery-set credit stamp-collecting credit

Sets in computer science

  • The files in a directory. Of course, when you order them (by name, modification date) you need a List to represent them.
  • The set of moves an opponent can play in a game.
  • The set of nodes in a network.

Sets in Rascal

  • The empty set: {}. Its type is set[void].
  • A set of integers: {3, 1, 4}. Its type is set[int].
  • A set of mixed-type values: {3, "a", 4}. Its type is set[value].
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.