make-specialized-array-from-data, and meaning of "It is an error"
Bradley Lucier 01 Apr 2024 00:13 UTC
make-specialized-array-from-data has the calling pattern
==============================
Procedure: make-specialized-array-from-data data [ storage-class [
mutable? [ safe? ] ] ]
==============================
and has the further comments
==============================
Any missing optional arguments are assigned the values
generic-storage-class, (specialized-array-default-mutable?), and
(specialized-array-default-safe?), respectively.
...
It is an error if the arguments do not satisfy these conditions, or if
mutable? is true and data is not mutable.
==============================
There is an issue with the interaction between the value of the mutable?
argument (which may have the default value of
(specialized-array-default-mutable?)) and the statement "It is an error
... if mutable? is true and data is not mutable."
The sample implementation currently throws an error if mutable? is #t
and data is not, indeed, mutable (if it's a compile-time constant, for
example).
But the initial value of the parameter
(specialized-array-default-mutable?) is #t, so if someone wants to make
a little array from a string (as in the palindrome example) using
make-specialized-array-from-data, and the string is immutable, then an
error will be thrown, even if the user never intends to set any value in
the array.
So maybe one might want the default value of
(specialized-array-default-mutable?) to be #f, but that screws with all
kinds of assumptions of the user coming from other computer languages.
(Obligatory joke: Perhaps I should just ask that user.)
So I think I'll change the sample implementation to *not* throw an error
when someone attempts to make a mutable array from immutable data, and
to delay the error until someone actually tries to call the setter of
the resulting array.
I have the impression that the R7RS Large committee wants to change many
instances of "it is an error" to "a condition is raised" (or whatever
the current terminology is), i.e., to leave fewer error conditions open
ended. But I really don't know what would be right in this instant.
Brad