From 6d0c8c2b6a9e22ebd53d7ef592dda893784a77e7 Mon Sep 17 00:00:00 2001 From: whiteline Date: Mon, 26 Jun 2023 16:19:12 +0200 Subject: [PATCH] finally conceptually got it right --- lisp.scm | 4 +++- util.scm | 12 +++++++++++- world.scm | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lisp.scm b/lisp.scm index 6db6d33..f36b6f6 100644 --- a/lisp.scm +++ b/lisp.scm @@ -51,6 +51,8 @@ `((test . ,(lambda function-args (display "test function called") (newline))) + (begin . ,(lambda function-args + (mapn lisp-eval function-args))) (if . ,(lambda function-args (match function-args ((e x y) (if (lisp-eval e) @@ -105,7 +107,7 @@ (lisp-exit "malformed lambda expression"))) (_ (lisp-exit "malformed lambda expression"))))))) - (lisp-eval body)) + (lisp-eval (cons 'begin body))) (call/cc (lambda (lisp-exit) (cons #t (lisp body (list (list)) (compose lisp-exit (curry cons #f)))))))) diff --git a/util.scm b/util.scm index c2269cb..77da998 100644 --- a/util.scm +++ b/util.scm @@ -1,9 +1,10 @@ ;;; Module storing utility functions for common use. -(module util (curry applied thunk just perhaps compose-symbols) +(module util (curry applied thunk just perhaps compose-symbols mapn) (import scheme) (import chicken.base) (import srfi-13) + (import matchable) ;; Partial application function for binary functions. (define (curry fn a) @@ -33,6 +34,15 @@ (fn arg) arg)) + (define (mapn fn ln) + (match ln + (() '()) + ((x) (fn x)) + (_ (begin + (fn (car ln)) + (mapn fn (cdr ln)))))) + + ;; Compose the argument symbols into a new symbol, joined by '-'. ;; (compose-symbols 'apple 'pear 'orange) = 'apple-pear-orange (define (compose-symbols . ln) diff --git a/world.scm b/world.scm index 7bd7fb9..96e17d6 100644 --- a/world.scm +++ b/world.scm @@ -142,7 +142,7 @@ ;; Match a tag against a list of objects, checking for its tag and its aliases. - (define (match-object tag objects) + (match-object tag objects) (let loop ((objects objects)) (if (null? objects) #f