问题描述
(defun find-attr (node attr)
(let ((children (pt-children node)))
(if (null children)
nil
(let ((subchildren (mapcar ##############
(get-value-if-attrib-present (node attrib) ...)
pt
是一个类. (pt-children node)
产生node
的子代,它们也是pt
对象. attr
是一个字符串.假设我编写了get-value-if-attrib-present
以返回pt
对象的值(如果它具有匹配的attr
),我该如何获取具有匹配的attr
的node
的所有子项值列表(在 ####....)?
pt
is a class. (pt-children node)
yields children of node
which are also pt
objects. attr
is a string. suppossing I write get-value-if-attrib-present
to return the value of a pt
object if it has the matching attr
, how do i go about getting the list of all the values of subchildren of node
with matching attr
here (at ####....)?
推荐答案
对于Common Lisp,请使用以下功能之一:
For Common Lisp use one of these functions:
-
REMOVE-IF
-
REMOVE-IF-NOT
-
REMOVE
REMOVE-IF
REMOVE-IF-NOT
REMOVE
他们遍历列表并删除项目.保留那些你想要的东西.
They go over a list and remove items. Keep those which you want.
其他明智的LOOP
会做到:
(LOOP for item in some-list
when (predicate-p item)
collect it)
IT
是LOOP
的功能->它引用WHEN
子句中谓词返回的值.
IT
is a LOOP
feature -> it refers to the value returned by the predicate in the WHEN
clause.
这篇关于如何在这里使用mapcar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!