SET operators

Newcomers to Astrobe and Oberon are welcome to ask any beginner-level questions here
Locked
alain
Posts: 6
Joined: Tue Jan 04, 2011 9:28 pm

SET operators

Post by alain » Thu Jan 13, 2011 9:08 am

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

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: SET operators

Post by cfbsoftware » Thu Jan 13, 2011 12:13 pm

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:

http://www.inf.ethz.ch/personal/wirth/A ... n/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}

Locked