From f8555f796d8e4f077cab2e9edc8f2e028a74513b Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 21 Jul 2022 21:41:47 -0400 Subject: [PATCH] Issue #489 - Guarantee order of eval begin exprs Guarantee that sub-expressions of a begin are evaluated in order. The code was reversing the results of a map. However map is not necessarily guaranteed to evaluate its arguments in any given order because it could be optimized into another function such as `Cyc-map-loop-1`. Instead we just use the optimized function directly as a more general `map` is not required here and this function is guaranteed to process its argument list in a predicable order. --- CHANGELOG.md | 4 ++++ scheme/eval.sld | 11 +++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08c46d2f..cd48329c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ Features Bug Fixes +- Prevent an error when evaluating a `begin` expression that contains both a macro definition and an application of that macro. For example: + + begin (define-syntax foo (syntax-rules () ((foo) 123))) (foo)) + - Fix a regression where `c-compiler-options` was not recognized as a top level form by programs. - Enforce a maximum recursion depth when printing an object via `display` and `write`, and when comparing objects via `equal?`. This prevents segmentation faults when working with circular data structures. diff --git a/scheme/eval.sld b/scheme/eval.sld index f45ec40a..ba33ae11 100644 --- a/scheme/eval.sld +++ b/scheme/eval.sld @@ -636,14 +636,9 @@ ;(display "/* ") ;(write (list exp)) ;(display "*/ ") - (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)) - (reverse (cdr exp)))))) + (let ((fncs (Cyc-map-loop-1 (lambda (expr) + (analyze expr a-env rename-env local-renamed)) + (cdr exp)))) (lambda (env) (foldl (lambda (fnc _) (fnc env)) #f fncs)))) ;; compiled macro