From bb8d10f80c667f63618c99b078448fb6e2156278 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Sat, 14 Apr 2018 17:59:41 -0700 Subject: [PATCH] Optimize code generated for let*, let*-syntax, and letrec. Thanks to Patric Jonsson for noticing this. --- src/runtime/mit-macros.scm | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/runtime/mit-macros.scm b/src/runtime/mit-macros.scm index 2393cd416..a1c87cd74 100644 --- a/src/runtime/mit-macros.scm +++ b/src/runtime/mit-macros.scm @@ -142,10 +142,12 @@ USA. (expand-let* scons-let-syntax bindings body-forms)))))) (define (expand-let* scons-let bindings body-forms) - (fold-right (lambda (binding expr) - (scons-let (list binding) expr)) - (apply scons-let '() body-forms) - bindings)) + (if (pair? bindings) + (fold-right (lambda (binding expr) + (scons-let (list binding) expr)) + (apply scons-begin body-forms) + bindings) + (apply scons-let '() body-forms))) (define $letrec (spar-transformer->runtime @@ -160,9 +162,14 @@ USA. (scons-let (map (lambda (id) (list id (unassigned-expression))) ids) - (apply scons-let - (map list temps vals) - (map scons-set! ids temps)) + (cond ((not (pair? ids)) + (default-object)) + ((not (pair? (cdr ids))) + (scons-set! (car ids) (car vals))) + (else + (apply scons-let + (map list temps vals) + (map scons-set! ids temps)))) (scons-call (apply scons-lambda '() body-forms))))))))) (define $letrec* -- 2.25.1