From: MON KEY <monkey@sandpframing.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Andreas Schwab <schwab@linux-m68k.org>, 6878@debbugs.gnu.org
Subject: bug#6878: bool-vectors of length 0 signal error when aref/aset the 0th element
Date: Wed, 18 Aug 2010 21:51:09 -0400 [thread overview]
Message-ID: <AANLkTinXTNQ4L8UPz9Ef5zsuLFZJhk3xaTCPmkUKqsbn@mail.gmail.com> (raw)
In-Reply-To: <jwvtyms4bll.fsf-monnier+emacs@gnu.org>
On Wed, Aug 18, 2010 at 3:36 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> When aref/aset'ing the 0th element of a bool-vectors of length 0 i get
>> an args-out-of-range 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..N-1, 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 bool-vector, again (note the "must"):
,---- (info "(elisp)Bool-Vector Type")
|
| "A "bool-vector" is a one-dimensional array of elements that must be `t'
| or `nil'."
|
`----
So why would/should Emacs let me create a bool-vectors 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/ bool-vectors because they are _limited_
by the type of data they can represenet. Coercing 0 length bool-vector returns a
bool-vector whereas coercing a like vanilla vector yields a vector e.g.:
(append (make-bool-vector 0 t) '())
;=> #&0""
(append (make-vector 0 1))
;=> []
This presents a presents a problem when one _expects_ a bool-vector to be
treated as a first class array:
(let* ((ab (make-bool-vector 0 t))
(abeq (cons ab ab)))
(concat (car abeq) (cdr abeq)))
;=> ""
(let* ((av (make-vector 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 (make-bool-vector 0 t))
(abeq (cons ab ab))
(av (make-vector 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 (make-vector 1 116))
(aseq (cons ab ab)))
(concat (car aseq) (cdr aseq)))
;=> "tt"
This doesn't:
(let* ((ab (make-bool-vector 1 t))
(abeq (cons ab ab)))
(concat (car abeq) (cdr abeq)))
;
;=> Debugger entered--Lisp error: (wrong-type-argument integerp t)
Honestly I can't find the utility of 0 length bool-vectors in a lisp system
which doesn't allow tweaking arrays at a lower level than Emacs presently
allows. Maybe bool-vectors were intended (at some point long ago)
to be (or to be eventually) made adjustable :) :
CL-USER> (setq ba (make-array 0 :element-type 'bit :adjustable t))
CL-USER> ba
#*
CL-USER> (adjustable-array-p ba)
T
CL-USER> (array-dimension ba 0)
0
CL-USER> (array-dimensions ba)
(0)
CL-USER> (adjust-array ba 1)
#*0
CL-USER> ba
#*0
CL-USER> (bit-vector-p ba)
T
CL-USER> (bit ba 0)
0
(setf (bit ba 0) 1)
1
CL-USER> (bit ba 0)
1
CL-USER> ba
#*1
--
/s_P\
next prev parent reply other threads:[~2010-08-19 1:51 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-18 4:19 bug#6878: bool-vectors of length 0 signal error when aref/aset the 0th element MON KEY
2010-08-18 7:36 ` Stefan Monnier
2010-08-19 1:51 ` MON KEY [this message]
2010-08-19 8:42 ` Andreas Schwab
2010-08-19 14:13 ` MON KEY
2010-08-19 15:51 ` Stefan Monnier
2010-08-19 17:06 ` MON KEY
2010-08-19 14:47 ` Stefan Monnier
2010-08-19 15:04 ` Andreas Schwab
2010-08-19 16:18 ` Chong Yidong
2010-08-19 17:09 ` MON KEY
2010-08-19 18:40 ` Juanma Barranquero
2010-08-19 23:24 ` Chong Yidong
2010-08-20 2:01 ` MON KEY
2010-08-20 2:23 ` Juanma Barranquero
2010-08-20 18:01 ` MON KEY
2010-08-20 19:49 ` Juanma Barranquero
2010-08-20 23:06 ` MON KEY
2010-08-20 13:02 ` Stefan Monnier
2010-08-20 18:44 ` MON KEY
2010-08-21 12:40 ` Kevin Rodgers
2010-08-21 15:53 ` Andreas Schwab
2010-08-21 17:02 ` MON KEY
2010-08-18 8:36 ` Andreas Schwab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTinXTNQ4L8UPz9Ef5zsuLFZJhk3xaTCPmkUKqsbn@mail.gmail.com \
--to=monkey@sandpframing.com \
--cc=6878@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=schwab@linux-m68k.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).