From 2bcf0551dff645b8c691290adf58dc890b79e745 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Mon, 19 May 2014 11:49:09 +0400 Subject: [PATCH] * src/lisp.h (CHECK_BOOLEAN): New function. * src/alloc.c (Fbool_vector): New function. (syms_of_alloc): Defsubr it. * src/data.c (Qbooleanp): New symbol. (syms_of_data): DEFSYM it. * src/dbusbind.c (xd_signature): Use CHECK_BOOLEAN. * doc/lispref/sequences.texi (Bool-vectors): Mention bool-vector. --- doc/lispref/ChangeLog | 4 ++++ doc/lispref/sequences.texi | 33 +++++++++++++++++++++++++++++---- src/ChangeLog | 9 +++++++++ src/alloc.c | 20 ++++++++++++++++++++ src/data.c | 3 ++- src/dbusbind.c | 3 +-- src/lisp.h | 7 ++++++- 7 files changed, 71 insertions(+), 8 deletions(-) diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index d892e1307a0..9614b89f66e 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,3 +1,7 @@ +2014-05-19 Dmitry Antipov + + * sequences.texi (Bool-vectors): Mention bool-vector. + 2014-05-17 Paul Eggert Assume C99 or later (Bug#17487). diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index da53990b449..1f7cd435cf6 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi @@ -811,7 +811,7 @@ value into an element of the bool-vector, the effect is to store and the length cannot be changed once the bool-vector is created. Bool-vectors are constants when evaluated. - There are two special functions for working with bool-vectors; aside + There are three special functions for working with bool-vectors; aside from that, you manipulate them with same functions used for other kinds of arrays. @@ -820,6 +820,32 @@ Return a new bool-vector of @var{length} elements, each one initialized to @var{initial}. @end defun +@defun bool-vector &rest objects +This function creates and returns a bool-vector whose elements are the +arguments, @var{objects}, each of them should be either @code{t} or @code{nil}. +Note that the printed form represents up to 8 boolean values as a single +character: + +@example +@group +(bool-vector t nil t nil) + @result{} #&4"^E" +(bool-vector) + @result{} #&0"" +@end group +@end example + +If you want to print a bool-vector in a way similar to other vectors, +you can use @code{vconcat} function: + +@example +@group +(vconcat (bool-vector nil t nil t)) + @result{} [nil t nil t] +@end group +@end example +@end defun + @defun bool-vector-p object This returns @code{t} if @var{object} is a bool-vector, and @code{nil} otherwise. @@ -873,9 +899,8 @@ or @code{nil}, and @var{i} is an index into @code{a}. Return the number of elements that are @code{t} in bool vector @var{a}. @end defun - Here is an example of creating, examining, and updating a -bool-vector. Note that the printed form represents up to 8 boolean -values as a single character. + Here is another example of creating, examining, and updating a +bool-vector: @example (setq bv (make-bool-vector 5 t)) diff --git a/src/ChangeLog b/src/ChangeLog index 31fe13e074c..06377ba257d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2014-05-19 Dmitry Antipov + + * lisp.h (CHECK_BOOLEAN): New function. + * alloc.c (Fbool_vector): New function. + (syms_of_alloc): Defsubr it. + * data.c (Qbooleanp): New symbol. + (syms_of_data): DEFSYM it. + * dbusbind.c (xd_signature): Use CHECK_BOOLEAN. + 2014-05-17 Paul Eggert Assume C99 or later (Bug#17487). diff --git a/src/alloc.c b/src/alloc.c index 7159d1fa747..e808c3d4bf3 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -2174,6 +2174,25 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */) return bool_vector_fill (val, init); } +DEFUN ("bool-vector", Fbool_vector, Sbool_vector, 0, MANY, 0, + doc: /* Return a new bool-vector with specified arguments as elements. +Any number of arguments, even zero arguments, are allowed. +Each argument should be either t or nil. +usage: (bool-vector &rest OBJECTS) */) + (ptrdiff_t nargs, Lisp_Object *args) +{ + ptrdiff_t i; + Lisp_Object vector; + + for (i = 0; i < nargs; i++) + CHECK_BOOLEAN (args[i]); + + vector = make_uninit_bool_vector (nargs); + for (i = 0; i < nargs; i++) + bool_vector_set (vector, i, !NILP (args[i])); + + return vector; +} /* Make a string from NBYTES bytes at CONTENTS, and compute the number of characters from the contents. This string may be unibyte or @@ -7102,6 +7121,7 @@ The time is in seconds as a floating point value. */); defsubr (&Scons); defsubr (&Slist); defsubr (&Svector); + defsubr (&Sbool_vector); defsubr (&Smake_byte_code); defsubr (&Smake_list); defsubr (&Smake_vector); diff --git a/src/data.c b/src/data.c index bf863aaed79..4061311e7ba 100644 --- a/src/data.c +++ b/src/data.c @@ -54,7 +54,7 @@ Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive; Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only; Lisp_Object Qtext_read_only; -Lisp_Object Qintegerp, Qwholenump, Qsymbolp, Qlistp, Qconsp; +Lisp_Object Qintegerp, Qwholenump, Qsymbolp, Qlistp, Qconsp, Qbooleanp; static Lisp_Object Qnatnump; Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp; Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp; @@ -3442,6 +3442,7 @@ syms_of_data (void) DEFSYM (Qlistp, "listp"); DEFSYM (Qconsp, "consp"); + DEFSYM (Qbooleanp, "booleanp"); DEFSYM (Qsymbolp, "symbolp"); DEFSYM (Qkeywordp, "keywordp"); DEFSYM (Qintegerp, "integerp"); diff --git a/src/dbusbind.c b/src/dbusbind.c index 8997e01b068..768e0a11b1c 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c @@ -387,8 +387,7 @@ xd_signature (char *signature, int dtype, int parent_type, Lisp_Object object) break; case DBUS_TYPE_BOOLEAN: - if (!EQ (object, Qt) && !EQ (object, Qnil)) - wrong_type_argument (intern ("booleanp"), object); + CHECK_BOOLEAN (object); sprintf (signature, "%c", dtype); break; diff --git a/src/lisp.h b/src/lisp.h index 67b26ef91c7..88ccaec4070 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -796,7 +796,7 @@ extern int char_table_translate (Lisp_Object, int); /* Defined in data.c. */ extern Lisp_Object Qarrayp, Qbufferp, Qbuffer_or_string_p, Qchar_table_p; extern Lisp_Object Qconsp, Qfloatp, Qintegerp, Qlambda, Qlistp, Qmarkerp, Qnil; -extern Lisp_Object Qnumberp, Qstringp, Qsymbolp, Qt, Qvectorp; +extern Lisp_Object Qnumberp, Qstringp, Qsymbolp, Qt, Qvectorp, Qbooleanp; extern Lisp_Object Qbool_vector_p; extern Lisp_Object Qvector_or_char_table_p, Qwholenump; extern Lisp_Object Qwindow; @@ -2510,6 +2510,11 @@ CHECK_CONS (Lisp_Object x) CHECK_TYPE (CONSP (x), Qconsp, x); } INLINE void +CHECK_BOOLEAN (Lisp_Object x) +{ + CHECK_TYPE (EQ (x, Qt) || EQ (x, Qnil), Qbooleanp, x); +} +INLINE void CHECK_VECTOR (Lisp_Object x) { CHECK_TYPE (VECTORP (x), Qvectorp, x); -- 2.39.5