tisp

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

commit 8eec941624c1c1b8cc600b0885760beb97047f7a
parent f5f83015e4af8f3def601e7f077b94cea3d77364
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Fri, 20 Mar 2020 01:47:33 -0700

Add default function to return a val if given nil

Diffstat:
tibs/lib.tsp | 8++++++++
1 file changed, 8 insertions(+), 0 deletions(-)

diff --git a/tibs/lib.tsp b/tibs/lib.tsp @@ -87,6 +87,14 @@ `(unless ,expr (error 'assert "assertion " ',expr " failed"))) +; TODO support any sized list n depending on size of optional val +(define (default n val) + (cond + ((nil? n) val) + ((and (pair? n) (nil? (cdr n))) + (car n)) + (else (error 'default "expected only 1 optional argument")))) + ;;; Control Flow ; TODO if b = pair and car b = else use cdr b (defmacro (if con a b)