Guest User

Untitled

a guest
Oct 6th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.54 KB | None | 0 0
  1.  
  2. (defun patch (func pattern patch)
  3.   "Patch a function definition by replacing `pattern' by `patch'."
  4.   (and (byte-code-function-p (symbol-function func))
  5.     (error "Symbol `%s' is bound to a byte compiled function." func))
  6.   (fset func (repl (symbol-function func) pattern patch)))
  7.  
  8. (defun repl (exp pattern patch)
  9.   (cond
  10.     ((null exp) nil)
  11.     ((listp exp)
  12.       (let ((expr (repl (car exp) pattern patch)))
  13.         (cons
  14.           (if (equal expr pattern) patch expr)
  15.           (repl (cdr exp) pattern patch))))
  16.       (t exp)))
Advertisement
Add Comment
Please, Sign In to add comment