thephoeron / let-over-lambda

Doug Hoyte's "Production" version of macros from Let Over Lambda, ready for ASDF and Quicklisp.
Other
131 stars 25 forks source link

anaphoric names not exported #7

Closed zellerin closed 9 years ago

zellerin commented 9 years ago

I believe the anaphoric names (it, this, self) should be exported.

Patch is trivial, but I can push it if wanted.

thephoeron commented 9 years ago

I'm not sure I agree. But let's ask @hoytech:

Was it your intention with the anaphoric macros in the let-over-lambda code to have the lexical symbols exported with the top-level package symbols? The way they are written, don't they expand into the package namespace where the macro is called at compile time?

zellerin commented 9 years ago

Why I think it should be: I cannot do (aif some-variable (fooize it) 'undefined) in other package using lol, as it expands to

(LET ((LET-OVER-LAMBDA::IT SOME-VARIABLE))
  (IF LET-OVER-LAMBDA::IT
      (FOOIZE IT)
      'UNDEFINED))
hoytech commented 9 years ago

As you can tell, I didn't really think about packages in much detail when I wrote the book so, @thephoeron, thanks for working all this stuff out.

The reason the symbols aren't in the package where the macro is expanded is because symbols are resolved by the reader. In this case, the symbols are resolved when you load lol.lisp and are therefore interned in the let-over-lambda package since that is the package in effect when the defmacro form is read in. Even though the macro can be run later when a different package is in effect, the symbols in its backquote form have already been interned into the let-over-lambda package.

Here's a good description of packages and their corner cases in CL:

http://www.flownet.com/gat/packages.pdf

"The most important thing to understand about packages is that they are fundamentally a part of the Lisp reader and not the evaluator."

Without having thought about it in too much detail, I agree with @zellerin that if we export the aif symbol then we should also export the anaphoric it symbol. If you are importing so you don't have to type the lol in lol:aif, you also shouldn't have to type the lol in lol:it. Of course I'm open to any counter-arguments as well.

Thanks!

thephoeron commented 9 years ago

@hoytech: good points, and that is a particularly interesting quote you provided. I have exported the symbols IT, THIS, and SELF as @zellerin requested.

zellerin commented 9 years ago

Thanks to both, both for looking into this and for writing the book and keeping the code in general.

One minor correction to what @hoytech wrote (that probably does not change anything) - without export, you would not be able to write lol:it, but only lol::it.

hoytech commented 9 years ago

@zellerin : Thanks, good point.