unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* How do I really do this?
@ 2004-03-03 23:52 Bruce Korb
  2004-03-06 12:17 ` Neil Jerram
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Bruce Korb @ 2004-03-03 23:52 UTC (permalink / raw)



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


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I really do this?
  2004-03-03 23:52 How do I really do this? Bruce Korb
@ 2004-03-06 12:17 ` Neil Jerram
  2004-03-06 17:43   ` Bruce Korb
  2004-03-06 20:50 ` Mikael Djurfeldt
  2004-03-08  2:27 ` Paul Jarc
  2 siblings, 1 reply; 13+ messages in thread
From: Neil Jerram @ 2004-03-06 12:17 UTC (permalink / raw)
  Cc: guile-devel

Bruce Korb <bkorb@veritas.com> writes:

> I would like to be able to associate a value with a string.

What level of uniqueness do you want?  If two strings with the same
contents are read twice, should the value associated with one
automatically be associated with the other.

> 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

You what?  What does it mean to create a hash table entry without a
hash table?

> I've tried:
> 
>   (define (string->symbol (function-returning-string))
>           (value-function))

This is bizarre and makes no sense.  The syntax is wrong, and I can't
guess what you mean.
 
> 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

No, although I'd like to!  Please ask again with more clarity.

        Neil


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I really do this?
  2004-03-06 12:17 ` Neil Jerram
@ 2004-03-06 17:43   ` Bruce Korb
  2004-03-06 18:00     ` Neil Jerram
  0 siblings, 1 reply; 13+ messages in thread
From: Bruce Korb @ 2004-03-06 17:43 UTC (permalink / raw)
  Cc: guile-devel

Neil Jerram wrote:
> 
> Bruce Korb <bkorb@veritas.com> 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
> 
> You what?  What does it mean to create a hash table entry without a
> hash table?

How do I get a hash table started?  I've grepped throught he
ice-9 code and I'm sure something's in there.  But looking at
code around 'hash-create' and 'hashq-create' or even just "hash"
didn't yield anything that worked.  I guess I just need something
really explicit, like:

   (define my-hash-table (hash-table-create))

except that doesn't work.  What does?

> > I've tried:
> >
> >   (define (string->symbol (function-returning-string))
> >           (value-function))
> 
> This is bizarre and makes no sense.  The syntax is wrong, and I can't
> guess what you mean.

OK.  This works:

   (define sym-name (value-function))

So, why doesn't this:

   (define (string->symbol "sym-name") (val-func))

If the "sym-name" in the first expression is a symbol, then
why isn't the string->symbol function yielding a symbol?

> > 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
> 
> No, although I'd like to!  Please ask again with more clarity.

:-)  Thank you, Neil.

Regards, Bruce


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I really do this?
  2004-03-06 17:43   ` Bruce Korb
@ 2004-03-06 18:00     ` Neil Jerram
  2004-03-10 21:07       ` Andreas Rottmann
                         ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Neil Jerram @ 2004-03-06 18:00 UTC (permalink / raw)
  Cc: guile-devel

Bruce Korb <bkorb@veritas.com> writes:

> How do I get a hash table started?  I've grepped throught he
> ice-9 code and I'm sure something's in there.  But looking at
> code around 'hash-create' and 'hashq-create' or even just "hash"
> didn't yield anything that worked.  I guess I just need something
> really explicit, like:
> 
>    (define my-hash-table (hash-table-create))
> 
> except that doesn't work.  What does?

The procedure you want is `make-hash-table':

guile> (help make-hash-table)
`make-hash-table' is a primitive procedure in the (guile) module.

 - Scheme Procedure: make-hash-table [n]
     Make a hash table with optional minimum number of buckets N

Note also that you might have found this using `apropos':

guile> (apropos "hash")
(guile): hashq	#<primitive-procedure hashq>
(guile): hashv	#<primitive-procedure hashv>
(guile): hash	#<primitive-procedure hash>
(guile): make-hash-table	#<primitive-procedure make-hash-table>
(guile): make-weak-key-hash-table	#<primitive-procedure make-weak-key-hash-table>
(guile): make-weak-value-hash-table	#<primitive-procedure make-weak-value-hash-table>
(guile): make-doubly-weak-hash-table	#<primitive-procedure make-doubly-weak-hash-table>
(guile): hash-table?	#<primitive-procedure hash-table?>
(guile): weak-key-hash-table?	#<primitive-procedure weak-key-hash-table?>
(guile): weak-value-hash-table?	#<primitive-procedure weak-value-hash-table?>
(guile): doubly-weak-hash-table?	#<primitive-procedure doubly-weak-hash-table?>
(guile): hash-clear!	#<primitive-procedure hash-clear!>
(guile): hashq-get-handle	#<primitive-procedure hashq-get-handle>
(guile): hashq-create-handle!	#<primitive-procedure hashq-create-handle!>
(guile): hashq-ref	#<primitive-procedure hashq-ref>
(guile): hashq-set!	#<primitive-procedure hashq-set!>
(guile): hashq-remove!	#<primitive-procedure hashq-remove!>
(guile): hashv-get-handle	#<primitive-procedure hashv-get-handle>
(guile): hashv-create-handle!	#<primitive-procedure hashv-create-handle!>
(guile): hashv-ref	#<primitive-procedure hashv-ref>
(guile): hashv-set!	#<primitive-procedure hashv-set!>
(guile): hashv-remove!	#<primitive-procedure hashv-remove!>
(guile): hash-get-handle	#<primitive-procedure hash-get-handle>
(guile): hash-create-handle!	#<primitive-procedure hash-create-handle!>
(guile): hash-ref	#<primitive-procedure hash-ref>
(guile): hash-set!	#<primitive-procedure hash-set!>
(guile): hash-remove!	#<primitive-procedure hash-remove!>
(guile): hashx-get-handle	#<primitive-procedure hashx-get-handle>
(guile): hashx-create-handle!	#<primitive-procedure hashx-create-handle!>
(guile): hashx-ref	#<primitive-procedure hashx-ref>
(guile): hashx-set!	#<primitive-procedure hashx-set!>
(guile): hash-fold	#<primitive-procedure hash-fold>
(guile): hash-for-each	#<primitive-procedure hash-for-each>
(guile): hash-for-each-handle	#<primitive-procedure hash-for-each-handle>
(guile): hash-map->list	#<primitive-procedure hash-map->list>
(guile): symbol-hash	#<primitive-procedure symbol-hash>
(guile): read-hash-procedures
(guile): read-hash-extend	#<primitive-procedure read-hash-extend>
(guile): source-whash

> OK.  This works:
> 
>    (define sym-name (value-function))
> 
> So, why doesn't this:
> 
>    (define (string->symbol "sym-name") (val-func))

Because this is the syntax for defining a procedure, and needs to be
one of:

(define (string->symbol) ...)
(define (string->symbol ARG1 ...) ...)
(define (string->symbol . ARGS) ...)

where all the ARGs must be symbols (not strings).

Also, string->symbol is already defined, so why are you trying to
redefine it?

Perhaps you're not trying to redefine it?  In which case, I still
don't understand what you are trying to do.

        Neil


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I really do this?
  2004-03-03 23:52 How do I really do this? Bruce Korb
  2004-03-06 12:17 ` Neil Jerram
@ 2004-03-06 20:50 ` Mikael Djurfeldt
  2004-03-07  1:33   ` Bruce Korb
  2004-03-10 23:44   ` Marius Vollmer
  2004-03-08  2:27 ` Paul Jarc
  2 siblings, 2 replies; 13+ messages in thread
From: Mikael Djurfeldt @ 2004-03-06 20:50 UTC (permalink / raw)
  Cc: djurfeldt, guile-devel

Bruce Korb <bkorb@veritas.com> 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


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I really do this?
  2004-03-06 20:50 ` Mikael Djurfeldt
@ 2004-03-07  1:33   ` Bruce Korb
  2004-03-10 23:44   ` Marius Vollmer
  1 sibling, 0 replies; 13+ messages in thread
From: Bruce Korb @ 2004-03-07  1:33 UTC (permalink / raw)
  Cc: guile-devel

Mikael Djurfeldt wrote:

> (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'.

The only Guile .info stuff I have in my distribution is:

> Scheme Programming
> * data-rep: (data-rep).  Data Representation in Guile -- how to use
>                          Guile objects in your C code.

which is why I was having so much trouble.  :(  I was looking up
the hash stuff in the libguile C sources and the "make-hash-table"
is an ice-9 defined wrapper around the primitive "make-vector".
That made it too difficult to find.  Thank you both for your help!
(You, Mike, and Neil, too!)

Regards, Bruce


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I really do this?
  2004-03-03 23:52 How do I really do this? Bruce Korb
  2004-03-06 12:17 ` Neil Jerram
  2004-03-06 20:50 ` Mikael Djurfeldt
@ 2004-03-08  2:27 ` Paul Jarc
  2 siblings, 0 replies; 13+ messages in thread
From: Paul Jarc @ 2004-03-08  2:27 UTC (permalink / raw)
  Cc: guile-devel

Bruce Korb <bkorb@veritas.com> wrote:
> 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 do you want to avoid creating a hash table?


paul


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I really do this?
  2004-03-06 18:00     ` Neil Jerram
@ 2004-03-10 21:07       ` Andreas Rottmann
  2004-03-10 22:21       ` Carl Witty
  2004-03-11 14:54       ` Paul Jarc
  2 siblings, 0 replies; 13+ messages in thread
From: Andreas Rottmann @ 2004-03-10 21:07 UTC (permalink / raw)


Neil Jerram <neil@ossau.uklinux.net> writes:

> Bruce Korb <bkorb@veritas.com> writes:
>
>> OK.  This works:
>> 
>>    (define sym-name (value-function))
>> 
>> So, why doesn't this:
>> 
>>    (define (string->symbol "sym-name") (val-func))
>
> Because this is the syntax for defining a procedure, and needs to be
> one of:
>
> (define (string->symbol) ...)
> (define (string->symbol ARG1 ...) ...)
> (define (string->symbol . ARGS) ...)
>
> where all the ARGs must be symbols (not strings).
>
> Also, string->symbol is already defined, so why are you trying to
> redefine it?
>
> Perhaps you're not trying to redefine it?  In which case, I still
> don't understand what you are trying to do.
>
I think he maybe wants to define a variable named after a
string. </wildguess>

Andy
-- 
Andreas Rottmann         | Rotty@ICQ      | 118634484@ICQ | a.rottmann@gmx.at
http://yi.org/rotty      | GnuPG Key: http://yi.org/rotty/gpg.asc
Fingerprint              | DFB4 4EB4 78A4 5EEE 6219  F228 F92F CFC5 01FD 5B62

Say NO to Software Patents! -- http://petition.eurolinux.org/



_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I really do this?
  2004-03-06 18:00     ` Neil Jerram
  2004-03-10 21:07       ` Andreas Rottmann
@ 2004-03-10 22:21       ` Carl Witty
  2004-03-12 17:18         ` Bruce Korb
  2004-03-11 14:54       ` Paul Jarc
  2 siblings, 1 reply; 13+ messages in thread
From: Carl Witty @ 2004-03-10 22:21 UTC (permalink / raw)
  Cc: Bruce Korb, guile-devel

On Sat, 2004-03-06 at 10:00, Neil Jerram wrote:
> Bruce Korb <bkorb@veritas.com> writes:
> > OK.  This works:
> > 
> >    (define sym-name (value-function))
> > 
> > So, why doesn't this:
> > 
> >    (define (string->symbol "sym-name") (val-func))
> 
> Because this is the syntax for defining a procedure, and needs to be
> one of:
> 
> (define (string->symbol) ...)
> (define (string->symbol ARG1 ...) ...)
> (define (string->symbol . ARGS) ...)
> 
> where all the ARGs must be symbols (not strings).
> 
> Also, string->symbol is already defined, so why are you trying to
> redefine it?
> 
> Perhaps you're not trying to redefine it?  In which case, I still
> don't understand what you are trying to do.

I think he's trying to get at something more like
  (eval `(define ,(string->symbol "sym-name") ,(val-func)))

(Bruce, hopefully this will help you get an answer to your question. 
I'd answer it myself, but it's been too long since I've dealt with
Scheme or Guile...)

Carl Witty



_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I really do this?
  2004-03-06 20:50 ` Mikael Djurfeldt
  2004-03-07  1:33   ` Bruce Korb
@ 2004-03-10 23:44   ` Marius Vollmer
  2004-03-14  2:54     ` Bruce Korb
  1 sibling, 1 reply; 13+ messages in thread
From: Marius Vollmer @ 2004-03-10 23:44 UTC (permalink / raw)
  Cc: bkorb, guile-devel

Mikael Djurfeldt <djurfeldt@nada.kth.se> writes:

> 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).

This might be confusing.  'make-hash-table' always creates a new hash
table, it doesn't reuse the one that is also used by 'define'.  What
Mikael is saying is that the hash table that is used to store bindings
created with 'define' is also created by 'make-hash-table' and is not
some super special data structure.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I really do this?
  2004-03-06 18:00     ` Neil Jerram
  2004-03-10 21:07       ` Andreas Rottmann
  2004-03-10 22:21       ` Carl Witty
@ 2004-03-11 14:54       ` Paul Jarc
  2 siblings, 0 replies; 13+ messages in thread
From: Paul Jarc @ 2004-03-11 14:54 UTC (permalink / raw)
  Cc: Bruce Korb, guile-devel

Neil Jerram <neil@ossau.uklinux.net> wrote:
> Bruce Korb <bkorb@veritas.com> writes:
>> OK.  This works:
>>
>>    (define sym-name (value-function))
>>
>> So, why doesn't this:
>>
>>    (define (string->symbol "sym-name") (val-func))
...
> Perhaps you're not trying to redefine it?  In which case, I still
> don't understand what you are trying to do.

I think he was trying to define sym-name, just as in the first case -
as if "define" were a normal procedure.  Of course, make-hash-table is
the way to go.


paul


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I really do this?
  2004-03-10 22:21       ` Carl Witty
@ 2004-03-12 17:18         ` Bruce Korb
  0 siblings, 0 replies; 13+ messages in thread
From: Bruce Korb @ 2004-03-12 17:18 UTC (permalink / raw)
  Cc: guile-devel

Carl Witty wrote:

> I think he's trying to get at something more like
>   (eval `(define ,(string->symbol "sym-name") ,(val-func)))

Even reading the docs didn't get me to that construct.
Yes!  That _was_ what I was trying to do.  Of course, I'm going
to use hash tables for what I was trying to do, but it is also
very nice to be clued into the "," operator :-).  Thank you!

Regards, Bruce


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I really do this?
  2004-03-10 23:44   ` Marius Vollmer
@ 2004-03-14  2:54     ` Bruce Korb
  0 siblings, 0 replies; 13+ messages in thread
From: Bruce Korb @ 2004-03-14  2:54 UTC (permalink / raw)
  Cc: djurfeldt, guile-devel

Marius Vollmer wrote:
> 
> Mikael Djurfeldt <djurfeldt@nada.kth.se> writes:
> 
> > 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).
> 
> This might be confusing.  ....


Thank you everyone  :-)  I have it working now.  I even now know
how to use:

   (eval '(define ,(...) ,(...) ))

That's really cool  :-)  It's just that that syntax is a little,
well, obscure (to me).  Anyway, I am using hash tables with the
(make-hash-table) function.  Thank you all again.

Regards, Bruce


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2004-03-14  2:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-03 23:52 How do I really do this? Bruce Korb
2004-03-06 12:17 ` Neil Jerram
2004-03-06 17:43   ` Bruce Korb
2004-03-06 18:00     ` Neil Jerram
2004-03-10 21:07       ` Andreas Rottmann
2004-03-10 22:21       ` Carl Witty
2004-03-12 17:18         ` Bruce Korb
2004-03-11 14:54       ` Paul Jarc
2004-03-06 20:50 ` Mikael Djurfeldt
2004-03-07  1:33   ` Bruce Korb
2004-03-10 23:44   ` Marius Vollmer
2004-03-14  2:54     ` Bruce Korb
2004-03-08  2:27 ` Paul Jarc

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).