There is a very strange behavior of the Ikarus REPL that I have discovered
a few months ago, but which I found difficult to reduce to a simple test case,
so that I have suffered it. I have now the simple enough test case.

Consider the following x.sls library, which is a greatly simplified version
of my sweet-macros library:

$ cat x.sls
(library (x)
(export syntax-match def-syntax)
(import (rnrs))

(define-syntax syntax-match
  (lambda (y)
    (syntax-case y (sub)
      ((syntax-match x (literal ...) (sub patt skel) ...)
       (for-all identifier? #'(literal ...))
       #'(syntax-case x (literal ...)
           (patt skel)
           ...))
      )))

(define-syntax def-syntax
  (lambda (y)
    (syntax-case y ()
     ((def-syntax name transformer)
          #'(define-syntax name
              (lambda (x)
                (syntax-case x (<source>)
                  ((name <source>) #''(... (... transformer))); comment-me!
                  (x (transformer #'x))))))

    )))
)

The library defines a ``syntax-match`` form which is a simplified version
of syntax-case (no fenders), and such that each clause is
introduced by a literal identifier ``sub``. The library also
defines a ``def-syntax`` form which stores the source code
of the transformer (this happens in the line marked as ``comment-me!``).
The code as it stands is - I believe - correct; you can test it
with the following script:

$ cat xx.ss
(import (rnrs) (x))
(def-syntax macro (lambda (y) (syntax-match y () (sub (ctx x) #'x))))
(display (macro <source>))

Running it, you get the source code of the macro, as you would expect:

$ scheme-script xx.ss
(lambda (y) (syntax-match y () (sub (ctx x) #'x)))

The strange issue is that the script *does not work* at the REPL:

$ ikarus xx.ss
Ikarus Scheme version 0.0.4-rc1+ (revision 1767, build 2009-04-13)
Copyright (c) 2006-2009 Abdulaziz Ghuloum

Unhandled exception:
 Condition components:
   1. &message: "invalid syntax"
   2. &syntax:
       form: (syntax-match y () (sub (ctx x) #'x))
       subform: #f
   3. &source-position:
       file-name: "xx.ss"
       character: 51
   4. &trace: #<syntax (syntax-match y () (sub (ctx x) #'x)) [char 51 of xx.ss]>

It looks like ``syntax-match`` is unable to recognize the literal identifier
``sub`` at the REPL.

I have tracked down the problem at the line marked as ``comment-me!``.
If I remove it (and I lose the feature of storing the source code
of the macro) there are no differences between the REPL and script
mode. I am baffled about what could be the origin of the problem,
which is quite disturbing, since it means that I cannot define any
macro at the REPL using sweet-macros, and I can test things only
non-interactively, with R6RS scripts :-(

Is this a bug of the REPL, or what? This has caused me lots of
pain and a head scratching ...

Reply via email to