Hi,

lloda schreef op do 25-11-2021 om 20:08 [+0100]:
I think literal arrays are always immutable, and one could base the
test on that.
>
Is such a function useful in some other context? If one has an array which is 
already immutable, it can be referenced freely and copying it seems 
unnecessary. If one has a mutable array, is there any reason why one would want 
to make an immutable copy?

To avoid accidental mutation (though at the cost of making a copy).

Also, literals aren't necessarily immutable if 'eval' is used:

(let ((literal (make-array 0 1 1))) (eval `(array-set! ',literal #xff 0 0) 
(current-module)) literal)
;; output: #2((255))

As-is, this is a somewhat contrived example. But 'eval' is useful REPL-like 
things,
and if someone implements a REPL-like thing, they might want to ‘immutabilise’
all input first such that array-set! on literals will actually produce an 
exception
as one would expect.

An alternative method would be to compile the code before running
(which is what the standard REPL does IIUC), but _requiring_ this extra step 
seems
suboptimal to me.

Greetings,
Maxime.

p.s. Somehow, your e-mail ended up in spam, for no apparent reason.


Reply via email to