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

shen-scheme doesn't allow the use of vectors for property vectors/hash tables. #14

Open
diseraluca opened this issue Apr 17, 2021 · 3 comments

Comments

@diseraluca
Copy link

The book of shen 3rd edition, page 93 says:

The function put receives

  1. An expression e_1.
  2. A pointer p which is used to point to ...
  3. ... a value e_2 within ...
  4. an (optionally user-specified) vector v.

On the next page, the following code snippet can be found:

(set *semantic-net* (vector 1000))
...
(define assert 
...
  -> (put Object is_a [...] (value *semantic-net*)

Similarly, the shen shendoc page reports:

put and get are actually polyadic functions which appear as such by the grace of the Shen reader. There is an optional final argument which should be a standard vector; thus (put Mark sex male (value myvector)) will use the vector myvector as the hashing table.

Running a similar code on shen-scheme, version 0.24, downloaded as a linux binary from the release page, will fail.

For example:

(put Mark sex male (vector 10))
Exception in hashtable-set!: #(10 shen.fail! shen.fail! shen.fail! shen.fail! shen.fail! shen.fail! shen.fail! shen.fail! shen.fail! shen.fail!) is not a hashtable

That is, the code fails as vector is not an hashtable.

This seems to be because the implementation uses the underlying system hashtables instead of shen vectors.

Indeed, the following works correctly:

(put Mark sex male (scm.make-hash-table))
male

The shen-cl implementation seems to provide the same behavior.

I expect that this is known and not a bug, but would it be possible to have the vector version working too? Otherwise, is there a way to make portable (between implementations) shen code that uses custom hash-maps with put/get?

If this is something that is possible or desired to change I'm open to help, within the limit of my abilities and knowing that I'm not versed in scheme, as I would like to be able to use the vector version.

@tizoc
Copy link
Owner

tizoc commented Apr 17, 2021

@diseraluca (shen.dict SizeHint) is what you want here. By default a vector is used to implement such dictionaries, but some ports will override it with a native hash table implementation for performance.

See: https://github.com/Shen-Language/shen-sources/blob/master/sources/dict.shen

@diseraluca
Copy link
Author

diseraluca commented Apr 17, 2021

This indeed solves my problems.

You have my deepest gratitude for the gentle pointer, the immediate response and your general work on the shen programming language.

Would you think it might be sensible to add a small note in the README about this to ease the confusion that may stem from TBOS and the shendoc webpage?

@tizoc
Copy link
Owner

tizoc commented Apr 17, 2021

I'm thinking that for the sake of compatibility with what has already been put in print, the put and get functions probably need to work with vectors too in platforms that use native hash tables. Give me some time to think about what the best solution would be.

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

2 participants