From 552cd6c999f3e44b13be88e45c4a8cb391eb40cf Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Tue, 11 Jun 2024 02:10:37 +0900 Subject: Rename filename from `algebraic-structs` to `algebraic-structures` --- algebraic-structures.foldable.make.scm | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 algebraic-structures.foldable.make.scm (limited to 'algebraic-structures.foldable.make.scm') diff --git a/algebraic-structures.foldable.make.scm b/algebraic-structures.foldable.make.scm new file mode 100644 index 0000000..46b4dd5 --- /dev/null +++ b/algebraic-structures.foldable.make.scm @@ -0,0 +1,39 @@ +(functor ((algebraic-structs foldable make) (F (foldl foldr))) + (foldl foldr length find any every ->list) + (import (except scheme length) F + (only (chicken base) add1 call/cc)) + + (define (length xs) + (foldl (lambda (acc _) (add1 acc)) + 0 + xs)) + + (define (find p? xs) + (call/cc + (lambda (k) + (foldl (lambda (acc e) + (if (p? e) + (k e) + acc)) + #f + xs)))) + + (define (any pred xs) + (call/cc + (lambda (return) + (foldl (lambda (acc e) + (cond ((pred e) => return) + (else acc))) + #f + xs)))) + + (define (every pred xs) + (call/cc + (lambda (return) + (foldl (lambda (acc e) + (or (pred e) (return #f))) + #t + xs)))) + + (define (->list xs) + (foldr cons '() xs))) -- cgit v1.2.3