Change Guile license to LGPLv3+
[bpt/guile.git] / libguile / boolean.c
1 /* Copyright (C) 1995, 1996, 2000, 2001, 2006, 2008 Free Software Foundation, Inc.
2 *
3 * This library is free software; you can redistribute it and/or
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.
7 *
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
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
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
17 */
18
19
20 \f
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include "libguile/_scm.h"
26
27 #include "libguile/validate.h"
28 #include "libguile/boolean.h"
29 #include "libguile/lang.h"
30 #include "libguile/tags.h"
31
32 \f
33
34
35 SCM_DEFINE (scm_not, "not", 1, 0, 0,
36 (SCM x),
37 "Return @code{#t} iff @var{x} is @code{#f}, else return @code{#f}.")
38 #define FUNC_NAME s_scm_not
39 {
40 return scm_from_bool (scm_is_false (x) || SCM_NILP (x));
41 }
42 #undef FUNC_NAME
43
44
45 SCM_DEFINE (scm_boolean_p, "boolean?", 1, 0, 0,
46 (SCM obj),
47 "Return @code{#t} iff @var{obj} is either @code{#t} or @code{#f}.")
48 #define FUNC_NAME s_scm_boolean_p
49 {
50 return scm_from_bool (scm_is_bool (obj) || SCM_NILP (obj));
51 }
52 #undef FUNC_NAME
53
54 int
55 scm_is_bool (SCM x)
56 {
57 return scm_is_eq (x, SCM_BOOL_F) || scm_is_eq (x, SCM_BOOL_T);
58 }
59
60 int
61 scm_to_bool (SCM x)
62 {
63 if (scm_is_eq (x, SCM_BOOL_F))
64 return 0;
65 else if (scm_is_eq (x, SCM_BOOL_T))
66 return 1;
67 else
68 scm_wrong_type_arg (NULL, 0, x);
69 }
70
71 void
72 scm_init_boolean ()
73 {
74 #include "libguile/boolean.x"
75 }
76
77
78 /*
79 Local Variables:
80 c-file-style: "gnu"
81 End:
82 */