Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ challenge

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.

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))))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List