From: jrwats
Subject: hash-tables string keys... am I a dunce?
Date: 
Message-ID: <bf68ba38-0631-495b-9920-de852638201f@i20g2000prf.googlegroups.com>
working in slime (clisp interpreter) and don't understand the
following...

CL-USER> (setf ht (make-hash-table))
#S(HASH-TABLE :TEST EXT:FASTHASH-EQL)
CL-USER> (setf (gethash 2 ht) "test1")
"test1"
CL-USER> (setf (gethash "two" ht) "test2")

"test2"
CL-USER> ht
#S(HASH-TABLE :TEST EXT:FASTHASH-EQL ("two" . "test2") (2 . "test1"))

;;; yes the above seems correct...

CL-USER> (gethash 2 ht)
"test1"
T

;;;ok

CL-USER> (gethash "two" ht)
NIL
NIL

;;;huh?

Is there something going on I'm not aware of?  I know the quote
strings are string constants, but given the fact:
CL-USER> (equal "two" "two")
T

I figured this would work... what's up? (Peter Norvig uses an example
just like this http://www.norvig.com/python-lisp.html and appears to
believe it should do what I think it should do)

Thanks!
John Watson

From: Kenny
Subject: Re: hash-tables string keys... am I a dunce?
Date: 
Message-ID: <48a1261b$0$20919$607ed4bc@cv.net>
jrwats wrote:
> working in slime (clisp interpreter) and don't understand the
> following...
> 
> CL-USER> (setf ht (make-hash-table))
> #S(HASH-TABLE :TEST EXT:FASTHASH-EQL)
> CL-USER> (setf (gethash 2 ht) "test1")
> "test1"
> CL-USER> (setf (gethash "two" ht) "test2")
> 
> "test2"
> CL-USER> ht
> #S(HASH-TABLE :TEST EXT:FASTHASH-EQL ("two" . "test2") (2 . "test1"))
> 
> ;;; yes the above seems correct...
> 
> CL-USER> (gethash 2 ht)
> "test1"
> T
> 
> ;;;ok
> 
> CL-USER> (gethash "two" ht)
> NIL
> NIL
> 
> ;;;huh?
> 
> Is there something going on I'm not aware of?  I know the quote
> strings are string constants, but given the fact:
> CL-USER> (equal "two" "two")
> T
> 
> I figured this would work... what's up? (Peter Norvig uses an example
> just like this http://www.norvig.com/python-lisp.html and appears to
> believe it should do what I think it should do)

That's a bug in his example, and I must say I myself often toss of finds 
and gethashes and whatever on strings forgetting (your problem) to 
specify :test 'equal or 'equalp for string values. Maybe PN has the same 
blindpsot.

Aside, you really do want to get EQ vs EQL vs EQUAL down early on. You 
can use forget EQ if you are lazy, but I like to use it with Lisp 
objects other than numbers and characters (unless of course when 
comparing two sequences I really do want to know only if they have the 
same elements).

hth,kt

-- 

$$$$$: http://www.theoryyalgebra.com/
Cells: http://common-lisp.net/project/cells/
BSlog: http://smuglispweeny.blogspot.com/
From: Pascal J. Bourguignon
Subject: Re: hash-tables string keys... am I a dunce?
Date: 
Message-ID: <878wv2g4s7.fsf@hubble.informatimago.com>
jrwats <······@gmail.com> writes:

> working in slime (clisp interpreter) and don't understand the
> following...
>
> CL-USER> (setf ht (make-hash-table))
> #S(HASH-TABLE :TEST EXT:FASTHASH-EQL)
                                   ^^^
> CL-USER> (equal "two" "two")
            ^^^^^

http://www.lispworks.com/reference/HyperSpec/Body/f_mk_has.htm

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
From: jrwats
Subject: Re: hash-tables string keys... am I a dunce?
Date: 
Message-ID: <ae10518a-9c8d-44dc-b1ad-7d10cfa83b99@a3g2000prm.googlegroups.com>
Is it possible to change test of a hash-table on the fly?

For instance if I made all these hash-table entries with string keys
but my test is eql.  I could see this being a problem if you had made
duplicats like:
(setf a-string "one")
(setf (gethash a-string ht) 2)
(setf (gethash "one" ht) 3)

which would have two entries it seems with a test of eql, but upon
changing the test of a hash-table it would break... which is why I
would guess you cannot change these on the fly.
From: Pascal J. Bourguignon
Subject: Re: hash-tables string keys... am I a dunce?
Date: 
Message-ID: <7czlnih68x.fsf@pbourguignon.anevia.com>
jrwats <······@gmail.com> writes:

> Is it possible to change test of a hash-table on the fly?

May be.  Have you read the reference page at the URL I gave?


> For instance if I made all these hash-table entries with string keys
> but my test is eql.  I could see this being a problem if you had made
> duplicats like:
> (setf a-string "one")
> (setf (gethash a-string ht) 2)
> (setf (gethash "one" ht) 3)
>
> which would have two entries it seems with a test of eql, but upon
> changing the test of a hash-table it would break... which is why I
> would guess you cannot change these on the fly.

-- 
__Pascal Bourguignon__