* How do I really do this?
@ 2004-03-03 23:52 Bruce Korb
0 siblings, 0 replies; 4+ messages in thread
From: Bruce Korb @ 2004-03-03 23:52 UTC (permalink / raw)
[-- Attachment #1: Type: text, Size: 527 bytes --]
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.
I've tried:
(define (string->symbol (function-returning-string))
(value-function))
I thought that to be really obvious, but I was wrong.
If either of these mecanisms are documented somewhere,
I'd gladly read it. Meanwhile, can someone send me a hint?
Thank you. - Bruce
[-- Attachment #2: Type: text/plain, Size: 139 bytes --]
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How do I really do this?
[not found] <40466FAF.3A286BB0@veritas.com>
@ 2004-03-10 0:29 ` Marco Parrone
2004-03-10 1:13 ` Christopher Cramer
2004-03-10 8:22 ` Thien-Thi Nguyen
2 siblings, 0 replies; 4+ messages in thread
From: Marco Parrone @ 2004-03-10 0:29 UTC (permalink / raw)
Cc: guile-user
[-- Attachment #1.1: Type: text/plain, Size: 1680 bytes --]
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) <marc0@autistici.org> [0x45070AD6]
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]
[-- Attachment #2: Type: text/plain, Size: 139 bytes --]
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How do I really do this?
[not found] <40466FAF.3A286BB0@veritas.com>
2004-03-10 0:29 ` How do I really do this? Marco Parrone
@ 2004-03-10 1:13 ` Christopher Cramer
2004-03-10 8:22 ` Thien-Thi Nguyen
2 siblings, 0 replies; 4+ messages in thread
From: Christopher Cramer @ 2004-03-10 1:13 UTC (permalink / raw)
On Wed, Mar 03, 2004 at 03:52:15PM -0800, Bruce Korb wrote:
> I've tried:
>
> (define (string->symbol (function-returning-string))
> (value-function))
You need to use eval to do something like this.
guile> (eval `(define ,(string->symbol "foo") 'bar) (current-module))
guile> foo
bar
Not sure why you'd want to avoid explicitly using a hash table. That's
pretty much what define does anyway.
--
Christopher Cramer <crayc@pyro.net> <http://www.pyro.net/~crayc/>
In politics you have to understand not where the voters are when a poll
is taken, but where they are likely to end up on Election Day.
-- Rep. Tom Davis, former NRCC Chairman
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How do I really do this?
[not found] <40466FAF.3A286BB0@veritas.com>
2004-03-10 0:29 ` How do I really do this? Marco Parrone
2004-03-10 1:13 ` Christopher Cramer
@ 2004-03-10 8:22 ` Thien-Thi Nguyen
2 siblings, 0 replies; 4+ messages in thread
From: Thien-Thi Nguyen @ 2004-03-10 8:22 UTC (permalink / raw)
Cc: guile-user
From: Bruce Korb <bkorb@veritas.com>
Date: Wed, 03 Mar 2004 15:52:15 -0800
Meanwhile, can someone send me a hint?
an alist w/ strings as keys works w/ `equal?', `member' and `assoc-ref'.
thi
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-03-10 8:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <40466FAF.3A286BB0@veritas.com>
2004-03-10 0:29 ` How do I really do this? Marco Parrone
2004-03-10 1:13 ` Christopher Cramer
2004-03-10 8:22 ` Thien-Thi Nguyen
2004-03-03 23:52 Bruce Korb
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).