home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!cs.utexas.edu!sdd.hp.com!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.lang.lisp
- Subject: Re: static, a.k.a. eval-once
- Date: 31 Aug 1992 21:22:28 GMT
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 61
- Message-ID: <17u2ikINNs6g@early-bird.think.com>
- References: <7399@skye.ed.ac.uk>
- NNTP-Posting-Host: telecaster.think.com
-
- In article <7399@skye.ed.ac.uk> jeff@aiai.ed.ac.uk (Jeff Dalton) writes:
- >About 4 years ago, I wrote an EVAL-ONCE macro. It appears, with
- >an explanation below. It has been claimed that my macro isn't
- >portable because the behavior of gensyms isn't sufficiently
- >restricted when compile and load is involved. What I want to
- >know is:
- >
- > 1. Is there a problem with using GENSYM this way?
-
- I think it should work. While the compiler has to arrange for all
- references to a particular gensym within a binary file to be the object,
- similarly named gensyms in different binary files should refer to different
- instances.
-
- BTW, I assume you realize that V should be a gensym, i.e. it should be:
-
- I think your version can be simplified a bit. The expansion doesn't need a
- LET binding:
-
- (defmacro eval-once (form)
- (let ((var (gensym)))
- `(if (boundp ',var)
- (symbol-value ',var)
- (set ',var ,form))))
-
- > 2. Is there a better way to get what I want.
-
- Not that I can think of quickly (I thought of using something like Scheme's
- delay/force, but it didn't work).
-
- This looks suspiciously like the stuff we were discussing a few months ago,
- where you wanted the ability to have modifiable literals in your program.
- If that were allowed, you could do:
-
- (defstruct eval-once
- (done nil)
- value)
-
- (defmacro eval-once (form)
- (let ((struct (make-eval-once)))
- `(if (eval-once-done ',struct)
- (eval-once-value ',struct)
- (setf (eval-once-done ',struct) t
- (eval-once-value ',struct) ,form)))))
-
- > 3. Is there a way that will get the EVAL-ONCE effect in
- > interpreted code even in an "expand macros each time"
- > implementation? (N.B. There is no correct portable way
- > to use *macroexpand-hook* cache macro expansions --
- > see page 204 of CLtL II.)
- ...
- >For the interpreted code problem, I can't think of anything better
- >than having EVAL-ONCE assume that EQ forms are never logically
- >different expressions.
-
- I can't think of another way, either.
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-