mapping approach:
;; assuming get-value-if-attrib-present simply returns nil when not present ;; (ie your attribute value cannot be nil without ambiguity) ;; ;; get the list of values from the children, matching attrib ;; (mapcan (lambda (child) (if (get-value-if-attrib-present child attrib) (list child))) children)
mapcan expects the function to return lists, and it destroys them. Therefore, you must be careful not to return the quoted lists from the lambda or any lists that came from somewhere else (not here).
In artificial programming paradigms (aka PAIP), Peter Norwig introduces the mappend function, which does the same, but indestructible. It is useful to have in your toolkit sometimes.
source share