How to change aif to be able to access 'it' within the macrocall without making 'it' public in the package

Posted by Sim on Stack Overflow See other posts from Stack Overflow or by Sim
Published on 2012-09-12T15:37:00Z Indexed on 2012/09/12 15:37 UTC
Read the original article Hit count: 223

Filed under:

If you put the aif code presented in onlisp in a package and try to use it in another you run in the problem that packagename:it is not external.

(in-package :packagename)

(defmacro aif (test-form then-form &optional else-form)
  ‘(let ((it ,test-form))
     (if it ,then-form ,else-form)))

wanted call syntax

(in-package :otherpackage)

(aif (do-stuff)
  (FORMAT t "~a~%" it)
  (FORMAT t "just got nil~%"))

How can I fix this behavior in code, without making the variable it external in the package declaration and beeing able to access it just by it instead of packagename:it?

© Stack Overflow or respective owner

Related posts about common-lisp