Skip to content

Instantly share code, notes, and snippets.

Last active Dec 11, 2018
What would you like to do?
(defun Decorators (stream ch1)
(declare (ignore ch1))
(let ((Decorator (read stream))
(the-func-form (read stream)))
(unless (eq (first the-func-form) 'defun)
(error "need 'defun"))
(let ((the-func-name (second the-func-form))
(the-func-args (third the-func-form))
(the-func (cdddr the-func-form)))
`(flet ((old-func ,the-func-args ,@the-func))
(defun ,the-func-name ,the-func-args
(funcall (,Decorator #'old-func) ,@the-func-args))))))
(defun print-hello (func)
(print 'hello)
(defun hello-name (name)
(format t "~&Hello, ~A~%" name))
(hello-name "john")
(funcall (print-hello #'hello-name) "john")
(set-macro-character #\@
(defun hello-world ()
(format t "~&Hello, world~%"))
#| output the result
(print (with-input-from-string (s "print-hello
(defun hello-world ()
(format t \"~&Hello, world~%\"))")
(Decorators s #\@)))
(defun show-num (num)
(print num))
(show-num 10)
(print (with-input-from-string (s "print-hello
(defun show-num (num)
(print num))")
(Decorators s #\@)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment