Hi:
I've read the hyperspec, but eval-when, the difference of "when to
evaluate" I still cannot understand, any easier document for eval-when
I can get ??
Thanks
On Feb 1, 9:40 am, ·············@gmail.com" <············@gmail.com>
wrote:
> Hi:
>
> I've read the hyperspec, but eval-when, the difference of "when to
> evaluate" I still cannot understand, any easier document for eval-when
> I can get ??
I agree with Pascal. If you need EVAL-WHEN you probably know you need
it: it's all about making the system do non-standard things when
compiling or loading code, and fortunately the standard things are
actually the ones you almost always want. The rules are quite subtle
and obscure and a number of implementations have had bugs as well,
which don't help if you are trying to work them out (I don't mean to
imply that they still do have such bugs, my experience is now all 5
years old or so).
--tim
On 1 Feb, 11:47, "Tim Bradshaw" <··········@tfeb.org> wrote:
> On Feb 1, 9:40 am, ·············@gmail.com" <············@gmail.com>
> wrote:
>
> > Hi:
>
> > I've read the hyperspec, but eval-when, the difference of "when to
> > evaluate" I still cannot understand, any easier document for eval-when
> > I can get ??
>
> I agree with Pascal. If you need EVAL-WHEN you probably know you need
> it: it's all about making the system do non-standard things when
> compiling or loading code, and fortunately the standard things are
> actually the ones you almost always want.
Maybe I am wrong, but is not eval-when needed even for using a
tailored function in macro definition defined in the same file? Is
this so non-standard?
Actually, I think that trying to understand what eval-when does and
why and when it is needed may help one to beter understand compile
logic of CL, and may be useful to hint that one has still some
misconceptions in the area. It certainly did that for me not so long
ago...
Tomas
On Feb 1, 1:20 pm, ·········@gmail.com" <········@gmail.com> wrote:
> Maybe I am wrong, but is not eval-when needed even for using a
> tailored function in macro definition defined in the same file? Is
> this so non-standard?
>
If you use the macro definition in the file (really: compilation
unit) in which it's defined, yes. But that's the sort of case I meant
by when you know you need it (and even then you can avoid having to
understand all the subtleties).
--tim
On Feb 1, 9:09 am, "Tim Bradshaw" <··········@tfeb.org> wrote:
> If you use the macro definition in the file (really: compilation
> unit) in which it's defined, yes. But that's the sort of case I meant
> by when you know you need it (and even then you can avoid having to
> understand all the subtleties).
Is there any reason not to just cargo-cultishly wrap the relevant
function defintions like this:
(eval-when (:compile-toplevel :load-toplevel :execute)
[defuns and such]
)
'Cause that's what I do, and I just do it 'cause I saw someone else do
it somewhere.
Cheers, Pillsy
On 2007-02-01 16:30:33 +0000, "Pillsy" <·········@gmail.com> said:
> Is there any reason not to just cargo-cultishly wrap the relevant
> function defintions like this:
>
> (eval-when (:compile-toplevel :load-toplevel :execute)
> [defuns and such]
> )
No, and that's the most common use of EVAL-WHEN. For a more obscure
case see the end of this:
http://www.tfeb.org/programs/conduit-packages.lisp. Understanding that
sort of issue is exactly the sort of thing I was suggesting that might
be put off until need (I did).
--tim
From: Vassil Nikolov
Subject: Re: I still cannot understand eval-when
Date:
Message-ID: <yy8vmz34gjya.fsf@eskimo.com>
On 1 Feb 2007 08:30:33 -0800, "Pillsy" <·········@gmail.com> said:
| Is there any reason not to just cargo-cultishly wrap the relevant
| function defintions like this:
| (eval-when (:compile-toplevel :load-toplevel :execute)
| [defuns and such]
| )
You don't necessarily want to pollute your compilation environment
with function definitions (even though in a vast number of cases you
might not feel the difference). By the way, only :COMPILE-TOPLEVEL
is the situation that is extra compared to what happens in the absence
of an EVAL-WHEN above.
Now, if "and such" includes reader macro definitions, that is a
different matter, but I would not group those with DEFUNs.
Shameless plug: by the way, some time ago I wrote a "describe eval-when"
utility, though I think I did not quite finish it, or test it very
extensively, but for whatever it is worth, it can be found at
http://www.eskimo.com/~van/lib/lisp/describe-eval-when.lisp.
---Vassil.
--
Our programs do not have bugs; it is just that the users' expectations
differ from the way they are implemented.
·········@gmail.com" <········@gmail.com> writes:
> On 1 Feb, 11:47, "Tim Bradshaw" <··········@tfeb.org> wrote:
>> On Feb 1, 9:40 am, ·············@gmail.com" <············@gmail.com>
>> wrote:
>>
>> > Hi:
>>
>> > I've read the hyperspec, but eval-when, the difference of "when to
>> > evaluate" I still cannot understand, any easier document for eval-when
>> > I can get ??
>>
>> I agree with Pascal. If you need EVAL-WHEN you probably know you need
>> it: it's all about making the system do non-standard things when
>> compiling or loading code, and fortunately the standard things are
>> actually the ones you almost always want.
>
> Maybe I am wrong, but is not eval-when needed even for using a
> tailored function in macro definition defined in the same file? Is
> this so non-standard?
>
> Actually, I think that trying to understand what eval-when does and
> why and when it is needed may help one to beter understand compile
> logic of CL, and may be useful to hint that one has still some
> misconceptions in the area. It certainly did that for me not so long
> ago...
If you are trying to understand, you can experiment.
-------------(test.lisp)--------------
(eval-when (:compile-toplevel)
(print '(compiling toplevel)))
(eval-when (:load-toplevel)
(print '(loading toplevel)))
(eval-when (:execute)
(print '(executing)))
(print '(normal toplevel))
---------------------------------------
And then try:
(compile-file "test.lisp")
(load "test.lisp")
--
__Pascal Bourguignon__ http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush
········@gmail.com wrote:
> On 1 Feb, 11:47, "Tim Bradshaw" <··········@tfeb.org> wrote:
>> On Feb 1, 9:40 am, ·············@gmail.com" <············@gmail.com>
>> wrote:
>>
>>> Hi:
>>> I've read the hyperspec, but eval-when, the difference of "when to
>>> evaluate" I still cannot understand, any easier document for eval-when
>>> I can get ??
>> I agree with Pascal. If you need EVAL-WHEN you probably know you need
>> it: it's all about making the system do non-standard things when
>> compiling or loading code, and fortunately the standard things are
>> actually the ones you almost always want.
>
> Maybe I am wrong, but is not eval-when needed even for using a
> tailored function in macro definition defined in the same file? Is
> this so non-standard?
>
> Actually, I think that trying to understand what eval-when does and
> why and when it is needed may help one to beter understand compile
> logic of CL, and may be useful to hint that one has still some
> misconceptions in the area. It certainly did that for me not so long
> ago...
With macro definitions you introduce new (possibly domain-specific)
language constructs into the language. More often than not, it's a good
idea to separate such language-level abstractions from the program in
which you actually use them. In Common Lisp, you can separate such
definitions into different files and use system definition facilities to
declare the dependencies, like ASDF, MK-DEFSYSTEM, or
implementation-dependent variants. Once you have done this, the system
definition facility will take care of compiling and loading the
components of your system in the right order, so that you don't have to
worry about these issues.
The remaining cases where you may need eval-when are rare, and when they
come up, it will be clear to you what to look for.
In other words: Before you learn eval-when, you should first learn how
to use system definition facilities. They are much more useful in
practice and give you more important productivity gains.
You can learn about the different phases (read time, compilation time,
macro expansion time, load time and run time) independently of eval-when.
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
············@gmail.com wrote:
> Hi:
>
> I've read the hyperspec, but eval-when, the difference of "when to
> evaluate" I still cannot understand, any easier document for eval-when
> I can get ??
If you don't understand this, you probably don't need it. What do you
want to do?
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/