guicho271828 / common-lisp-extensions

list of extensions beyond CL available in lisp implementations, and the status of its spread.
21 stars 0 forks source link

Printing / reading specialized arrays #4

Open guicho271828 opened 5 years ago

guicho271828 commented 5 years ago

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

no-defun-allowed commented 5 years ago

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))
guicho271828 commented 5 years ago

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

guicho271828 commented 5 years ago

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

guicho271828 commented 5 years ago

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 commented 5 years ago

The same goes with the structure literals:

#S(point2d :x 0 :y 0)

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

y2q-actionman commented 5 years ago

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