From: Tel A.
Subject: Packages and Anaphoric Macros
Date: 
Message-ID: <1144215644.681347.72500@i39g2000cwa.googlegroups.com>
I was reading the chapter on anaphoric macros in Paul Graham's _On
Lisp_ coming across this paragraph:

>    Whenever a macro which does intentional variable capture is exported to
> another package, it is necessary also to export the symbol being captured. For
> example, wherever aif is exported, it should be as well. Otherwise the it which
> appears in the macro definition would be a different symbol from an it used in a
> macro call.
>
> (pg 195)

He writes aif like so,

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

I wonder if it would be possible to write aif so that it grabs the
package it's being expanded in at macroexpansion time and ensures that
the it symbol being let is defined within the current package.
Something like,

(defmacro aif (test-form then-form &optional else-form)
	`(let ((,*package*::it ,test-form))
	  (if ,*package*::it ,then-form ,else-form)))

Although this very poor example does not work at all since the
interpreter tries to get the value of package at that very moment.

I'm not well enough versed to figure this out, but it seems it might be
possible. Anyone have an idea/implementation/reason why it can't
happen? It seems possible that something in the mechanics of export or
something about macroexpansion I don't yet grasp might muck it up.

From: Alexander
Subject: Re: Packages and Anaphoric Macros
Date: 
Message-ID: <1144222453.148383.120590@v46g2000cwv.googlegroups.com>
TEST> (in-package :cl-user)
#<PACKAGE COMMON-LISP-USER>
CL-USER> (defmacro aif (test-form then-form &optional else-form)
	   `(let ((,(intern "IT") ,test-form))
	     (if ,(intern "IT") ,then-form ,else-form)))
AIF
CL-USER> (in-package :test)
#<PACKAGE TEST>
TEST> (cl-user::aif (> 3 1) (format t "~a" it) 30)
T
NIL
TEST>
From: mac
Subject: Re: Packages and Anaphoric Macros
Date: 
Message-ID: <1144466014.505920.118910@g10g2000cwb.googlegroups.com>
I'm really curious if there's any drawback from defining aif the way
you suggested, because it's rather neat that you don't have to export
the symbol "it".

Both pg, marco baringer and Nikodemus Siivola's anaphoric module export
the symbol "it " so they don't mix well together.
From: Alexander
Subject: Re: Packages and Anaphoric Macros
Date: 
Message-ID: <1144673854.927734.66350@z34g2000cwc.googlegroups.com>
1. If someone use non-standart reader (acl modern mode for example) ...
2. If someone change *package* between read time and macroexpansion
time ...