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 ( { { --> { )
[
[ 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
{
{ 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 ( { { --> { )
[
[ 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>{
{
{
{
{
{ banana melon pear apple } are fruits that are not colours
{ blue green red } are all colours
|