aboutsummaryrefslogtreecommitdiff
path: root/algebraic-structures.foldable.scm
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2024-06-15 01:47:35 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2024-06-15 01:47:35 +0900
commit959ead049e6f22438902399eb0925e8f60e0f3e0 (patch)
tree4f2e8e887e91226798ea275aa11f0d131bade96f /algebraic-structures.foldable.scm
parenta7f95e5555880f3d6d3b0fe0308f94c82b83b767 (diff)
Add `member?` function
Diffstat (limited to 'algebraic-structures.foldable.scm')
-rw-r--r--algebraic-structures.foldable.scm17
1 files changed, 15 insertions, 2 deletions
diff --git a/algebraic-structures.foldable.scm b/algebraic-structures.foldable.scm
index be3d615..25c66bb 100644
--- a/algebraic-structures.foldable.scm
+++ b/algebraic-structures.foldable.scm
@@ -3,10 +3,11 @@
length
count
any
- every)
+ every
+ member?)
(import (except scheme length)
F
- (only (chicken base) add1 call/cc))
+ (only (chicken base) add1 call/cc assert))
(define (length xs)
(fold (lambda (_ acc) (add1 acc))
@@ -36,4 +37,16 @@
(fold (lambda (e acc)
(or (pred e) (return #f)))
#t
+ xs))))
+
+ (define (member? x xs #!optional (= equal?))
+ (call/cc
+ (lambda (return)
+ (fold (lambda (e _)
+ (if (= e x)
+ (return #t)
+ #f))
+ #f
xs)))))
+
+