Bruce Korb on Wed, 03 Mar 2004 15:52:15 -0800 writes: > I would like to be able to associate a value with a string. > hash functions look perfect, except I can't use them unless > I have a hash table and there isn't any clear way I've found > to create hash table entries without having a hash table. Why don't you create the empty hash-table first with `make-hash-table'? Then you add entries using `hashq-set!' and alike, and you read values using `hashq-ref' and alike. guile> (make-hash-table 10) #(() () () () () () () () () ()) guile> (define myhash (make-hash-table 10)) guile> (hashq-set! myhash 'myvarname "myvarvalue") "myvarvalue" guile> myhash #(() () () () ((myvarname . "myvarvalue")) () () () () ()) guile> (hashq-ref myhash 'myvarname) "myvarvalue" > I've tried: > > (define (string->symbol (function-returning-string)) > (value-function)) > > I thought that to be really obvious, but I was wrong. Some ways are: guile> (eval-string "(define abc 1)") guile> abc 1 guile> (eval `(define ,(string->symbol "mytestvarname") ,1) (interaction-environment)) guile> mytestvarname 1 guile> > Meanwhile, can someone send me a hint? Another way would be to use an associative list, a list of key and value pairs, and get values using (cdr (assq KEY ASSOCLIST)). guile> (define myassoc (list (cons 'key1 "val1") (cons 'key2 "val2"))) guile> myassoc ((key1 . "val1") (key2 . "val2")) guile> (assq 'key1 myassoc) (key1 . "val1") guile> (cdr (assq 'key1 myassoc)) "val1" guile> > If either of these mecanisms are documented somewhere, > I'd gladly read it. The guile info manual is great :) -- Marco Parrone (marc0) [0x45070AD6]