Bodies of internal definitions should be expanded before right-hand-side expressions

Bug #165133 reported by Abdulaziz Ghuloum
2
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
Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Fixed in revision 1150.

Changed in ikarus:
status: Confirmed → Fix Committed
Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

This bug report is about to be closed as the fix comitted
previously will be incorporated in the next 0.0.3 release of
Ikarus Scheme, scheduled for January 31, 2008. A release
candidate tarball is available for download from:
http://www.cs.indiana.edu/~aghuloum/ikarus/ikarus-0.0.3-rc1.tar.gz
Please do test it if you have the time and report any issues
you might encounter. Thank you very much for your support.
(Sorry for the duplicates; I'm updating every open bug.)

Changed in ikarus:
milestone: none → 0.0.3
Changed in ikarus:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.