Set: Difference between revisions
Content added Content deleted
(Added second method to Quackery) |
(→{{header|Quackery}}: logic on "difference" was reversed) |
||
Line 4,781: | Line 4,781: | ||
[ join --duplicates ] is symmdiff ( { { --> { ) |
[ join --duplicates ] is symmdiff ( { { --> { ) |
||
[ |
[ over intersection symmdiff ] is difference ( { { --> { ) |
||
[ over intersection = ] is subset ( { { --> b ) |
[ over intersection = ] is subset ( { { --> b ) |
||
Line 4,792: | Line 4,792: | ||
( ------------------------------ demo ------------------------------ ) |
( ------------------------------ demo ------------------------------ ) |
||
⚫ | |||
⚫ | |||
set{ red orange green blue |
set{ red orange green blue |
||
purple apricot peach }set is colours ( --> { ) |
purple apricot peach }set is colours ( --> { ) |
||
⚫ | |||
⚫ | |||
⚫ | |||
colours dup echoset say " are colours" cr |
colours dup echoset say " are colours" cr |
||
⚫ | |||
⚫ | |||
2dup intersection echoset say " are both fruits and colours" cr |
2dup intersection echoset say " are both fruits and colours" cr |
||
⚫ | |||
2dup union echoset say " are fruits or colours" cr |
2dup union echoset say " are fruits or colours" cr |
||
2dup symmdiff echoset say " are fruits or colours but not both" cr |
2dup symmdiff echoset say " are fruits or colours but not both" cr |
||
difference echoset say " are fruits that are not colours" cr |
difference echoset say " are fruits that are not colours" cr |
||
set{ red green blue }set dup echoset say " are" |
set{ red green blue }set dup echoset say " are" |
||
colours subset not if [ say " not" ] say " all colours" cr |
colours subset not if [ say " not" ] say " all colours" cr |
||
say "fruits and colours are" fruits colours = not if [ say " not" ] |
say "fruits and colours are" fruits colours = not if [ say " not" ] |
||
say " exactly the same" cr |
say " exactly the same" cr |
||
$ "orange" dup echo$ say " is" |
$ "orange" dup echo$ say " is" |
||
fruits element not if [ say " not" ] say " a fruit" cr |
fruits element not if [ say " not" ] say " a fruit" cr |
||
set{ orange }set dup echoset say " is" |
set{ orange }set dup echoset say " is" |
||
fruits propersubset dup if [ say " not" ] say " the only fruit" |
fruits propersubset dup if [ say " not" ] say " the only fruit" |
||
Line 4,826: | Line 4,826: | ||
{{out}} |
{{out}} |
||
<pre>{ apricot |
<pre>{ apple apricot banana melon orange peach pear } are fruits |
||
{ |
{ apricot blue green orange peach purple red } are colours |
||
{ apricot orange peach } are both fruits and colours |
{ apricot orange peach } are both fruits and colours |
||
{ apple apricot banana blue green melon orange peach pear purple red } are fruits or colours |
{ apple apricot banana blue green melon orange peach pear purple red } are fruits or colours |
||
Line 4,883: | Line 4,883: | ||
[ ^ ] is symmdiff ( { { --> { ) |
[ ^ ] is symmdiff ( { { --> { ) |
||
[ |
[ over intersection symmdiff ] is difference ( { { --> { ) |
||
[ over intersection = ] is subset ( { { --> b ) |
[ over intersection = ] is subset ( { { --> b ) |
||
Line 4,894: | Line 4,894: | ||
( ----------------------------- demo ---------------------------- ) |
( ----------------------------- demo ---------------------------- ) |
||
⚫ | |||
⚫ | |||
set{ red orange green blue |
set{ red orange green blue |
||
purple apricot peach }set is colours ( --> { ) |
purple apricot peach }set is colours ( --> { ) |
||
⚫ | |||
⚫ | |||
⚫ | |||
colours dup echoset say " are colours" cr |
colours dup echoset say " are colours" cr |
||
⚫ | |||
⚫ | |||
⚫ | |||
2dup intersection echoset say " are both fruits and colours" cr |
2dup intersection echoset say " are both fruits and colours" cr |
||
Line 4,928: | Line 4,928: | ||
{{out}} |
{{out}} |
||
<pre>{ |
<pre>{ orange banana apricot melon pear peach apple } are fruits |
||
{ |
{ purple blue green red orange apricot peach } are colours |
||
{ |
{ orange apricot peach } are both fruits and colours |
||
{ |
{ purple blue green red orange banana apricot melon pear peach apple } are fruits or colours |
||
{ |
{ 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 |
{ banana melon pear apple } are fruits that are not colours |
||
{ blue green red } are all colours |
{ blue green red } are all colours |