Using hash tables in racket
Posted
by
user2963128
on Stack Overflow
See other posts from Stack Overflow
or by user2963128
Published on 2013-11-07T03:17:37Z
Indexed on
2013/11/07
3:54 UTC
Read the original article
Hit count: 402
Im working on an Ngrams program and im having trouble filling out my hash table. i want to write out a recursive function that will take the words and add them to the hash table. The way its supposed to work is given the data set 1 2 3 4 5 6 7 the first entry in the hash table should have a key of [1 2] and the data should be 3. The second entry should be: [2 3] and its data should be 4 and continuing on until the end of the text file.
we are given a predefined function called readword that will simply return 1 word from the text. But im not sure how to make these calls overlap each other. The calls would look something like this if the data was hard coded in.
(hash-set! (list "1" "2") 3
(hash-set! (list "2" "3") 4
2 calls that ive tried look like this
(hash-set! Ngram-table(list((word1) (word2)) readword in)))
(hash-set! Ngram-table(append((cdr data) word1)) readword in)
apparently the in after readword is supposed to tell the computer that this is and input instead of an output or something like that.
How would I call this to make the data in the key of the hashtable overlap like this? And what would the recursive call look like?
edit: also we are not allowed to use assigment statements in this program.
© Stack Overflow or respective owner