common-lisp-extensions icon indicating copy to clipboard operation
common-lisp-extensions copied to clipboard

Printing / reading specialized arrays

Open guicho271828 opened this issue 5 years ago • 6 comments

#A((SIGNED-BYTE 8) (2 2) ((0 0) (0 0)))

  • [ ] SBCL
  • [ ] CCL
  • [ ] ECL
  • [x] CMU
  • [ ] ABCL
  • [x] ALISP

guicho271828 avatar May 19 '19 10:05 guicho271828

SBCL has similar syntax but the array dimensions and type are switched, and the array values are consed on to the end:

* (setf *print-readably* t)
T
* (make-array '(2 2) :element-type '(signed-byte 8) :initial-element '0)
#A((2 2) (SIGNED-BYTE 8) (0 0) (0 0))

no-defun-allowed avatar May 21 '19 12:05 no-defun-allowed

hmm, which sbcl version are you using? I can't reproduce the behavior

guicho271828 avatar May 21 '19 15:05 guicho271828

I now see, it should be printed, not on the repl.

guicho271828 avatar May 21 '19 15:05 guicho271828

Personally I feel it is saner to have a form

#A((2 2) :element-type (signed-byte 8) :initial-contents ((0 0) (0 0)))

because it preserves the duality between the constructor and the reader.

guicho271828 avatar May 21 '19 15:05 guicho271828

The same goes with the structure literals:

#S(point2d :x 0 :y 0)

reflects the constructor function call (point2d :x 0 :y 0).

guicho271828 avatar May 21 '19 15:05 guicho271828

Allegro Common Lisp extends #A reader macro for similar purpose, but its syntax is very different from the one discussed here.

See https://franz.com/support/documentation/10.1/doc/implementation.htm#sharpsign-a-2

y2q-actionman avatar May 23 '19 04:05 y2q-actionman