Skip to content

Instantly share code, notes, and snippets.

@ichimal
Created September 12, 2012 00:44
Show Gist options
  • Save ichimal/3703328 to your computer and use it in GitHub Desktop.
Save ichimal/3703328 to your computer and use it in GitHub Desktop.
self update map
(defun map-update (fun src &rest lists)
(funcall
(reduce (lambda (cont list-elms)
(lambda ()
(apply fun (funcall cont) list-elms) ))
(apply #'mapcar #'list lists)
:initial-value (constantly src) )))
(defun subst-all (to-list from-list src)
(map-update
(lambda (src from to) (subst to from src))
src from-list to-list ))
(subst-all '(1 2 3) '(a b c) '(a b c d c b a)) ; => '(1 2 3 d 3 2 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment