1
Name:
Anonymous
2014-07-16 18:35
Write a macro that, given a term of code, transforms all the calls to the function FOO in that term, and only those calls, into calls to function BAR with the same arguments. Language: Common Lisp or Scheme.
9
Name:
Anonymous
2014-07-16 23:40
Done.(defun replace-foo-with-bar (expression) (cond ((atom expression) expression) ((eq (car expression) 'foo) (cons 'bar (replace-foo-with-bar* (cdr expression)))) ((and (eq (car expression) 'funcall) (or (eq (cadr expression) 'foo) (equalp (cadr expression) '(function foo)))) (append '(funcall (function bar)) (replace-foo-with-bar* (cddr expression)))) (t (replace-foo-with-bar* expression)))) (defun replace-foo-with-bar* (expression) (cond ((atom expression) expression) ((consp (car expression)) (cons (replace-foo-with-bar (car expression)) (replace-foo-with-bar* (cdr expression)))) (t (cons (car expression) (replace-foo-with-bar* (cdr expression))))))