[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: obscure problem
From: |
Marius Vollmer |
Subject: |
Re: obscure problem |
Date: |
03 Jun 2001 21:44:51 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.102 |
David Pirotte <address@hidden> writes:
> (define (db-utils/build-db-class-slots table-attrs)
> (let ((slots '(db-oid))
^^^^^^^^
This is a literal...
> (slot-defs '((db-oid #:accessor db-oid
> #:init-keyword #:db-oid
> #:init-value #f))))
>
> (for-each (lambda (table-attr)
> (let* ((attr-name (cadr table-attr))
> (slot (string->symbol attr-name))
> (slot-kw (symbol->keyword slot)))
> (set! slots (cons slot slots))
> (set! slot-defs (cons `(,slot #:accessor ,slot
> #:init-keyword ,slot-kw
> #:init-value #f)
> slot-defs))))
> table-attrs)
> (values (reverse! slots)
^^^^^
Which you are modifying here.
You are not allowed to modify literals. `reverse!' will re-link the
cdrs of the list, and also modify its last cdr, which is in the
literal object. The next time thru, `slots' will be initialized with
the exact same object as the first time, but this object has been
modified now.
The solutionis to initialize `slots' and `slot-defs' with fresh
objects each time:
(define (db-utils/build-db-class-slots table-attrs)
(let ((slots (list 'db-oid))
(slot-defs (list '(db-oid #:accessor db-oid
#:init-keyword #:db-oid
#:init-value #f))))
(for-each (lambda (table-attr)
(let* ((attr-name (cadr table-attr))
(slot (string->symbol attr-name))
(slot-kw (symbol->keyword slot)))
(set! slots (cons slot slots))
(set! slot-defs (cons `(,slot #:accessor ,slot
#:init-keyword ,slot-kw
#:init-value #f)
slot-defs))))
table-attrs)
(values (reverse! slots)
(reverse! slot-defs))
))