Lisp CL-obj参数如何传递到labels函数中?

Lisp CL-obj参数如何传递到labels函数中?,lisp,Lisp,返回REPL中的(威士忌桶) obj如何进入at-loc-p?处对象的任何参数均未命名为obj处对象的任何参数均未命名为obj,但处-loc-p的其中一个参数(实际上是唯一的参数)为。因此,当使用参数调用at-loc-p时(通过remove if not),该参数将传递给at-loc-p,其名称为obj标签定义函数。所以 (defparameter *objects* '(whiskey bucket frog chain)) (defparameter *object-locations*

返回REPL中的
(威士忌桶)


obj
如何进入
at-loc-p
对象的任何参数均未命名为
obj

对象的任何参数均未命名为
obj
,但
处-loc-p
的其中一个参数(实际上是唯一的参数)为。因此,当使用参数调用
at-loc-p
时(通过
remove if not
),该参数将传递给
at-loc-p
,其名称为
obj

标签定义函数。所以

(defparameter *objects* '(whiskey bucket frog chain))

(defparameter *object-locations* '((whiskey living-room)
                                   (bucket living-room)
                                   (chain garden)
                                   (frog garden)))

(defun objects-at (loc objs obj-locs)
  (labels ((at-loc-p (obj)
             (eq (cadr (assoc obj obj-locs)) loc)))
    (remove-if-not #'at-loc-p objs)))

(objects-at 'living-room *objects* *object-locations*)

(labels ((square (x) (* x x))) (square 2))
x
(在您的示例中,
obj
)只是
square
at-loc-p
)函数的参数名称

中编写函数
对象的另一种方法是

(let ((square (lambda (x) (* x x)))) (funcall square 2))

除了全局定义函数
at-loc-p

之外,请注意,在上一个代码片段中,您将
at-loc-p
定义为一个全局函数,可以从
处的
对象外部看到。这与
labels
做的事情不同。Doooh,没有注意到它调用函数时使用objs作为labels后面的参数。谢谢你的简明解释。
(defun objects-at (loc objs obj-locs)
  (defun at-loc-p (obj)
    (eq (cadr (assoc obj obj-locs)) loc))
  (remove-if-not #'at-loc-p objs)))