Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dict] with numbers as keys force string to symbol #136

Open
il-k opened this issue Apr 27, 2022 · 7 comments
Open

[dict] with numbers as keys force string to symbol #136

il-k opened this issue Apr 27, 2022 · 7 comments

Comments

@il-k
Copy link

il-k commented Apr 27, 2022

Which gives a weird unit (symbol "1")
And I'm not sure how to deal with it in dicts with both numeric and alphabetic keys,
except very ugly workarounds which bother me for my incompetence.

@iainctduncan
Copy link
Owner

Hi, can you give me more information on what you're trying and perhaps sample patch/files? thx!

@il-k
Copy link
Author

il-k commented Apr 27, 2022

Sure, thanks for responding so swiftly!
Here's a sample.
I'd like to use [dict] as storage for hash-tables with mixed keys.

Not that difficult to fix when keys are only numeric. I just (string->number (symbol->string key)) each key.
Now if they're mixed, the only solution I can think of is translate the keys into chars then check if any of them are members in a digit list, etc etc., then slowly rebuild them. Seems doable, but not too easy for an intermediate like me.
I could surely get by without alphabetic keys, but it would be nice to have both. Not a must though!

@iainctduncan
Copy link
Owner

Ok let me see if I can understand better. Am I correct that you have a mixed key hashtable in Scheme, this is working fine, but you get an issue when saving it to a Max dict? Can you tell me where you hit the snag? Sorry it's been a while since I wrote the dict code, and to be honest, nowadays I'm just persisting things directly from Scheme! But I'd still like to make the dict integration work nicely.

@il-k
Copy link
Author

il-k commented Apr 28, 2022 via email

@il-k
Copy link
Author

il-k commented May 16, 2022

Seems it would require a workaround for what Max API provides.

max_atom_to_s7_obj
Dict key is t_symbol. s7_make_symbol is obvious.
But hash-table accepts int for key?
So in the case a dict key is made up entirely of digits, I guess it should rather make an int/long key?

@lassik
Copy link

lassik commented May 18, 2022

If Max supportslong keys natively, you could hash each Scheme object into a long, then use that long as the key in the Max dict. See e.g. sxhash in Common Lisp, or Section 13.4 "Hash functions" in the R6RS libraries.

@lassik
Copy link

lassik commented May 18, 2022

To be clear, that would mean Scheme strings, integers, and any other Scheme type all gets hashed into a C long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants