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.
# cat z.scm (define (%syntax exp cur-env stx-env) (define (syntax 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 zzz.scm (define (pretty-print x)(write x)(newline)) (define trans-define (lambda (l) (if (symbol? (cadr l)) `(define ,(cadr l) ,@(transform (cddr l))) (let ((procname (caadr l)) (formals (cdadr l)) (exps (transform (cddr l)))) `(define ,procname (lambda ,formals ,@exps)))))) (define (transform exp) (cond ((not (pair? exp)) exp) ((and (list? exp) (eq? 'quote (car exp))) exp) ((and (list? exp) (eq? 'define (car exp))) (trans-define exp)) ((list? exp) (map transform exp)) ((pair? exp) (cons (transform (car exp)) (transform (cdr exp)))) (else (begin (pretty-print (list "Which is not entirely unlike tea. " exp))(exit))))) (define (loop) (let ((text (read))) (if (eof-object? text) (exit) (begin (pretty-print (transform text)) (newline) (loop))))) (newline) (loop)
Afficher les réponses par date
You would be able to get it down to:
'(foo syntax 1)
(foo . #'1)
Dunno about the reason.
If you wanted, you could try this simple, unfinished and unpolished printer instead:
(define (pretty-print x) (cond ((symbol? x) (display x) (display " ")) ((string? x) (display (list #" x #" #\space))) ((pair? x) (display #() (let lp ((x x)) (pretty-print (car x)) (let ((d (cdr x))) (cond ((null? d) (display #))) ((pair? d) (lp d)) (else (display #.) (pretty-print d)))))) ((null? x) (display #() (display #))) ((number? x) (display x) (display #\space)) (else (error "don't know type of:" x))))
On 9/14/08, Christian Jaeger christian@pflanze.mine.nu wrote:
You would be able to get it down to:
'(foo syntax 1)
(foo . #'1)
Dunno about the reason.
If you wanted, you could try this simple, unfinished and unpolished printer instead:
(define (pretty-print x) (cond ((symbol? x) (display x) (display " ")) ((string? x) (display (list #" x #" #\space))) ((pair? x) (display #() (let lp ((x x)) (pretty-print (car x)) (let ((d (cdr x))) (cond ((null? d) (display #))) ((pair? d) (lp d)) (else (display #.) (pretty-print d)))))) ((null? x) (display #() (display #))) ((number? x) (display x) (display #\space)) (else (error "don't know type of:" x))))
Thanks, this is all I need for transformations.
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:
1) 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.
Marc
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
Date: Sun, 14 Sep 2008 15:06:32 +0000 From: "naruto canada" narutocanada@gmail.com
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)
MIT Scheme's output can be configured by setting the variable *UNPARSE-ABBREVIATE-QUOTATIONS?* --
(pp ''`,,@foo) ;; Output: ;(quote (quasiquote (unquote (unquote-splicing foo))))
(fluid-let ((*unparse-abbreviate-quotations?* #t)) (pp ''`,,@foo)) ;; Output: ;'`,,@foo
It would surprise me if Gambit had no similar facility for configuring the format of its output.