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.applicative.list.base.scm | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 algebraic-structures.applicative.list.base.scm (limited to 'algebraic-structures.applicative.list.base.scm') diff --git a/algebraic-structures.applicative.list.base.scm b/algebraic-structures.applicative.list.base.scm new file mode 100644 index 0000000..01625ff --- /dev/null +++ b/algebraic-structures.applicative.list.base.scm @@ -0,0 +1,29 @@ +(module (algebraic-structs applicative list base) (map pure map2) + (import (except scheme map) + (algebraic-structs functor list) + (only (chicken base) atom? cut) + (only (srfi 1) append! reverse!) + matchable) + + (define (pure x) + (list x)) + + (define (rev-map f lst) + (let loop ((lst lst) + (acc '())) + (match lst + [() acc] + [(h . t) + (loop t (cons (f h) acc))]))) + + (define (product op lst1 lst2) + (let loop ((lst lst1) + (acc '())) + (match lst + [() (reverse! acc)] + [(h . t) + (loop t + (append! (rev-map (cut op h <>) lst2) + acc))]))) + + (define map2 product)) -- cgit v1.2.3