[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#6878: boolvectors of length 0 signal error when aref/aset the 0th e
From: 
MON KEY 
Subject: 
bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element 
Date: 
Wed, 18 Aug 2010 21:51:09 0400 
On Wed, Aug 18, 2010 at 3:36 AM, Stefan Monnier
<address@hidden> wrote:
>> When aref/aset'ing the 0th element of a boolvectors of length 0 i get
>> an argsoutofrange error:
> To have a 0th element, an array needs to be of length >= 1.
Sure, this is true in the generalized case for an Elisp array.
> An array of length N has elements 0..N1, so an array of length
> 0 doesn't have any elements at all.
Maybe, but this is not what the manual has to say of the particular type of
array that is a boolvector, again (note the "must"):
, (info "(elisp)BoolVector Type")

 "A "boolvector" is a onedimensional array of elements that must be `t'
 or `nil'."

`
So why would/should Emacs let me create a boolvectors that I can neither set
nor get without signalling an error?
I can imagine there are situations where making 0 length vanilla vector has
utility because these are "closer" to list representation w/re the _type_ of
contents they can hold and can be reasonable coerced w/ less representational
loss of data but this is not the case w/ boolvectors because they are _limited_
by the type of data they can represenet. Coercing 0 length boolvector returns a
boolvector whereas coercing a like vanilla vector yields a vector e.g.:
(append (makeboolvector 0 t) '())
;=> #&0""
(append (makevector 0 1))
;=> []
This presents a presents a problem when one _expects_ a boolvector to be
treated as a first class array:
(let* ((ab (makeboolvector 0 t))
(abeq (cons ab ab)))
(concat (car abeq) (cdr abeq)))
;=> ""
(let* ((av (makevector 0 0))
(aveq (cons av av)))
(concat (car aveq) (cdr aveq)))
;=> ""
Indeed, if we are to believe the above return values the coercion results in two
return values which _are_ `eq':
(let* ((ab (makeboolvector 0 t))
(abeq (cons ab ab))
(av (makevector 0 0))
(aveq (cons av av)))
(eq (concat (car abeq) (cdr abeq))
(concat (car aveq) (cdr abeq))))
;=> t
However apropos Andreas' question:
> In which way are bool vectors different from other vectors?
Andreas, if your listening this is how:
This works:
(let* ((ab (makevector 1 116))
(aseq (cons ab ab)))
(concat (car aseq) (cdr aseq)))
;=> "tt"
This doesn't:
(let* ((ab (makeboolvector 1 t))
(abeq (cons ab ab)))
(concat (car abeq) (cdr abeq)))
;
;=> Debugger enteredLisp error: (wrongtypeargument integerp t)
Honestly I can't find the utility of 0 length boolvectors in a lisp system
which doesn't allow tweaking arrays at a lower level than Emacs presently
allows. Maybe boolvectors were intended (at some point long ago)
to be (or to be eventually) made adjustable :) :
CLUSER> (setq ba (makearray 0 :elementtype 'bit :adjustable t))
CLUSER> ba
#*
CLUSER> (adjustablearrayp ba)
T
CLUSER> (arraydimension ba 0)
0
CLUSER> (arraydimensions ba)
(0)
CLUSER> (adjustarray ba 1)
#*0
CLUSER> ba
#*0
CLUSER> (bitvectorp ba)
T
CLUSER> (bit ba 0)
0
(setf (bit ba 0) 1)
1
CLUSER> (bit ba 0)
1
CLUSER> ba
#*1

/s_P\
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element, MON KEY, 2010/08/18
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element, Stefan Monnier, 2010/08/18
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element,
MON KEY <=
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element, Andreas Schwab, 2010/08/19
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element, MON KEY, 2010/08/19
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element, Stefan Monnier, 2010/08/19
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element, MON KEY, 2010/08/19
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element, Stefan Monnier, 2010/08/19
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element, Andreas Schwab, 2010/08/19
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element, Chong Yidong, 2010/08/19
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element, MON KEY, 2010/08/19
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element, Juanma Barranquero, 2010/08/19
 bug#6878: boolvectors of length 0 signal error when aref/aset the 0th element, Chong Yidong, 2010/08/19