home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!goanna!ok
- From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
- Newsgroups: comp.lang.lisp
- Subject: Re: Freezing a variable: how?
- Message-ID: <14290@goanna.cs.rmit.oz.au>
- Date: 1 Sep 92 04:35:10 GMT
- References: <1992Aug28.194300.20461@jpl-devvax.jpl.nasa.gov> <19920829213038.4.KMP@PLANTAIN.SCRC.Symbolics.COM>
- Organization: Comp Sci, RMIT, Melbourne, Australia
- Lines: 33
-
- In article <19920829213038.4.KMP@PLANTAIN.SCRC.Symbolics.COM>, KMP@stony-brook.scrc.symbolics.com (Kent M Pitman) writes:
- > It's not remarkably graceful, but for some purposes it might work to just
- > promote the variable to a constant by doing DEFCONSTANT of the thing which
- > is already a variable.
-
- As I understand it, a program is loaded in two phases, in the first of which
- a variable is updated, and in the second of which it should be read-only.
-
- The thought that occurs to me at once is "why does it have to be the same
- variable?" Why can't there be a variable which is updated by the first phase,
- and the last thing it installs is a defconstant holding the final value of the
- thing?
-
- As an alternative, you can do this in Scheme:
-
- (define thingy "thingy")
- (define set-thingy! "set-thingy!")
- (let ((hidden-variable initial-value))
- (set! thingy (lambda () hidden-variable))
- (set! set-thingy! (lambda (x) (set! hidden-variable x) "!"))
- "access functions for thingy defined")
-
- ;; first phase now uses (thingy) and (set-thingy! x)
-
- (set! set-thingy! (lambda (x) (error <dialect-dependent arguments>)))
-
- ;; second phase now uses (thingy) but cannot change the value at all
- ;; In fact, _no-one_ can change hidden-variable any more.
-
- Presumably something similar is doable in Common Lisp.
-
- --
- You can lie with statistics ... but not to a statistician.
-