From: Jeff M.
Subject: How does Lisp compile constants?
Date: 
Message-ID: <1112913714.010365.55610@l41g2000cwc.googlegroups.com>
I'm wondering how Lisp compiles various constants that consist of more
than just simple literals. For example:

;; trivial example where load-bitmap returns an array of bytes
(defconstant img (load-bitmap "foobar.bmp"))

;; blit the constant image to the screen
(defun draw-window () (blit img 0 0))

So, back to my question: at compile time, will load-bitmap be called,
return the array of bytes and then `img` be set to some constant array?
Or, will the code be compiled so that on program startup the image will
be loaded?

If this is implementation specific, that'd be good to know, too :)

Thanks,
Jeff M.

From: Barry Margolin
Subject: Re: How does Lisp compile constants?
Date: 
Message-ID: <barmar-B0CEE4.20181807042005@comcast.dca.giganews.com>
In article <·······················@l41g2000cwc.googlegroups.com>,
 "Jeff M." <·······@gmail.com> wrote:
> If this is implementation specific, that'd be good to know, too :)

It's implementation specific.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Kent M Pitman
Subject: Re: How does Lisp compile constants?
Date: 
Message-ID: <ubr8nlvje.fsf@nhplace.com>
Barry Margolin <······@alum.mit.edu> writes:

> In article <·······················@l41g2000cwc.googlegroups.com>,
>  "Jeff M." <·······@gmail.com> wrote:
> > If this is implementation specific, that'd be good to know, too :)
> 
> It's implementation specific.

Right.  DEFCONSTANT is allowed to be treated pretty much like DEFPARAMETER
if the compiler doesn't have inlining.  So the compiler is permitted, but
not required, to load it at compile time.  Your environment must be set up
to work in both cases.

As someone else noted, you can use #. to force read-time processing.

You might also be interested in LOAD-TIME-VALUE which executes at execution
time (so you don' thave to have the compile-time environment set up for
what you're doing) but still behaves like a constant on an ongoing basis.
It gives power similar to an 'own' variable in Algol or a static variable
in a C++ member function.
From: Frank Buss
Subject: Re: How does Lisp compile constants?
Date: 
Message-ID: <d34j15$rjf$1@newsreader3.netcologne.de>
"Jeff M." <·······@gmail.com> wrote:

> (defconstant img (load-bitmap "foobar.bmp"))
> 
> So, back to my question: at compile time, will load-bitmap be called,
> return the array of bytes and then `img` be set to some constant
> array? 

I don't know, but you can force to execute at compile time with the #.
reader macro, like I've done in my example for something like a Lisp
resource compiler: 

http://groups.google.de/groups?selm=d12d40%24qvs%241%40newsreader2.netcologne.de 

-- 
Frank Bu�, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de