tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit df04febf77d29d451d7055630f08964a2e94fb72
parent a14557fd6ea99a03bdba470811639fa16d98d219
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sat, 14 Mar 2020 21:08:21 -0700

Support composing functions with many arguments

Diffstat:
test.c | 2++
tibs/lib.tsp | 10++++++----
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/test.c b/test.c @@ -289,6 +289,8 @@ char *tests[][2] = { { "((compose / sqrt sqr) 18)", "1/18" }, { "((compose - sqrt cube) 4)", "-8" }, { "((compose -) 5/3)", "-5/3" }, + { "((compose - +) 5 6)", "-11" }, + { "((compose sqrt integer *) 4.5 2)", "3" }, { "list mod", NULL }, { "(reverse '(1 2 3 4 5))", "(5 4 3 2 1)" }, diff --git a/tibs/lib.tsp b/tibs/lib.tsp @@ -207,10 +207,12 @@ (else (filter proc (cdr lst))))) (define (compose . procs) - (if procs - (lambda (x) - ((car procs) ((apply compose (cdr procs)) x))) - (lambda (x) x))) + (cond + ((nil? procs) (lambda x x)) + ((nil? (cdr procs)) (car procs)) + (else + (lambda x + ((car procs) (apply (apply compose (cdr procs)) x)))))) (define (reverse l) (recur f ((in l) (out nil))