common lisp - How to use example functions? -
this program taken paradigms of artificial intelligence programming: case studies in common lisp peter norvig, 1992, morgan kaufmann publishers, inc. if compile , load debug window, how use it?
; function returns random element of list choices (defun random-elt (choices) "choose element list @ random." ;; elt returns (n + 1)th element of list choices ;; random returns random integer no large number of ;; elements in list choices (elt choices (random (length choices)))) ; function returns random element of given set , returns ; in list (defun one-of (set) "pick 1 element of set, , make list of it." (list (random-elt set))) ; define sentence noun-phrase + verb phrase (defun sentence () (append (noun-phrase) (verb-phrase))) ; define noun phrase article + noun (defun noun-phrase () (append (article) (noun))) ; define verb phrase verb + noun phrase (defun verb-phrase () (append (verb) (noun-phrase))) ; function returns randomly selected article (defun article () (one-of '(the a))) ; function returns randomly selected noun (defun noun () (one-of '(man ball woman table))) ; function returns randomly selected verb (defun verb () (one-of '(hit took saw liked)))
looking @ code see function not used in sentence
. if enter (sentence)
you'll random sentence like:
(sentence) ;==> (the woman took table)
Comments
Post a Comment