From: Jeff
Subject: Re: Different execution in package
Date: 
Message-ID: <7NDbd.365228$mD.320884@attbi_s02>
Wade Humeniuk wrote:

> 
> (let ((*package* (load-time-value (find-package :my-parser))))
>     <code>)

Just curious as to what LOAD-TIME-VALUE gets me in this instance (as
opposed to just using FIND-PACKAGE without it)?

And BTW, thanks for the help -- that was it ;)

Jeff M.

From: Wade Humeniuk
Subject: Re: Different execution in package
Date: 
Message-ID: <ZCFbd.21413$qU.16335@clgrps13>
Jeff wrote:
> Wade Humeniuk wrote:
> 
> 
>>(let ((*package* (load-time-value (find-package :my-parser))))
>>    <code>)
> 
> 
> Just curious as to what LOAD-TIME-VALUE gets me in this instance (as
> opposed to just using FIND-PACKAGE without it)?

The simple answer is speed.

I put it in so that FIND-PACKAGE is not called each time the let is
entered.  Other possible ways are:

(let ((*package* #.(find-package :my-parser))) ...

or

(defvar *my-parser-package* (find-package :my-parser))

(let ((*package* *my-parser-package*)) ...


But I have come to think that using load-time-value is better in this
situation.

Wade
From: Barry Margolin
Subject: Re: Different execution in package
Date: 
Message-ID: <barmar-A8AD2B.23470114102004@comcast.dca.giganews.com>
In article <······················@attbi_s01>,
 "Jeff" <···@nospam.insightbb.com> wrote:

> Wade Humeniuk wrote:
> 
> > Jeff wrote:
> > > Wade Humeniuk wrote:
> > > 
> > > 
> > > > (let ((*package* (load-time-value (find-package :my-parser))))
> > >>    <code>)
> > > 
> > > 
> > > Just curious as to what LOAD-TIME-VALUE gets me in this instance (as
> > > opposed to just using FIND-PACKAGE without it)?
> > 
> > The simple answer is speed.
> > 
> > I put it in so that FIND-PACKAGE is not called each time the let is
> > entered.  Other possible ways are:
> > 
> > (let ((*package* #.(find-package :my-parser))) ...
> > 
> 
> I'm a little confused now. Not trying to say that you're wrong, but I
> was curious was the advantage was when I looked up LOAD-TIME-VALUE in
> the Hyperspec and saw this example:
> 
> ;;; The function INCR1 always returns 
> ;;; the same value, even in different images.
> 
> ;;; The function INCR2 always returns the same 
> ;;; value in a given image, but the value it 
> ;;; returns might vary from image to image.
> 
> (defun incr1 (x) (+ x #.(random 17)))
> (defun incr2 (x) (+ x (load-time-value (random 17))))
> 
> Your example leads me to believe that the result would be the same (in
> your example it very well might be, but obviously there is a
> difference).

In INCR1, RANDOM is called when the source file is read by the compiler, 
and the resulting value is put into the compiled file.  So every time 
that file is loaded, it will have that same value.

In INCR2, RANDOM is called when the compiled file is loaded.  So each 
time you load it into a different image it will return a different 
random number, but that value will be retained for the duration of that 
image.

> 
> > (defvar *my-parser-package* (find-package :my-parser))
> > (let ((*package* *my-parser-package*))
> 
> My guess would be that this is more synonymous with LOAD-TIME-VALUE,
> but again, I'm not sure. If I understand the Hyperspec, all code
> wrapped in a LOAD-TIME-VALUE is executed once, right at the start of
> the program and "inserted". However, #. is just a macro to evaluate
> "now", correct?

They are different "now"s.  LOAD-TIME-VALUE occurs when the compiled 
file is loaded.  #. occurs when the source code is read by the compiler.

However, they're close to equivalent if you load the source file rather 
than compiling it and loading the object file, or if you just type the 
code into the interpreter.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Vassil Nikolov
Subject: Re: Different execution in package
Date: 
Message-ID: <lzpt3kmy24.fsf@janus.vassil.nikolov.names>
"Jeff" <···@nospam.insightbb.com> writes:

> [...]
> My guess would be that this is more synonymous with LOAD-TIME-VALUE,
> but again, I'm not sure. If I understand the Hyperspec, all code
> wrapped in a LOAD-TIME-VALUE is executed once, right at the start of
> the program and "inserted". However, #. is just a macro to evaluate
> "now", correct?

  #. evaluates at read time, which is before compile time (perhaps
  shortly before); load time is after compile time (perhaps long after,
  often in a different image).

  ---Vassil.

-- 
Vassil Nikolov <········@poboxes.com>

Hollerith's Law of Docstrings: Everything can be summarized in 72 bytes.