Skip to content

Commit

Permalink
Merge pull request #539 from justinethier/issue-537-apply-in-icyc
Browse files Browse the repository at this point in the history
Issue 537 apply in icyc
  • Loading branch information
justinethier authored May 22, 2024
2 parents 65fa16c + bb6b3ea commit 6456839
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

Bug Fixes

- Fixed a bug in `apply` where an error may be raised when processing quoted sub-expressions. For example the following would throw an error: `(apply cons '(5 (1 2)))`. Thanks to @srgx for the bug report!
- Fixed a beta expansion optimization bug where code such as the following would cause the compiler to hang. Thanks to Yorick Hardy for the bug report:

(define (compile-forever x) x (compile-forever x))
Expand Down
15 changes: 12 additions & 3 deletions scheme/eval.sld
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,26 @@
((analyze exp *global-environment* rename-env '()) *global-environment*)
((analyze exp (car env) rename-env '()) (car env))))

;; Called from the C runtime to support apply
(define (eval-from-c exp . _env)
(let ((env (if (null? _env) *global-environment* (car _env))))
(eval (wrapc exp) env)))

;; Expressions received from C code are already evaluated, but sometimes too much so.
;; Try to wrap
;; Helper function for eval-from-c
;;
;; Expressions received from C code are already evaluated,
;; however any quoted expressions will have the quotes
;; stripped off. This is a problem for expressions that
;; aren't self evaluating - like (1 2) - so we re-quote
;; the expressions here so a subsequent eval will work.
;;
(define (wrapc exp)
(cond
((application? exp)
(cond
((compound-procedure? (car exp))
((or (primitive-procedure? (car exp))
(compound-procedure? (car exp))
(procedure? (car exp)))
(cons
(car exp)
(map
Expand Down

0 comments on commit 6456839

Please sign in to comment.