Commit | Line | Data |
---|---|---|
210c0325 | 1 | /* Copyright (C) 1995, 1996, 2000, 2001, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
0f2d19dd | 2 | * |
73be1d9e | 3 | * This library is free software; you can redistribute it and/or |
53befeb7 NJ |
4 | * modify it under the terms of the GNU Lesser General Public License |
5 | * as published by the Free Software Foundation; either version 3 of | |
6 | * the License, or (at your option) any later version. | |
0f2d19dd | 7 | * |
53befeb7 NJ |
8 | * This library is distributed in the hope that it will be useful, but |
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
73be1d9e MV |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | * Lesser General Public License for more details. | |
0f2d19dd | 12 | * |
73be1d9e MV |
13 | * You should have received a copy of the GNU Lesser General Public |
14 | * License along with this library; if not, write to the Free Software | |
53befeb7 NJ |
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
16 | * 02110-1301 USA | |
73be1d9e | 17 | */ |
1bbd0b84 | 18 | |
1bbd0b84 | 19 | |
0f2d19dd | 20 | \f |
dbb605f5 LC |
21 | #ifdef HAVE_CONFIG_H |
22 | # include <config.h> | |
23 | #endif | |
0f2d19dd | 24 | |
a0599745 | 25 | #include "libguile/_scm.h" |
20e6290e | 26 | |
a0599745 MD |
27 | #include "libguile/validate.h" |
28 | #include "libguile/boolean.h" | |
1fe56d60 MV |
29 | #include "libguile/tags.h" |
30 | ||
45f4cbdf MW |
31 | #include "verify.h" |
32 | ||
0f2d19dd JB |
33 | \f |
34 | ||
45f4cbdf MW |
35 | /* |
36 | * These compile-time tests verify the properties needed for the | |
37 | * efficient test macros defined in boolean.h, which are defined in | |
38 | * terms of the SCM_MATCHES_BITS_IN_COMMON macro. | |
39 | * | |
40 | * See the comments preceeding the definitions of SCM_BOOL_F and | |
41 | * SCM_MATCHES_BITS_IN_COMMON in tags.h for more information. | |
42 | */ | |
210c0325 AW |
43 | verify (SCM_BITS_DIFFER_IN_EXACTLY_ONE_BIT_POSITION \ |
44 | (SCM_BOOL_F_BITS, SCM_BOOL_T_BITS)); | |
45 | verify (SCM_BITS_DIFFER_IN_EXACTLY_ONE_BIT_POSITION \ | |
46 | (SCM_ELISP_NIL_BITS, SCM_BOOL_F_BITS)); | |
47 | verify (SCM_BITS_DIFFER_IN_EXACTLY_ONE_BIT_POSITION \ | |
48 | (SCM_ELISP_NIL_BITS, SCM_EOL_BITS)); | |
49 | verify (SCM_BITS_DIFFER_IN_EXACTLY_TWO_BIT_POSITIONS \ | |
50 | (SCM_ELISP_NIL_BITS, SCM_BOOL_F_BITS, SCM_BOOL_T_BITS, \ | |
51 | SCM_XXX_ANOTHER_BOOLEAN_DONT_USE_0)); | |
52 | verify (SCM_BITS_DIFFER_IN_EXACTLY_TWO_BIT_POSITIONS \ | |
53 | (SCM_ELISP_NIL_BITS, SCM_BOOL_F_BITS, SCM_EOL_BITS, \ | |
54 | SCM_XXX_ANOTHER_LISP_FALSE_DONT_USE)); | |
0f2d19dd | 55 | |
3b3b36dd | 56 | SCM_DEFINE (scm_not, "not", 1, 0, 0, |
da4a1dba | 57 | (SCM x), |
d38b431a | 58 | "Return @code{#t} iff @var{x} is false, else return @code{#f}.") |
1bbd0b84 | 59 | #define FUNC_NAME s_scm_not |
0f2d19dd | 60 | { |
d38b431a | 61 | return scm_from_bool (scm_is_false (x)); |
0f2d19dd | 62 | } |
1bbd0b84 | 63 | #undef FUNC_NAME |
0f2d19dd | 64 | |
9348168e BT |
65 | SCM_DEFINE (scm_nil_p, "nil?", 1, 0, 0, |
66 | (SCM x), | |
67 | "Return @code{#t} iff @var{x} is nil, else return @code{#f}.") | |
68 | #define FUNC_NAME s_scm_nil_p | |
69 | { | |
70 | return scm_from_bool (scm_is_lisp_false (x)); | |
71 | } | |
72 | #undef FUNC_NAME | |
0f2d19dd | 73 | |
3b3b36dd | 74 | SCM_DEFINE (scm_boolean_p, "boolean?", 1, 0, 0, |
1bbd0b84 | 75 | (SCM obj), |
d38b431a | 76 | "Return @code{#t} iff @var{obj} is @code{#t} or false.") |
1bbd0b84 | 77 | #define FUNC_NAME s_scm_boolean_p |
0f2d19dd | 78 | { |
d38b431a | 79 | return scm_from_bool (scm_is_bool (obj)); |
0f2d19dd | 80 | } |
1bbd0b84 | 81 | #undef FUNC_NAME |
0f2d19dd | 82 | |
3a684cc6 MV |
83 | int |
84 | scm_to_bool (SCM x) | |
85 | { | |
d38b431a | 86 | if (scm_is_false (x)) |
3a684cc6 MV |
87 | return 0; |
88 | else if (scm_is_eq (x, SCM_BOOL_T)) | |
89 | return 1; | |
90 | else | |
91 | scm_wrong_type_arg (NULL, 0, x); | |
92 | } | |
1cc91f1b | 93 | |
baedef98 LC |
94 | /* We keep this primitive as a function in addition to the same-named macro |
95 | because some applications (e.g., GNU LilyPond 2.13.9) expect it to be a | |
96 | function. */ | |
97 | #undef scm_is_bool | |
98 | int | |
99 | scm_is_bool (SCM obj) | |
100 | { | |
101 | /* This must match the macro definition of `scm_is_bool ()'. */ | |
d38b431a | 102 | return scm_is_bool_or_nil (obj); |
baedef98 LC |
103 | } |
104 | ||
105 | \f | |
0f2d19dd JB |
106 | void |
107 | scm_init_boolean () | |
0f2d19dd | 108 | { |
a0599745 | 109 | #include "libguile/boolean.x" |
0f2d19dd JB |
110 | } |
111 | ||
89e00824 ML |
112 | |
113 | /* | |
114 | Local Variables: | |
115 | c-file-style: "gnu" | |
116 | End: | |
117 | */ |