[gambit-list] bug with write?
Marc Feeley
feeley at iro.umontreal.ca
Sun Sep 14 09:47:57 EDT 2008
On 12-Sep-08, at 10:11 PM, naruto canada wrote:
> hi
>
> I believe there might be a problem with gambit-c's write function,
> gambit-c seem to treat the word "syntax" with special meaning, (I'm
> not entirely sure about this)
> or that this is a problem with inner defines?
> I was testing some transformations and ran into this problem:
>
> cat z.scm | mzscheme -m -f zzz.scm
>
> (define %syntax (lambda (exp cur-env stx-env) (define syntax (lambda
> (exp cur-env stx-env) (if (eq? stx-env cur-env) (%wrap-syntax exp
> stx-env 1) (%wrap-syntax (syntax exp (cdr cur-env) stx-env) cur-env
> 1)))) (%wrap-syntax (syntax exp cur-env stx-env) cur-env -1)))
>
> cat z.scm | /usr/gambitc/bin/gsi zzz.scm
>
> (define %syntax (lambda (exp cur-env stx-env) (define . #'(lambda (exp
> cur-env stx-env) (if (eq? stx-env cur-env) (%wrap-syntax exp stx-env
> 1) (%wrap-syntax (syntax exp (cdr cur-env) stx-env) cur-env 1))))
> (%wrap-syntax (syntax exp cur-env stx-env) cur-env -1)))
>
> the word "syntax" got translated into ". #'", which is incorrect.
Write knows about read-macros (such as 'x `x and ,x) and uses them
when writing 2 element lists whose car is "quote", "quasiquote",
"unquote":
Gambit v4.2.8
> '(foo 'bar)
(foo 'bar)
> '(foo . 'bar)
(foo . 'bar)
> '(foo quote bar)
(foo . 'bar)
> '(foo . ,bar)
(foo . ,bar)
> '(foo unquote bar)
(foo . ,bar)
Other Scheme systems behave this way too, but not consistently (it
seems that many systems use the read-macros when writing, but not in
the cdr of a list). Gambit does detect cases where the read-macro is
in the cdr of a list.
Now Gambit supports more read-macros than R5RS. It has #'foo =
(syntax foo) and #,foo = (unsyntax foo) and a few more. So you get
this:
> '(foo (syntax bar))
(foo #'bar)
> '(foo . (syntax bar))
(foo . #'bar)
> '(foo syntax bar)
(foo . #'bar)
> '(foo . #'bar)
(foo . #'bar)
> '(foo syntax bar)
(foo . #'bar)
> '(foo unsyntax bar)
(foo . #,bar)
> '(foo quasisyntax bar)
(foo . #`bar)
Gambit behaves consistently, but perhaps also suprizingly. So what
the best approach for Gambit to take? Here are some orthogonal ways
to deal with the issue:
1) by default only do this for the R5RS read-macros (i.e. `x 'x ,x
and , at x)
2) by default never use read-macros when in the cdr of a list
3) allow user to select individual read-macros to support
Please place your vote now... I'm inclined to have 1 and 2 to bring
Gambit closer to what users from other systems expect. It also means
that by default a datum written by Gambit will be readable by other
Scheme systems.
Marc
More information about the Gambit-list
mailing list