From cf19435efad3146b578c721878db7966cb3add34 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 24 Jan 2023 22:09:40 -0500 Subject: Add and/or. --- chickadee/graphics/seagull.scm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/chickadee/graphics/seagull.scm b/chickadee/graphics/seagull.scm index 6af69eb..b3aef24 100644 --- a/chickadee/graphics/seagull.scm +++ b/chickadee/graphics/seagull.scm @@ -301,6 +301,20 @@ ((l . rest) (loop rest `(primcall / ,exp ,(expand l stage env))))))))) +(define (expand:or exps stage env) + (match exps + (() #f) + ((exp . rest) + (expand `(let ((x ,exp)) (if x x (or ,@rest))) + stage env)))) + +(define (expand:and exps stage env) + (match exps + (() #t) + ((exp . rest) + (expand `(let ((x ,exp)) (if x (and ,@rest) #f)) + stage env)))) + (define (expand:primitive-call operator operands stage env) `(primcall ,operator ,@(expand:list operands stage env))) @@ -368,6 +382,10 @@ (expand:* args stage env)) (('/ args ...) (expand:/ args stage env)) + (('or exps ...) + (expand:or exps stage env)) + (('and exps ...) + (expand:and exps stage env)) ;; Primitive calls: (((? primitive-call-for-stage? operator) args ...) (expand:primitive-call operator args stage env)) -- cgit v1.2.3