Skip to content

Commit e66fa67

Browse files
committed
Add reduce
1 parent 201366b commit e66fa67

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

examples/library.lisp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@
5656
(cons (fn (car lis))
5757
(map (cdr lis) fn))))
5858

59+
(defun reduce (fn lst init)
60+
(if (eq () lst)
61+
init
62+
(reduce fn
63+
(cdr lst)
64+
(fn init (car lst)))))
65+
5966
;; Applies each element of lis to pred. If pred returns a true value, terminate
6067
;; the evaluation and returns pred's return value. If all of them return (),
6168
;; returns ().
@@ -98,7 +105,7 @@
98105
(or (not lis)
99106
(progn (fn (car lis))
100107
(for-each (cdr lis) fn))))
101-
108+
102109
; Concatenates and flattens lists into a single list
103110
(defun append (first . rest)
104111
(if (eq () rest)

0 commit comments

Comments
 (0)