From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: MON KEY Newsgroups: gmane.emacs.bugs 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 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: dough.gmane.org 1282183753 17663 80.91.229.12 (19 Aug 2010 02:09:13 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 19 Aug 2010 02:09:13 +0000 (UTC) Cc: Andreas Schwab , 6878@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 19 04:09:11 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OluZ1-0005XY-N4 for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Aug 2010 04:09:08 +0200 Original-Received: from localhost ([127.0.0.1]:58195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OluZ0-000728-F9 for geb-bug-gnu-emacs@m.gmane.org; Wed, 18 Aug 2010 22:09:06 -0400 Original-Received: from [140.186.70.92] (port=41021 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OluYt-000720-I7 for bug-gnu-emacs@gnu.org; Wed, 18 Aug 2010 22:09:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OluYs-0008FT-0S for bug-gnu-emacs@gnu.org; Wed, 18 Aug 2010 22:08:59 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:47223) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OluYr-0008FM-U7 for bug-gnu-emacs@gnu.org; Wed, 18 Aug 2010 22:08:57 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1OluHW-0001HK-5X; Wed, 18 Aug 2010 21:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: MON KEY Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Aug 2010 01:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6878 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 6878-submit@debbugs.gnu.org id=B6878.12821826064906 (code B ref 6878); Thu, 19 Aug 2010 01:51:02 +0000 Original-Received: (at 6878) by debbugs.gnu.org; 19 Aug 2010 01:50:06 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OluGc-0001H5-9f for submit@debbugs.gnu.org; Wed, 18 Aug 2010 21:50:06 -0400 Original-Received: from mail-wy0-f172.google.com ([74.125.82.172]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OluGZ-0001Gg-KG for 6878@debbugs.gnu.org; Wed, 18 Aug 2010 21:50:04 -0400 Original-Received: by wyb40 with SMTP id 40so1470112wyb.3 for <6878@debbugs.gnu.org>; Wed, 18 Aug 2010 18:51:09 -0700 (PDT) Original-Received: by 10.216.44.209 with SMTP id n59mr86085web.58.1282182669100; Wed, 18 Aug 2010 18:51:09 -0700 (PDT) Original-Received: by 10.216.65.140 with HTTP; Wed, 18 Aug 2010 18:51:09 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: Ag93yKGBs2fuJGuGB836gGWfdU0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Wed, 18 Aug 2010 21:51:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:39615 Archived-At: On Wed, Aug 18, 2010 at 3:36 AM, Stefan Monnier 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\