本文介绍了如何在这里使用mapcar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(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),我该如何获取具有匹配的attrnode的所有子项值列表(在 ####....)?

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)

ITLOOP的功能->它引用WHEN子句中谓词返回的值.

IT is a LOOP feature -> it refers to the value returned by the predicate in the WHEN clause.

这篇关于如何在这里使用mapcar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:06