printing readably an array of type bit!
- From: "\"(typep 'nil (statisfies 'identity))\"" <christophamort@xxxxxxxx>
- Date: Thu, 30 Oct 2008 16:57:34 -0700 (PDT)
I like bit arrays because they are so fast in computing bit
operations, but would like to store their content. ... so I ran into
following error:
(let ((bit-array (make-array (list 3 3) :element-type 'bit
:initial-contents
'((0 0 0) (1 1 1) (0 0
0))))
(*print-readably* t)
(*print-array* t))
(print bit-array))
Error: Unable to print #2A((0 0 0) (1 1 1) (0 0 0)) readably and
*print-readably* is true.
[condition type: print-not-readable]
.... if I remowe the (*print-readably* t) it prints normal as expected
the array:
=> #2A((0 0 0) (1 1 1) (0 0 0))
.... but this is not a (simple-array bit *), it is of type (array t).
(let ((bit-array (make-array (list 3 3)
:element-type 'bit
:initial-contents
'((0 0 0) (1 1 1) (0 0 0)))))
(array-element-type (read-from-string (write-to-string bit-
array :array t))))
=> t
Then I was thinking to define my own print-object method:
(defmethod print-object ((array0 array) (stream0 stream))
(format stream0 "#.~S"
`(make-array ,(array-dimensions array0)
:element-type (array-element-type array0)
:initial-contents ,(loop for i from 0 below (array-
dimension array0 0)
collect (loop for j from 0
below (array-dimension array0 0)
collect (bit
array0 i j))))))
..... when I evaluate the expression my implementation (Allegro 7.1)
fails gracefully like a stone!
So, what to do?
- Add a specialized method for bit arrays ...
- Write a non generic Function, and every time I print an object I've
to check if it is
an array of type bit ... pffff. NOT NICE!
- find a way to use the #* notation of bit-vectors?
Suggestions and solutions welcome!
c.
.
- Follow-Ups:
- Re: printing readably an array of type bit!
- From: Barry Margolin
- Re: printing readably an array of type bit!
- Prev by Date: Re: use-package & name conflict: why they are not deferred?
- Next by Date: Re: Is it a bad sign...
- Previous by thread: Convert html diacritics to unicode
- Next by thread: Re: printing readably an array of type bit!
- Index(es):