Skip to content

Commit bd9f55c

Browse files
committed
set.lambda: Move set operations there.
1 parent 07a2473 commit bd9f55c

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

README.org

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Sources of inspiration and code:
2626
- ~numbers.lambda~ :: Numeric, arithmetics. Depends on ~combinators.lambda~ and ~bool.lambda~.
2727
- ~cons.lambda~ :: Conses. Depends on ~bool.lambda~.
2828
- ~list.lambda~ :: Linked lists and utils for them. Mostly fold operations. Depends on ~cons.lambda~, ~numbers.lambda~, ~combinators.lambda~, ~bool.lambda~.
29+
- ~set.lambda~ :: Operations on lists-as-sets. Depends on ~list.lambda~ and its transitive dependencies.
2930
- ~alist.lambda~ :: Associative (key-value) lists. Depends on ~cons.lambda~ and ~combinators.lambda~.
3031
- ~alias.lambda~ :: Aliases for all of the above.
3132
- Run the code using these primitives. Say

list.lambda

-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ rotatel = λl.rcons (cdr l) (car l)
2121
rotater = λl.cons (last l) (butlast l)
2222
take = λn.λl.Y (λr.λl.if (eq n (length l)) l (r (butlast l))) l
2323
split = λn.λl.(cons (take n l) (singleton (nthcdr n l)))
24-
deduplicate = λp.λl.foldr (λe.λa.if (some (λx.p x e) a) a (cons e a)) nil l
25-
difference = λp.λa.λb.remove (λe.(some (λx.p x e) b)) a
26-
intersection = λp.λa.λb.filter (λe.(some (λx.p x e) b)) a
27-
union = λp.λa.λb.deduplicate p (concat a b)
2824
unzip = λl.(cons (map car l) (singleton (map cadr l)))
2925

3026
sorted = λl.foldr (λe.λa.(cons (and (car a) (leq e (cdr a))) e)) (cons true (last l)) (butlast l)

set.lambda

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
deduplicate = λp.λl.foldr (λe.λa.if (some (λx.p x e) a) a (cons e a)) nil l
2+
difference = λp.λa.λb.remove (λe.(some (λx.p x e) b)) a
3+
intersection = λp.λa.λb.filter (λe.(some (λx.p x e) b)) a
4+
union = λp.λa.λb.deduplicate p (concat a b)

0 commit comments

Comments
 (0)