Bodies of internal definitions should be expanded before right-hand-side expressions
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Ikarus Scheme |
Fix Released
|
Low
|
Abdulaziz Ghuloum |
Bug Description
Currently, the right-hand-side expressions of internal definitions are expanded before the body. The rationale was that you should get the errors in the order in which they appear in the file. There is a better rationale for expanding the body expressions first (based on first-hand experience porting the 11000-line compiler benchmark to an r6rs library).
Suppose you have an R5RS program, where definitions and expressions are mixed in arbitrary ways (imagine the code being much longer):
(define (main) (bar))
(define (foo x)
(display x))
(foo "a b c\n")
(define (t x) x)
(define (bar)
(display "bar\n"))
(main)
Now you want to put everything in a library, except for the final call to main, so you make a library like:
(library (R)
(export main)
(import (rnrs))
(define (main) (bar))
(define (foo x)
(display x))
(foo "a b c\n")
(define (t x) x)
(define (bar)
(display "bar\n")))
If you try importing that library right now, what you get is:
Unhandled exception:
Condition components:
1. &error
2. &who: expander
3. &message: "unbound identifier"
4. &irritants: (bar)
But you swear that there is a binding for bar. Look, a (define (bar) ---).
Now when I was porting that code, I knew that the reason for the expander not seeing the definition of bar is because it found something before bar that made it terminate the "definitions" context and switched to the "expressions" context then went on to expanding the right-hand-side expression of main, which contained a reference to bar which it has not seen yet. Now if it was expanding the body first, then it would've seen the (define (t x) x) in expression context and it would've said:
Unhandled exception
Condition components:
1. &error
2. &who: expander
3. &message: "a definition was found where an expression was expected"
4. &irritants: ((define (t x) x))
which is more useful since you only have to look at the line immediately above it to see the cause of the error.
It probably would've taken me less time to fix this than to report it. Oh well, maybe someone somewhere will learn something from it. :-)
Changed in ikarus: | |
assignee: | nobody → aghuloum |
importance: | Undecided → Low |
status: | New → Confirmed |
Changed in ikarus: | |
status: | Fix Committed → Fix Released |
Fixed in revision 1150.