tisp

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

commit 9f66f5ff824b3e976ebe9bfd86d2e7266ce19cfd
parent 2c5affc676759954b723c5267aadfcf81540451d
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sun,  4 Aug 2019 14:56:54 -0700

Add foreach to apply function on each element

Utilize to allow disp-string to take multiple arguments

Diffstat:
tibs/lib.tsp | 17++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/tibs/lib.tsp b/tibs/lib.tsp @@ -96,6 +96,11 @@ (define (apply fn args) (eval (cons fn args))) +(define (foreach fn args) + (unless (nil? args) + (fn (car args)) + (foreach fn (cdr args)))) + (define (map fn lst) (cond (lst (cons (fn (car lst)) @@ -146,9 +151,11 @@ ;;; Printing (define (newline) (print "\n")) -(define (disp . x) (apply print x) (newline)) -(define (disp-string str) - (if (string? str) - (print "\"" str "\"") - (print str)) +(define (disp . str) (apply print str) (newline)) +(define (disp-string . str) + (foreach (lambda (s) + (if (string? s) + (print "\"" s "\"") + (print s))) + str) (newline))