On 9/14/08, Marc Feeley feeley@iro.umontreal.ca wrote:
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
- (%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:
- by default only do this for the R5RS read-macros (i.e. `x 'x ,x
and ,@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.
I have no clear idea about what R5RS read-macro issues are, as I'm at about the level of R0RS SICP student level-- so I will abstain from voting.
I will only note that mit-scheme print everything literally including all the quotes (quasiquotes unquote-spicing unquote)-- which is good for reading and pretty to look at. (All the quotes look like some sort of swearing when you are not used to it) Maybe a "pretty-print-for-students" version -- but wait -- students should write their own versions right? Lucky they weren't told to write a parser by themselves, but I digress.
Marc