(context 'hash) ; create hash container
(dolist (the-word (parse "Set the controls for the heart of the sun.
It looks like it's time for a sharp exit, but don't make a hash of it!" " "))
(set 'the-word (lower-case the-word))
(replace "[^A-Za-z]" the-word "" 0) ; tidy the string
(set 'occurrences (eval (sym the-word hash))) ; number of occurrences of word in list
(if (> occurrences 0)
(set (sym the-word hash (+ 1 occurrences))) ; increase count for this word
(set (sym the-word hash ) 1 ) ; or add new word
))
(dolist (s (symbols hash))
(println (sym s hash) ":" (eval (sym s hash))))
(exit)
I haven't looked through the code you posted (sorry I am in a hurry at the moment). But reserved words in a dictionary should work, because they get explicitely overwitten.
newLISP v.8.7.4 on OSX, execute 'newlisp -h' for more info.
> (set (sym "exit" 'MyHash) 123)
123
> (eval (sym "exit" 'MyHash))
123
>
;; try the new shorter/faster form since 8.7.4
;; with an expanded syntax of 'context'
> (context 'MyHash "time" 456)
456
> (context 'MyHash "time")
456
>
A different problem arises when you save the context (save "myhash.txt" 'MyHash) and then load it again with (load "myhash.txt") with words like 'set'. Because of this in the projects I am invloved (indexing/parsing huge numbers of documents), we prepend every word token with a "_" underscore, but if your dictionaries are never saved to disk this should not be a problem. There must be something different going one here.