Hi!
I have some questions about EQUAL hash tables. First, let's make an
example hash table:
CL-USER 40 > (defparameter *hash* (make-hash-table :test #'equal))
*HASH*
CL-USER 41 > (setf (gethash "foo" *hash*) 42)
42
Now, is the following code ok, as far as the Standard is concerned?
CL-USER 46 > (let ((buf (copy-seq "Foo")))
(print (gethash buf *hash*))
(setf (schar buf 0) #\f)
(print (gethash buf *hash*))
(setf (schar buf 0) #\X))
NIL
42
#\X
I would say it definitely should be, although I am not so sure anymore
when I read 18.1.2 in the HyperSpec. I mean, it says ``If an object
O1 is used as a key in a hash table H...�� and ``used��, well, can
mean pretty much anything, right? Didn't I ``use�� BUF as a key in a
hash table by using it in a query?
And how about this:
CL-USER 48 > (let ((buf (copy-seq "foo")))
(setf (gethash buf *hash*) 17)
(setf (schar buf 0) #\F))
#\F
I would say it should be ok, too, because a string EQUAL to BUF
already /was/ in the table, but I am not so sure anymore when reading
the Standard...
What do you think? And if any of these are /not/ allowed, are there
any sensible reasons for that?
The only thing /I/ had disallowed, would be
(let ((buf (copy-seq "Blark")))
(setf (gethash buf *hash*) 19)
(setf (schar buf 0) #\X))
i.e., modifying the a key after /adding/ it to a table... or am I
missing something here?
Regards,
--
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."
PGP key ID 0x0655CFA0
In article <··············@cartan.de>, Nils Goesche <······@cartan.de> wrote:
>Hi!
>
>I have some questions about EQUAL hash tables. First, let's make an
>example hash table:
>
>CL-USER 40 > (defparameter *hash* (make-hash-table :test #'equal))
>*HASH*
>
>CL-USER 41 > (setf (gethash "foo" *hash*) 42)
>42
>
>Now, is the following code ok, as far as the Standard is concerned?
>
>CL-USER 46 > (let ((buf (copy-seq "Foo")))
> (print (gethash buf *hash*))
> (setf (schar buf 0) #\f)
> (print (gethash buf *hash*))
> (setf (schar buf 0) #\X))
>
>NIL
>42
>#\X
>
>I would say it definitely should be, although I am not so sure anymore
>when I read 18.1.2 in the HyperSpec. I mean, it says ``If an object
>O1 is used as a key in a hash table H...�� and ``used��, well, can
>mean pretty much anything, right? Didn't I ``use�� BUF as a key in a
>hash table by using it in a query?
No, you used it as a parameter to a query. It was never used as the key of
any entry in the hash table.
>And how about this:
>
>CL-USER 48 > (let ((buf (copy-seq "foo")))
> (setf (gethash buf *hash*) 17)
> (setf (schar buf 0) #\F))
>#\F
>
>I would say it should be ok, too, because a string EQUAL to BUF
>already /was/ in the table, but I am not so sure anymore when reading
>the Standard...
>
>What do you think? And if any of these are /not/ allowed, are there
>any sensible reasons for that?
>
>The only thing /I/ had disallowed, would be
>
>(let ((buf (copy-seq "Blark")))
> (setf (gethash buf *hash*) 19)
> (setf (schar buf 0) #\X))
>
>i.e., modifying the a key after /adding/ it to a table... or am I
>missing something here?
You're correct -- the only thing you're not allowed to modify is the actual
object that's saved in the hash table as a key.
--
Barry Margolin, ··············@level3.com
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Barry Margolin <··············@level3.com> writes:
> In article <··············@cartan.de>, Nils Goesche <······@cartan.de> wrote:
> >The only thing /I/ had disallowed, would be
> >
> >(let ((buf (copy-seq "Blark")))
> > (setf (gethash buf *hash*) 19)
> > (setf (schar buf 0) #\X))
> >
> >i.e., modifying the a key after /adding/ it to a table... or am I
> >missing something here?
> You're correct -- the only thing you're not allowed to modify is the
> actual object that's saved in the hash table as a key.
Now that's some relief -- thanks very much!
Regards,
--
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."
PGP key ID 0x0655CFA0