Common lisp 如何使用示例函数?
这个程序是由Peter Norvig,1992,Morgan Kaufmann Publishers,Inc.编写的。如果我编译并加载到调试窗口中,我将如何使用它Common lisp 如何使用示例函数?,common-lisp,Common Lisp,这个程序是由Peter Norvig,1992,Morgan Kaufmann Publishers,Inc.编写的。如果我编译并加载到调试窗口中,我将如何使用它 ; This function returns a random element of the list choices (defun random-elt (choices) "Choose an element from a list at random." ;; elt returns the (n + 1)th ele
; This function returns a random element of the list choices
(defun random-elt (choices)
"Choose an element from a list at random."
;; elt returns the (n + 1)th element of the list choices
;; random returns a random integer no large than the number of
;; elements in the list choices
(elt choices (random (length choices))))
; This function returns a random element of the given set and returns
; it in a list
(defun one-of (set)
"Pick one element of set, and make a list of it."
(list (random-elt set)))
; Define a sentence as a noun-phrase + verb phrase
(defun sentence () (append (noun-phrase) (verb-phrase)))
; Define a noun phrase as an article + noun
(defun noun-phrase () (append (Article) (Noun)))
; Define a verb phrase as a verb + a noun phrase
(defun verb-phrase () (append (Verb) (noun-phrase)))
; This function returns a randomly selected article
(defun Article () (one-of '(the a)))
; This function returns a randomly selected noun
(defun Noun () (one-of '(man ball woman table)))
; This function returns a randomly selected verb
(defun Verb () (one-of '(hit took saw liked)))
看看这段代码,我看到另一段代码中唯一没有使用的功能是
语句
。如果您输入(句子)
,您将得到一个随机句子,如:
(sentence) ;==> (THE WOMAN TOOK A TABLE)
看看这段代码,我看到另一段代码中唯一没有使用的功能是
语句
。如果您输入(句子)
,您将得到一个随机句子,如:
(sentence) ;==> (THE WOMAN TOOK A TABLE)
通常我会使用SLIME/Emacs、Clozure CL、LispWorks、Allegro CL等工具编辑文件。。。或者任何其他有编辑器可以与公共Lisp对话的东西 如果将代码放入缓冲区,则编译缓冲区。在SLIME/Emacs中,使用control-c control-k或meta-x SLIME编译和加载文件。这将编译整个文件,并将编译后的代码加载到运行的公共Lisp中 在LispWorksIDE中,我只需进入buffer菜单并执行compile
然后转到侦听器(又名REPL)并执行
(句子)
。诺维格优秀著作的第34至38页详细解释了代码以及如何使用它。通常我会使用SLIME/Emacs、Clozure CL、LispWorks、Allegro CL等工具编辑文件。。。或者任何其他有编辑器可以与公共Lisp对话的东西
如果将代码放入缓冲区,则编译缓冲区。在SLIME/Emacs中,使用control-c control-k或meta-x SLIME编译和加载文件。这将编译整个文件,并将编译后的代码加载到运行的公共Lisp中
在LispWorksIDE中,我只需进入buffer菜单并执行compile
然后转到侦听器(又名REPL)并执行
(句子)
。诺维格优秀著作的第34页至第38页详细解释了代码和如何使用它。这本书没有说明如何使用它?这本书没有说明如何使用它?我想我在IDE中键入代码时犯了一个错误。当我将代码直接加载到调试窗口时,它的工作方式与您描述的一样。谢谢我想我在输入IDE时犯了一个错误。当我将代码直接加载到调试窗口时,它的工作方式与您描述的一样。谢谢