[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Immutable code and quoted data



I agree that the report should not constrain implementations
one way or another on the quote/mutable issue.  There are 
reasonable arguments on both sides.

On the immutable side, it can be more efficient in terms of
garbage collection and virtual memory if an implementation
is allowed to put quoted structures in read-only memory.

On the mutable side, it can be quite useful for quote to
produce mutable structures to share or retain state.  For
example, consider the following implementation of "once",
presumably as a macro, where "(once e)" evalutates "e" only
once and thereafter returns the same value:

   (once e) =>

   (let ([x '(any . #!false)])		; x not appearing in e
      (unless (cdr x)
         (set-car! x e)
         (set-cdr! x #!true))
      (car x))

A perverse example using once:

   (begin
      (define foo (lambda (x) (once x)))
      (foo 3)
      (foo 4)) => 3

The same sort of idea can be used for "own" variables.

Things get even stranger when quote is used to introduce the
same (identical) structure in two separate places, for some
sort of communication purposes.  People here have actually
done this, although it causes problems with printing object
code in the absense of a hashing printer.