jscl icon indicating copy to clipboard operation
jscl copied to clipboard

Make hash-table support numbers as keys

Open nagy opened this issue 2 years ago • 4 comments

This allows numbers to be used as hash-table keys, since they are crudely converted to strings.

Closes #424

nagy avatar Mar 14 '22 10:03 nagy

@nagy, thanks. Sorry, very busy lately. I'll take a look at the code this weekend.

vlad-km avatar Mar 29 '22 18:03 vlad-km

I think a requirement for this change is that (gethash 1 ht) should be different from (gethash "1" ht), of even for JS objects.

For #'eq hash tables, we could just probably use a Map.

But that doen't solve the problem for #'eql hash-tables.

davazp avatar Mar 29 '22 18:03 davazp

that (gethash 1 ht) should be different from (gethash "1" ht)

You are right, I will think of a different approach.

nagy avatar Apr 01 '22 20:04 nagy

May be we can store keys as strings like "TYPE:VALUE", for example "1" will be converted to "string:1" and 1 will be "number:1", etc.

hemml avatar Apr 01 '22 21:04 hemml

To my surprise, that distinction between numbers and strings is already happening correctly. I have split the commit into two and added some more test and wrote some reasoning into the commit message.

Please check if it is fine now.

nagy avatar Aug 22 '22 21:08 nagy

Awesome! Thanks!

davazp avatar Aug 23 '22 08:08 davazp