guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I really do this?


From: Mikael Djurfeldt
Subject: Re: How do I really do this?
Date: Sat, 06 Mar 2004 15:50:22 -0500
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Bruce Korb <address@hidden> 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.
> 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?

(define t (make-hash-table))
(hash-set! t (function-returning-string) (value-function))

Then you can lookup values again with (hash-ref t <string>).

This is all documented in the Guile refence manual in the info node
'Hash Tables'.

You don't gain anything by trying to piggyback on 'define', because
'define' uses exactly the same hash table internally as that returned
by (make-hash-table).

M




reply via email to

[Prev in Thread] Current Thread [Next in Thread]