diff options
author | David Thompson <dthompson2@worcester.edu> | 2023-01-14 12:24:22 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2023-06-08 08:14:41 -0400 |
commit | 1161556e4feab4b845f30eb81a90d8a2461f5347 (patch) | |
tree | 325a08778d9831a310b3039d2a5d9942d641cfad | |
parent | 3b998eb0ff1e1bfea3cee80dc997db5b1704572a (diff) |
Allow + and * to be n-ary.
-rw-r--r-- | chickadee/graphics/seagull.scm | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/chickadee/graphics/seagull.scm b/chickadee/graphics/seagull.scm index c7f8ee9..50ac1e8 100644 --- a/chickadee/graphics/seagull.scm +++ b/chickadee/graphics/seagull.scm @@ -215,6 +215,20 @@ (define params* (lookup-all params env*)) `(lambda ,params* ,(expand body env*))) +(define (expand:+ args env) + (match args + (() 0) + ((n) (expand n env)) + ((n . rest) + `(primcall + ,(expand n env) ,(expand:+ rest env))))) + +(define (expand:* args env) + (match args + (() 1) + ((n) (expand n env)) + ((n . rest) + `(primcall * ,(expand n env) ,(expand:* rest env))))) + (define (expand:primitive-call operator operands env) `(primcall ,operator ,@(expand:list operands env))) @@ -248,6 +262,10 @@ ;; Macros: (('let* (bindings ...) body) (expand:let* bindings body env)) + (('+ args ...) + (expand:+ args env)) + (('* args ...) + (expand:* args env)) ;; Primitive calls: (((? primitive-call? operator) args ...) (expand:primitive-call operator args env)) |