[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] Problem with (symbol->string) in Chicken 4.0
From: |
William Ramsay |
Subject: |
[Chicken-users] Problem with (symbol->string) in Chicken 4.0 |
Date: |
Thu, 30 Apr 2009 08:30:31 -0400 |
User-agent: |
Thunderbird 2.0.0.17 (X11/20080914) |
Hi,
I've recently moved from Chicken-3.4.0 to Chicken-4.0.0.
I've been using a structure macro I got from /Teach Yourself Scheme in
Fixnum Days/ by Dorai Sitaram. It's worked fine in 3.4 but fails in
4.0 and I can figure out why. It fails on line 4 of (define-syntax
define-structure) with a compile error starting that s is not a
symbol. It is trying to read (define-structure customer ...) at the
bottom of the listing. Why is the word customer no longer a symbol?
Bill
My entire code is here
(define list-position
(lambda (o l)
(let loop ((i 0) (l l))
(if (null? l) #f
(if (eqv? (car l) o) i
(loop (+ i 1) (cdr l)))))))
(define-syntax define-structure
(lambda (s . ff)
(let
((name (symbol->string s)) (n (length ff)))
(let*
((n+1 (+ n 1))
(vv (make-vector n+1)))
(let loop ((i 1) (ff ff))
(if (<= i n)
(let
((f (car ff)))
(vector-set! vv i (if (pair? f) (cadr f) '(if #f #f)))
(loop (+ i 1) (cdr ff)))))
(let
((ff (map (lambda (f)
(if (pair? f) (car f) f))
ff)))
`(begin
(define ,(string->symbol (string-append "make-" name))
(lambda fvfv
(let
((st (make-vector ,n+1)) (ff ',ff))
(vector-set! st 0 ',s)
,@(let loop ((i 1) (r '()))
(if (>= i n+1)
r
(loop (+ i 1)
(cons `(vector-set! st ,i ,(vector-ref vv
i)) r))))
(let loop ((fvfv fvfv))
(if (not (null? fvfv))
(begin
(vector-set! st (+ (list-position (car fvfv) ff) 1)
(cadr fvfv))
(loop (cddr fvfv)))))
st)))
,@(let loop ((i 1) (procs '()))
(if (>= i n+1) procs
(loop (+ i 1)
(let
((f (symbol->string (list-ref ff (- i 1)))))
(cons `(define ,(string->symbol (string-append
name "." f))
(lambda (x) (vector-ref x ,i)))
(cons `(define ,(string->symbol
(string-append
"set!" name "." f))
(lambda (x v)
(vector-set! x ,i v)))
procs))))))
(define ,(string->symbol (string-append name "?"))
(lambda (x)
(and (vector? x)
(eqv? (vector-ref x 0) ',s))))))))))
(define-structure customer (first-name "")
(last-name "")
(company "")
(phone 0))
- [Chicken-users] Problem with (symbol->string) in Chicken 4.0,
William Ramsay <=