all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#6878: bool-vectors of length 0 signal error when aref/aset the 0th element
@ 2010-08-18  4:19 MON KEY
  2010-08-18  7:36 ` Stefan Monnier
  2010-08-18  8:36 ` Andreas Schwab
  0 siblings, 2 replies; 24+ messages in thread
From: MON KEY @ 2010-08-18  4:19 UTC (permalink / raw
  To: 6878

When aref/aset'ing the 0th element of a bool-vectors of length 0 i get
an args-out-of-range error:

(setq tt--bv (make-bool-vector 29 t))
;=> #&29"\377\377\377\x1f"

(vconcat (make-bool-vector 29 t))
; => [t { ... 27 t's ... } t]

(aref tt--bv 0)
;=> t

(aset tt--bv 0 nil)
;=> nil

(setq tt--bv (make-bool-vector 0 t))
;=> #&0""

(vconcat (make-bool-vector 0 t))
;=> []

(aref tt--bv 0)
;=> Debugger entered--Lisp error: (args-out-of-range #&0"" 0)

(aset tt--bv 0 t)
;=> Debugger entered--Lisp error: (args-out-of-range #&0"" 0)

As with the the first bool-vector of length 29 the second bool-vector
of length 0 should also have a value at element 0 that evaluates to
`t'.  (Or, it should according to the manual):

,---- (info "(elisp)Bool-Vector Type")
|
| "A "bool-vector" is a one-dimensional array of elements that must be
| `t' or `nil'."
|
`----

I can't find mention in the docs that the 0th element of a bool-vector
is void for 0 length bool-vectors. Indeed, it isn't at all clear why
it should.

I find this is problematic because there aren't any equivalents to
`car-safe'/`safe-length' for generalized bool-vectors operations.

Obv. taking the 0th index of a vector or char-table also signals an
args-out-of-range error however I belive this for slightly different
reasons.

(setq tt--mv (make-vector 0 t))
;=> []

(vectorp tt--mv)
;=> t

(vectorp tt--bv)
;=> nil

(char-table-p tt--bv)
;=> nil

(vector-or-char-table-p tt--bv)
;=> nil

(arrayp tt--bv)
;=> t

(bool-vector-p tt--bv)
;=> t

(null tt--bv)
;=> nil

(null (append tt--bv))
;=> nil

(null (append tt--bv nil))
;=> t

Maybe something like this is needed:

(defun safe-aref-bool-vector (bool-vector idx)
  (if (and (bool-vector-p bool-vector)
           (not (null (append bool-vector nil))))
      (aref bool-vector idx)
    0))

(defun safe-aset-bool-vector (bool-vector idx)
  (if (and (bool-vector-p bool-vector)
           (not (null (append bool-vector nil))))
      (aset bool-vector idx)
    0))





^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2010-08-21 17:02 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.