[Cs254f11] subst
Lee Spector
lspector at hampshire.edu
Fri Nov 18 12:29:47 EST 2011
Josiah and I discussed this in person, as a way to do what he's doing more simply, and I won't repeat all of our discussion here, but others might find it useful for similar or different purposes.
-Lee
(use 'clojure.walk)
(defn subst
"Returns the given list but with all instances of that (at any depth)
replaced with this. Read as 'subst this for that in list'. "
[this that lst]
(postwalk-replace {that this} lst))
(subst 0 1 '(0 1 2 3 (0 1 2 3 (0 1 2 3) 0 1 2 3) 0 1 2 3))
; (0 0 2 3 (0 0 2 3 (0 0 2 3) 0 0 2 3) 0 0 2 3)
--
Lee Spector, Professor of Computer Science
Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspector at hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438
More information about the Cs254f11
mailing list