[Larceny-users] Ticket 638

Lynn Winebarger owinebar at gmail.com
Mon Apr 20 22:04:20 EDT 2009


This ticket is pretty interesting:

  % cat temp2.sps
  (import (for (rnrs) run expand)
          (rename (only (rnrs base) cons) (cons kons)))

  (free-identifier=? #'cons #'kons)
  % ./larceny --r6rs --program temp2.sps

  Syntax violation: invalid reference

  Attempt to use binding of cons in library (program~19XamJ~2) at
  invalid level -1.  Binding is only available at levels: 0 1 2

Evidently this should evaluate to #t according to the PLT test suite.

First, if it isn't clear, this is occuring because Andre's system is
resolving the reflected identifier in the syntax form, regardless of
whether the form is being evaluated on the right hand side of a syntax
binding form (define-syntax etc).  That's why it reports the
identifier being desired at level -1.

There are multiple issues:
1) The syntax violation is getting triggered too early.  There's an
echo of Will's complaint that R6RS requires compiling programs with
obvious errors to give error messages at run-time
2) The binding is getting resolved too early.  It shouldn't be
resolved until it appears on the right hand side of a syntax binding
form.  Consider whether the following program should produce 'a or 7:

(library (defines x) (export x) (import (rnrs))
(define x 7))

(library (defines foo)
(export foo)
(import (rnrs) (rnrs syntax-case) (for (defines x) (meta -1)))
(define foo (syntax x))
)

(library (expands foo)
(export foo-expander)
(import (for (rnrs) run expand)
        (for (rnrs syntax-case) run expand)
        (for (defines foo) run expand))

(define x 'a)
(define-syntax foo-expander
  (lambda (x)
    (syntax-case x ()
      ((_) foo))))
)

(import (expands foo))
(foo-expander)

This test would imply 'a is the right answer.  That preserves
referential transparency at the site of the macro definiton, even
though the identifier object is constructed outside that context.

3) It doesn't make a lot of sense to have free-identifier=? if you
can't create a free identifier without triggering an expand time
error.

Lynn



More information about the Larceny-users mailing list