Page 1 of 1

SET operators

Posted: Thu Jan 13, 2011 9:08 am
by alain
Hello,
This series of enhancement topics you started recently is really usefull 8-)

It would be nice to have some examples showing the use of SET operators in expressions and as single operands
eg:
u:= s- {8,9,13} if s:={7,9,14} :?:
u:= -s :?:

not so clear :idea: for me the use of IS an the TYPE "Tree"
Regards

Alain

Re: SET operators

Posted: Thu Jan 13, 2011 12:13 pm
by cfbsoftware
Thank you for your feedback - much appreciated. There's a lot more to come if there is sufficient interest :)

Niklaus Wirth has written a paper on the use of SETs titled "SET: A neglected data type and its compilation for the ARM". You can download a copy from:

https://people.inf.ethz.ch/~wirth/Oberon/SETs.pdf

When you subtract one set from another, any element that is common to both sets is removed. No other element is affected.

Thus, if you execute the code:

Code: Select all

s := {7,9,14};
u := s - {8,9,13};
then u = {7, 14};

-SET is the complement of a set. i.e. the resulting set contains all the elements that were not in the original set and none of the elements that were in the original set.

If s = {7, 9, 14} then -s = {0,1,2,3,4,5,6,8,10,11,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}

This is more conveniently written as {0..6, 8, 10..13, 15..31}