Sujet : Re: chain of transformations
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.schemeDate : 17. Sep 2024, 13:07:52
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vcbnu7$3g15u$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Kaz Kylheku wrote:
(defun tree-find (needle haystack &key (test #'eql))
(dolist (item haystack)
(if (funcall test needle item)
(return item)
(when (consp item)
(let ((find (tree-find needle item :test test)))
(when find
(return find)))))))
Gauche Scheme:
(define (tree-find needle haystack :optional (test equal?))
(any
(lambda (item)
(if (test needle item)
item
(and (pair? item) (tree-find needle item test))))
haystack))