I'd like to re-submit this patch and ask for some advice, if it is
It basically fixes this:
(format nil "~s" (make-array 2 :element-type 'single-float
:initial-contents '(1.0 2.0))))
to output this:
#.(make-array 2 :element-type 'single-float :initial-contents '(1.0 2.0))
instead of generating an error condition or printing #(1.0 2.0) (ie.
re-loaded without type
One cannot provide a print-object method specialised on this kind of
type-specialized array. So, I would really like to get this
functionality into SBCL, if it is at all possible, to save having to
work-around it untidily.
Bill Robinson <airbaggins@...> writes:
> I'd like to re-submit this patch and ask for some advice, if it is
Not that I'm wild about this -- because I'm not convinced of the
utility of providing #. read syntaxes, particularly of stuff that is
explicitly not standardly required -- but at the very least any
putative patch along these lines needs to respect the interaction of
*read-eval* and *print-readably* documented in the Notes section of
*READ-EVAL* in the spec.
I have made a couple of changes to this patch again.
Last submission (I submitted the email in HTML, sorry, maybe it got missed):
* Fix: Reworked to obey *read-eval* and throw the print-not-readable
if not permitted to use #.
* Added: Test case at tests/print-typed-array-readably.impure.lisp
for a variety of arrays, asserting that the printed output is equalp
to the original object when it is read back in and that errors get
thrown when they should.
* Rationale: As one cannot specialize print-object for system
classes, printing typed single-float, double-float, fixnum, etc.
arrays with *print-readably* t (and *read-eval* t) only yields errors.
So if you want to preserve the element-type, this requires wrapping
print-object (for simple cases), or writing your own printer system,
with all the features you might need (like print-circle, print-case,
etc), in application space. So it's an attempt to avoid duplicate
Changes since last submission:
* Refactor: Abstracted out the actual printing of the #.(MAKE-ARRAY
...) to the function output-read-eval-array-guts for use in both
output-read-eval-array-guts and output-read-eval-vector.
* Refactor: Made output-array slightly more orthogonal with
output-vector in that the decision of output strategy is made there
and not in the output-array-guts function.
I am still hoping this functionality would be compatible with the SBCL