Set: Difference between revisions

→‎{{header|Quackery}}: logic on "difference" was reversed
(Added second method to Quackery)
(→‎{{header|Quackery}}: logic on "difference" was reversed)
Line 4,781:
[ join --duplicates ] is symmdiff ( { { --> { )
 
[ tuckover intersection symmdiff ] is difference ( { { --> { )
 
[ over intersection = ] is subset ( { { --> b )
Line 4,792:
 
( ------------------------------ demo ------------------------------ )
 
set{ apple peach pear melon
apricot banana orange }set is fruits ( --> { )
 
set{ red orange green blue
purple apricot peach }set is colours ( --> { )
 
fruits dup echoset say " are fruits" cr
set{ apple peach pear melon
apricot banana orange }set is fruits ( --> { )
 
colours dup echoset say " are colours" cr
 
fruits dup echoset say " are fruits" cr
 
2dup intersection echoset say " are both fruits and colours" cr
 
2dup union echoset say " are fruits or colours" cr
 
2dup symmdiff echoset say " are fruits or colours but not both" cr
 
difference echoset say " are fruits that are not colours" cr
 
set{ red green blue }set dup echoset say " are"
colours subset not if [ say " not" ] say " all colours" cr
 
say "fruits and colours are" fruits colours = not if [ say " not" ]
say " exactly the same" cr
 
$ "orange" dup echo$ say " is"
fruits element not if [ say " not" ] say " a fruit" cr
 
set{ orange }set dup echoset say " is"
fruits propersubset dup if [ say " not" ] say " the only fruit"
Line 4,826:
{{out}}
 
<pre>{ apple apricot bluebanana greenmelon orange peach purple redpear } are coloursfruits
{ apple apricot bananablue melongreen orange peach pearpurple red } are fruitscolours
{ apricot orange peach } are both fruits and colours
{ apple apricot banana blue green melon orange peach pear purple red } are fruits or colours
Line 4,883:
[ ^ ] is symmdiff ( { { --> { )
 
[ tuckover intersection symmdiff ] is difference ( { { --> { )
 
[ over intersection = ] is subset ( { { --> b )
Line 4,894:
 
( ----------------------------- demo ---------------------------- )
 
set{ apple peach pear melon
apricot banana orange }set is fruits ( --> { )
 
set{ red orange green blue
purple apricot peach }set is colours ( --> { )
 
fruits dup echoset say " are fruits" cr
set{ apple peach pear melon
apricot banana orange }set is fruits ( --> { )
 
colours dup echoset say " are colours" cr
 
fruits dup echoset say " are fruits" cr
2dup intersection echoset say " are both fruits and colours" cr
Line 4,928:
{{out}}
 
<pre>{ peachorange banana apricot purplemelon bluepear green orangepeach redapple } are coloursfruits
{ bananapurple melonblue peargreen applered peachorange apricot orangepeach } are fruitscolours
{ peachorange apricot orangepeach } are both fruits and colours
{ bananapurple melonblue peargreen applered peachorange banana apricot purplemelon bluepear greenpeach orange redapple } are fruits or colours
{ banana melon pear apple purple blue green red banana melon pear apple } are fruits or colours but not both
{ banana melon pear apple } are fruits that are not colours
{ blue green red } are all colours
1,462

edits