GNU bug report logs - #6878
bool-vectors of length 0 signal error when aref/aset the 0th element

Previous Next

Package: emacs;

Reported by: MON KEY <monkey <at> sandpframing.com>

Date: Wed, 18 Aug 2010 04:19:02 UTC

Severity: minor

Done: Chong Yidong <cyd <at> stupidchicken.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: MON KEY <monkey <at> sandpframing.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: lekktu <at> gmail.com, cyd <at> stupidchicken.com, schwab <at> linux-m68k.org, 6878 <at> debbugs.gnu.org
Subject: bug#6878: bool-vectors of length 0 signal error when aref/aset the 0th element
Date: Fri, 20 Aug 2010 14:44:12 -0400
On Fri, Aug 20, 2010 at 9:02 AM, Stefan Monnier
<monnier <at> iro.umontreal.ca> wrote:
>> As you wish. Though, I don't think changing the wording solves the
>> real problem If there are no good reasons to create a boole-vectro of
>> length 0 why allow it?
>
> That's the wrong question. The question is: why not allow them?

How about Juanma's example earlier wich is a mis-application of substring on
vectors satisfying the predicate `bool-vector-p' e.g. his:

> (defun split-vec (v p)
>  (list (substring v 0 p)
>        (substring v p (length v))))


>
>> Emacs lisp doesn't and I can think of no good reasons to create 0
>> length bool-vectors.
>> Can any one else?
>
> The same reasons to create zero-length strings.
>

I'm not convinced.
Anyhow, my query included the caveat "good reasons" :)

(substring (make-bool-vector 0 t) 0)

;=> Debugger entered--Lisp error: (wrong-type-argument arrayp #&0"")

And, it doesn't really work for vectors either:

(substring (make-vector 0 1) 0)
;=> []

Likewise, where is the sense in these:

(apply 'string (append (make-bool-vector 0 t) nil))
;=> ""

(concat (make-bool-vector 0 t))
;=> ""

When this:
(concat)
;=> ""

and this:
(apply 'string nil)
;=> ""

would suffice.

Note, I _do_ recognize that there is some utility for things like this w/
_vanilla_ vectors:

(defmacro v->empty (&optional char-val-maybe)
  (let ((vvoid (make-symbol "vvoid")))
    `(let ((,vvoid (if (characterp ,char-val-maybe)
                       1 0)))
       (make-vector ,vvoid ,char-val-maybe))))

(v->empty 'not-a-char)
;=> []
(v->empty 32)
;=> [32]
(v->empty)
;=> []

(mapconcat #'identity
           (mapcar  #'(lambda (ve) (concat (v->empty ve)))
                    '(119 'not-a-char 32 nil 111 'nor-inil
                          32 "nope" 119 'nada 33)) "")

But I can't see how the `make-vector' idiom would translate for
`make-bool-vector'.

>        Stefan
>

--
/s_P\




This bug report was last modified 14 years and 337 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.