tisp

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

commit a713cee597378d2a201c9c7a9d705bf5cbb312a7
parent 66a687024fcce8d66d22484b37235fcaa9db4de4
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Fri,  3 Jan 2020 19:29:23 -0800

Add compose function

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

diff --git a/test.c b/test.c @@ -274,6 +274,10 @@ char *tests[][2] = { { "(filter positive? '(1 2 -4 5 -9 10))", "(1 2 5 10)" }, { "(filter odd? '(8 6 17 9 82 34 27))", "(17 9 27)" }, { "(filter integer? '(1/2 3.e-2 9/3 3.2 0.0 8 17))", "(3 8 17)" }, + { "((compose - sqrt) 9)", "-3" }, + { "((compose / sqrt sqr) 18)", "1/18" }, + { "((compose - sqrt cube) 4)", "-8" }, + { "((compose -) 5/3)", "-5/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 @@ -180,6 +180,12 @@ ((proc (car lst)) (cons (car lst) (filter proc (cdr lst)))) (else (filter proc (cdr lst))))) +(define (compose . procs) + (if procs + (lambda (x) + ((car procs) ((apply compose (cdr procs)) x))) + (lambda (x) x))) + (define (reverse l) (recur f ((in l) (out nil)) (if (pair? in)