From d038bc439d8b0801671546e73471cb03279d7852 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 25 Feb 2023 10:40:15 -0500 Subject: Allow lookup* to return a default. --- chickadee/graphics/seagull.scm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/chickadee/graphics/seagull.scm b/chickadee/graphics/seagull.scm index d03de86..abd4429 100644 --- a/chickadee/graphics/seagull.scm +++ b/chickadee/graphics/seagull.scm @@ -142,8 +142,12 @@ (make-exception-with-message "seagull: unbound variable") (make-exception-with-irritants (list name (env-names env))))))) -(define (lookup* name env) - (assq-ref env name)) +(define* (lookup* name env #:optional default) + (let loop ((env env)) + (match env + (() default) + (((k . v) . rest) + (if (eq? k name) v (loop rest)))))) (define (lookup-all names env) (map (lambda (name) (lookup name env)) names)) -- cgit v1.2.3