Issue #331 - Ensure map evaluates in order

Reverse so everything is evaluated in order, then reverse again so final results are in order.
This commit is contained in:
Justin Ethier 2019-08-07 13:29:43 -04:00
parent 7420b34f84
commit f211d350e0

View file

@ -614,17 +614,22 @@
rename-env rename-env
local-renamed)))))) local-renamed))))))
(cond (cond
;; special case - a begin can splice in definitions, so we can't use the ;; special case - begin can splice in definitions, so we can't use the
;; built-in macro that just expands them in a new lambda scope. Instead ;; built-in macro that just expands them within a new lambda scope.
;; we nest them below within the same lexical environment. ;; Instead we nest them below within the same lexical environment.
((eq? 'begin op) ((eq? 'begin op)
;(newline) ;(newline)
;(display "/* ") ;(display "/* ")
;(write (list exp)) ;(write (list exp))
;(display "*/ ") ;(display "*/ ")
(let ((fncs (map (lambda (expr) (let ((fncs
;; Our map starts from the end, we reverse
;; so everything is evaluated in order, then
;; reverse again so results are in order
(reverse
(map (lambda (expr)
(analyze expr a-env rename-env local-renamed)) (analyze expr a-env rename-env local-renamed))
(cdr exp)))) (reverse (cdr exp))))))
(lambda (env) (lambda (env)
(foldl (lambda (fnc _) (fnc env)) #f fncs)))) (foldl (lambda (fnc _) (fnc env)) #f fncs))))
;; compiled macro ;; compiled macro