Opened 13 years ago

Last modified 12 years ago

#444 closed defect

Symbol lookup fails in modules in conjunction with renaming macros — at Version 9

Reported by: Moritz Heidkamp Owned by:
Priority: major Milestone: 4.9.0
Component: expander Version: 4.6.x
Keywords: Cc:
Estimated difficulty:

Description (last modified by Moritz Heidkamp)

I stumbled upon a problem when trying to generate a
foreign-lambda call in an IR macro. Somehow it failed to
re-rename the injected void symbol correctly. This resulted in
it referring to #%void aka ##sys#void. The following
reproduces the problem:

(import foreign)

(foreign-declare "void foo() { printf(\"hi\\n\"); }")

(module foo
  (bar)
  (import chicken scheme foreign)
  
  (define-syntax bar
    (ir-macro-transformer
     (lambda (x i c)
       `((foreign-lambda ,(i 'void) ,(i 'foo)))))))

(import foo)
(bar)

Note that it does work outside the module, though. So does the ER
version:

(er-macro-transformer
     (lambda (x r c)
       `((,(r 'foreign-lambda) void foo))))

This might suggest that the problem lies within the IR macro
implementation but sjamaan is almost certain that the symbol lookup
must be going wrong somewhere and that it only fails in the IR version
because there's more renaming taking place. Thinking about it some
more he concluded that there is a chance that it's a problem in the IR
implementation anyway. This ticket mainly serves as a reminder for him
to think about that some more. However, other interested parties are
welcome to contribute their thoughts as well, of course!

P.S.: Mr Z. found out that (import (except chicken void)) helps
to make the IR version. This might be a work-around for people
experiencing the same issue and looking for a work-around.

Change History (10)

comment:1 Changed 13 years ago by sjamaan

After some investigation, I found a difference in behaviour between Chicken and other Schemes:

(define else #f)
(cond (else 1)) => 1

In other Schemes (s48, Mzscheme and Guile - but not Gauche or Chibi) it returns unspecified.

comment:2 Changed 13 years ago by sjamaan

Gambit behaves as Chicken, Gauche and Chibi

comment:3 Changed 13 years ago by sjamaan

eh, the relevance of this comment about "else" is that a COND macro written as IR macro would behave the same as s48 and mzscheme in all cases. One written as ER macro would behave as Chicken (since chicken's cond IS written as an er macro)

comment:4 in reply to:  1 Changed 13 years ago by Moritz Heidkamp

Bigloo and MIT Scheme also behave as Chicken. Ikarus and Ypsilon don't allow definition of else. Racket behaves as s48 and friends.

comment:5 in reply to:  1 Changed 13 years ago by Moritz Heidkamp

And, for the record, Mosh behaves like s48, too :-)

comment:6 Changed 13 years ago by sjamaan

Correction: According to Alex, chibi only behaves like that at the toplevel because this redefines the "else" that "cond" matches against. It returns undefined when this is inside a module.

comment:7 Changed 13 years ago by sjamaan

This very issue (what to do with "free" identifiers) is under consideration for WG1 of R7RS:

http://trac.sacrideo.us/wg/ticket/83

comment:8 Changed 13 years ago by sjamaan

Here's a fun one:

(define (foo) (define else #f) (cond (else 1)))
(foo) => 1

(define (foo) (letrec ((else #f)) (cond (else 1))))
(foo) => ; #<unspecified>

According to R5RS, this should behave the same
http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-8.html#%_sec_5.2.2

comment:9 Changed 13 years ago by Moritz Heidkamp

Description: modified (diff)

Oops, the original problem reproduction code contained the (except chicken void) work-around which lead to it not reproducing the problem anymore. I fixed this now!

Changed 13 years ago by sjamaan

Attachment: ir-fix.patch added

Fix for IR renaming bug

Note: See TracTickets for help on using tickets.