[gambit-list] bug with write?
naruto canada
narutocanada at gmail.com
Fri Sep 12 22:11:20 EDT 2008
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 , at 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)
More information about the Gambit-list
mailing list