tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

46
Task/Set/PicoLisp/set-1.l Normal file
View file

@ -0,0 +1,46 @@
(setq
Set1 (1 2 3 7 abc "def" (u v w))
Set2 (2 3 5 hello (x y z))
Set3 (3 hello (x y z)) )
# Element tests (any non-NIL value means "yes")
: (member "def" Set1)
-> ("def" (u v w))
: (member "def" Set2)
-> NIL
: (member '(x y z) Set2)
-> ((x y z))
# Union
: (uniq (append Set1 Set2))
-> (1 2 3 7 abc "def" (u v w) 5 hello (x y z))
# Intersection
: (sect Set1 Set2)
-> (2 3)
# Difference
: (diff Set1 Set2)
-> (1 7 abc "def" (u v w))
# Test for subset
: (not (diff Set1 Set2))
-> NIL # Set1 is not a subset of Set2
: (not (diff Set3 Set2))
-> T # Set3 is a subset of Set2
# Test for equality
: (= (sort (copy Set1)) (sort (copy Set2)))
-> NIL
: (= (sort (copy Set2)) (sort (copy Set2)))
-> T

57
Task/Set/PicoLisp/set-2.l Normal file
View file

@ -0,0 +1,57 @@
# Create three test-sets
(balance 'Set1 (1 2 3 7 abc "def" (u v w)))
(balance 'Set2 (2 3 5 hello (x y z)))
(balance 'Set3 (3 hello (x y z)))
# Get contents
: (idx 'Set1)
-> (1 2 3 7 abc "def" (u v w))
: (idx 'Set2)
-> (2 3 5 hello (x y z))
# Element tests (any non-NIL value means "yes")
: (idx 'Set1 "def")
-> ("def" (abc) (u v w))
: (idx 'Set2 "def")
-> NIL
: (idx 'Set2 '(x y z))
-> ((x y z))
# Union
: (use S
(balance 'S (idx 'Set1))
(balance 'S (idx 'Set2) T)
(idx 'S) )
-> (1 2 3 5 7 abc "def" hello (u v w) (x y z))
# Intersection
: (sect (idx 'Set1) (idx 'Set2))
-> (2 3)
# Difference
: (diff (idx 'Set1) (idx 'Set2))
-> (1 7 abc "def" (u v w))
# Test for subset
: (not (diff (idx 'Set1) (idx 'Set2)))
-> NIL # Set1 is not a subset of Set2
: (not (diff (idx 'Set3) (idx 'Set2)))
-> T # Set3 is a subset of Set2
# Test for equality
: (= (idx 'Set1) (idx 'Set2))
-> NIL
: (= (idx 'Set2) (idx 'Set2))
-> T