Mutation

BRIAN SPILSBURY zhivago@iglou.com
Wed, 14 May 1997 01:42:21 -0400 (EDT)


HB> Another approach is to create a brand new functional array by copying
HB> an existing mutable array.  This solves the problem of bad semantics,
HB> but forces you to throw away and GC a perfectly good mutable array for
HB> every immutable array.  So we have good semantics, but bad performance.

Another approach is to when you allocate them pass a generator.

(make-array 10 :allocation immutable :generator '(lambda (i) (random 100)))

to allocate an immutable array with 10 random numbers in it.

(make-array (length foo) :allocation immutable :generator
  `(lambda (i) (nth i ,foo)))

to initialize from a list.

A simple, clean solution?

Brian