Can someone please explain to me how I search for the occurrences of each word in a sentence, such as "the cat sat on the mat" in Common lisp ?
The user has to have inputted this line of text before hand and then the occurrences must be counted from that. Any help on even where to start would help.
Have a look at
split-by-one-space
in The Common Lisp CookbookNow you could just use a hash table with
equal
as test and perhaps usemapc
on the list to get a key and frequency hash. Then you have what you wanted in the hash table.Alternatively (and slower) would be to count the first element with
(count (car lst) lst :test #'equal)
and process the rest of the list with(remove (car lst) lst :test #'equal)
. When the filtered list is empty you're done.