Set: Difference between revisions
m
→{{header|Wren}}: Minor tidy
(Added XPL0 example.) |
m (→{{header|Wren}}: Minor tidy) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 4,809:
=={{header|Maxima}}==
<syntaxhighlight lang="
a: {1, 2, 3, 4};
Line 5,806:
<!--</syntaxhighlight>-->
Same output as above. I have written a builtins/sets.e, and tried another approach with builtins/sets2.e, but neither really hit the spot.
=={{header|Phixmonti}}==
<syntaxhighlight lang="Phixmonti">include ..\Utilitys.pmt
def isElement find enddef
def setUnion dup >ps remove ps> chain enddef
def setIntersection over >ps remove ps> swap remove enddef
def setDifference remove enddef
def setSubset swap remove len not nip enddef
def setEquality sort swap sort == enddef
( 1 2 3 ) 1 isElement ?
4 isElement ?
( 3 4 5 ) setUnion ?
( 1 2 3 ) ( 3 4 5 ) setIntersection ?
( 1 2 3 ) ( 3 4 5 ) setDifference ?
( 1 2 3 ) ( 3 4 5 ) setSubset ?
( 1 2 3 ) ( 1 2 ) setSubset ?
( 1 2 3 ) ( 3 4 5 ) setEquality ?
( 1 2 3 ) ( 3 1 2 ) setEquality ?
</syntaxhighlight>
{{out}}
<pre>1
0
[1, 2, 3, 4, 5]
[3]
[1, 2]
0
1
0
1
=== Press any key to exit ===</pre>
=={{header|PicoLisp}}==
Line 6,817 ⟶ 6,856:
"Azerty" #4 3.14 3 →LIST
{{works with|Halcyon Calc|4.2.7}}
We first need a command to remove an item for a list
≪ DUP2 1 + OVER SIZE SUB ROT ROT
IF DUP 1 == THEN DROP2 ELSE
1 SWAP 1 - SUB SWAP +
END
≫ '<span style="color:blue">POPL</span>' STO <span style="color:grey">@ ''( { a1 .. ak .. an } k → { a1 .. an } )''</span>
{| class="wikitable"
! RPL code
Line 6,822 ⟶ 6,867:
|-
|
≪ POS SIGN ≫ '
≪ → a b
Line 6,828 ⟶ 6,873:
b j GET '''IF''' a OVER POS '''THEN''' DROP '''ELSE''' + '''END'''
'''NEXT'''
≫ ≫ '
≪ → a b
LAST ROT SWAP <span style="color:blue">POPL</span>
ROT ROT + SWAP
'''ELSE''' DROP '''END'''
'''NEXT''' DROP
≫ ≫ ‘<span style="color:blue">INTER</span>’ STO
≪ → a b
LAST ROT SWAP <span style="color:blue">POPL</span>
ROT ROT + SWAP
'''ELSE''' DROP '''END'''
'''NEXT''' DROP
≫ ≫ ‘<span style="color:blue">DIFFL</span>’ STO
≪ → a b
Line 6,846 ⟶ 6,901:
'''IF''' b a j GET POS NOT '''THEN''' 1 SF a SIZE 'j' STO '''END'''
'''NEXT''' 1 FC?
≫ ≫ '
≫ '
|
Scan {B}...
... and add to {A} all {B} items not already in {A}
.▼
Put a copy of {B} in stack
▲ '''INTER''' ''( {A} {B} -- {A ∩ B} )''
Scan {A}
if {A} item in copy of {B}
.▼
remove it from copy of {B}
.▼
add it to result
'''DIFFL''' ''( {A} {B} -- {A ∖ B} )''▼
Scan {A}...▼
.▼
Put a copy of {B} in stack
'''INCL?''' ''( {A} {B} -- boolean )'' // true if {A} ⊆ {B}▼
if {A} item not in copy of {B}
remove it from copy of {B}
add it to result
Scan {A}...
... and break loop if an {A} item is not in {B}
return flag 1, set if loop has been broken
{A} = {B} <=> {A} ⊆ {B} and {B} ⊆ {A}
|}
Line 7,967 ⟶ 8,032:
{{libheader|Wren-set}}
Note that the Set class in the above module uses a Map internally for storage. Consequently, iteration order is undefined.
<syntaxhighlight lang="
var fruits = Set.new(["apple", "pear", "orange", "banana"])
|