Hash problems - clashing with newLISP's own symbols
Posted: Tue Dec 13, 2005 2:01 pm
I'm trying to learn about hash tables (or newLISP's way of doing them). I think I need to learn how to avoid clashes with newLISP's reserved words.
Here's a short test case:
which gives the output:
Here's a short test case:
Code: Select all
(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)
Code: Select all
:1
a:1
but:1
controls:1
dont:1
hash:exit:1
hash:for:1
heart:1
it:1
its:1
like:1
looks:1
make:1
occurrences:1
of:1
s:s
hash:set:1
sharp:1
sun:1
the:1
the-word:nil
hash:time:1
invalid function : (hash:exit)