RE: (dsssl) access variable value with a string

Subject: RE: (dsssl) access variable value with a string
From: "Nilsson, Peter" <pni@xxxxxxxxx>
Date: Fri, 16 Mar 2001 09:29:55 +0100
> -----Original Message-----
> From: hoenicka_markus [mailto:hoenicka_markus@xxxxxxxxxxxxxx]

[...]
(define bar "none")

(define styleparams
  (list
    (cons 'foo foo)
    (cons 'bar bar)))

(define (symbol-value varname)
  (let ((a (assoc (string->symbol varname) styleparams)))
    (if a (cadr a) #f)))

Then I try to get the value of say foo with:
 (symbol-value var)
where var is the string "foo".

Jade says:
openjade:E: 1st argument for primitive "list-ref" of wrong type: "(foo .
"none")" not a list


Since your assoc lst is a list of pairs (which in this case is not a list of
proper lists), you should use just cdr instead of cadr. I.e. the value yo7u
want is the cdr of the return value of assoc.

If you define a list like
(define styleparams
  '(("foo" none) ("bar" "none") ...))
you'd use cadr, because the cdr of the return value of assoc would be a list
(i.e. a pair containing ("none" . ()), and to get "none", you need to the
the car of that list.

Hope this clarifies more than confuses...

Regards,
/Peter

 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist

Current Thread