Re: [Chicken-users] Problem with (symbol->string) in Chicken 4.0
On Thu, Apr 30, 2009 at 2:59 PM, William Ramsay wrote: > Can you be a little more explicit in what you mean? Adding that just > produces more errors. > John Cowan wrote: >> (lambda body rename compare) >> (define s (car body)) >> (define ff (cdr body)) Change this: (define-syntax define-structure (lambda (s . ff) (let ((name (symbol->string s)) (n (length ff))) to this: (define-syntax define-structure (lambda (form rename compare) (let* ((s (cadr form)) (ff (cddr form)) (name (symbol->string s)) (n (length ff))) ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Problem with (symbol->string) in Chicken 4.0
Can you be a little more explicit in what you mean? Adding that just produces more errors. John Cowan wrote: William Ramsay scripsit: 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? In Chicken 4, a bare lambda in define-syntax is an explicit-renaming macro, so the simplest change is this: (define-syntax define-structure (lambda (s . ff) (lambda body rename compare) (define s (car body)) (define ff (cdr body)) ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Problem with (symbol->string) in Chicken 4.0
William Ramsay scripsit: > 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? In Chicken 4, a bare lambda in define-syntax is an explicit-renaming macro, so the simplest change is this: > (define-syntax define-structure > (lambda (s . ff) (lambda body rename compare) (define s (car body)) (define ff (cdr body)) -- Newbies always ask: John Cowan "Elements or attributes? http://www.ccil.org/~cowan Which will serve me best?" co...@ccil.org Those who know roar like lions; Wise hackers smile like tigers. --a tanka, or extended haiku ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Problem with (symbol->string) in Chicken 4.0
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 "") (phone0)) ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users