home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / lisp / 2347 < prev    next >
Encoding:
Internet Message Format  |  1992-08-31  |  1.7 KB

  1. Path: sparky!uunet!munnari.oz.au!goanna!ok
  2. From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Re: Freezing a variable: how?
  5. Message-ID: <14290@goanna.cs.rmit.oz.au>
  6. Date: 1 Sep 92 04:35:10 GMT
  7. References: <1992Aug28.194300.20461@jpl-devvax.jpl.nasa.gov> <19920829213038.4.KMP@PLANTAIN.SCRC.Symbolics.COM>
  8. Organization: Comp Sci, RMIT, Melbourne, Australia
  9. Lines: 33
  10.  
  11. In article <19920829213038.4.KMP@PLANTAIN.SCRC.Symbolics.COM>, KMP@stony-brook.scrc.symbolics.com (Kent M Pitman) writes:
  12. > It's not remarkably graceful, but for some purposes it might work to just
  13. > promote the variable to a constant by doing DEFCONSTANT of the thing which
  14. > is already a variable.
  15.  
  16. As I understand it, a program is loaded in two phases, in the first of which
  17. a variable is updated, and in the second of which it should be read-only.
  18.  
  19. The thought that occurs to me at once is "why does it have to be the same
  20. variable?"  Why can't there be a variable which is updated by the first phase,
  21. and the last thing it installs is a defconstant holding the final value of the
  22. thing?
  23.  
  24. As an alternative, you can do this in Scheme:
  25.  
  26.     (define thingy "thingy")
  27.     (define set-thingy! "set-thingy!")
  28.     (let ((hidden-variable initial-value))
  29.         (set! thingy (lambda () hidden-variable))
  30.         (set! set-thingy! (lambda (x) (set! hidden-variable x) "!"))
  31.         "access functions for thingy defined")
  32.  
  33.     ;; first phase now uses (thingy) and (set-thingy! x)
  34.  
  35.     (set! set-thingy! (lambda (x) (error <dialect-dependent arguments>)))
  36.  
  37.     ;; second phase now uses (thingy) but cannot change the value at all
  38.     ;; In fact, _no-one_ can change hidden-variable any more.
  39.  
  40. Presumably something similar is doable in Common Lisp.
  41.  
  42. -- 
  43. You can lie with statistics ... but not to a statistician.
  44.