summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2023-02-25 10:42:36 -0500
committerDavid Thompson <dthompson2@worcester.edu>2023-06-08 08:14:41 -0400
commita564307a9473a0a5d3b5413d14595aaead145cd4 (patch)
tree34e08cec5d7756e54185bc63b29a7d767382561d
parent9c97bdffef0e2143eb156d9158492b067f0a1b50 (diff)
Improve partial evaluation of 'if' expressions.
-rw-r--r--chickadee/graphics/seagull.scm13
1 files changed, 10 insertions, 3 deletions
diff --git a/chickadee/graphics/seagull.scm b/chickadee/graphics/seagull.scm
index 70ff46b..0df9b89 100644
--- a/chickadee/graphics/seagull.scm
+++ b/chickadee/graphics/seagull.scm
@@ -1194,9 +1194,16 @@
(map (lambda (exp) (simplify exp env)) exps))
(define (simplify:if predicate consequent alternate env)
- `(if ,(simplify predicate env)
- ,(simplify consequent env)
- ,(simplify alternate env)))
+ (define predicate* (simplify predicate env))
+ (cond
+ ((eq? predicate* #t)
+ (simplify consequent env))
+ ((eq? predicate* #f)
+ (simplify alternate env))
+ (else
+ `(if ,predicate*
+ ,(simplify consequent env)
+ ,(simplify alternate env)))))
(define (simplify:lambda params body env)
`(lambda ,params ,(simplify body env)))