boolean.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #include "libguile/_scm.h"
  22. #include "libguile/validate.h"
  23. #include "libguile/boolean.h"
  24. #include "libguile/lang.h"
  25. #include "libguile/tags.h"
  26. SCM_DEFINE (scm_not, "not", 1, 0, 0,
  27. (SCM x),
  28. "Return @code{#t} iff @var{x} is @code{#f}, else return @code{#f}.")
  29. #define FUNC_NAME s_scm_not
  30. {
  31. return scm_from_bool (scm_is_false (x) || SCM_NILP (x));
  32. }
  33. #undef FUNC_NAME
  34. SCM_DEFINE (scm_boolean_p, "boolean?", 1, 0, 0,
  35. (SCM obj),
  36. "Return @code{#t} iff @var{obj} is either @code{#t} or @code{#f}.")
  37. #define FUNC_NAME s_scm_boolean_p
  38. {
  39. return scm_from_bool (scm_is_bool (obj) || SCM_NILP (obj));
  40. }
  41. #undef FUNC_NAME
  42. int
  43. scm_is_bool (SCM x)
  44. {
  45. return scm_is_eq (x, SCM_BOOL_F) || scm_is_eq (x, SCM_BOOL_T);
  46. }
  47. int
  48. scm_to_bool (SCM x)
  49. {
  50. if (scm_is_eq (x, SCM_BOOL_F))
  51. return 0;
  52. else if (scm_is_eq (x, SCM_BOOL_T))
  53. return 1;
  54. else
  55. scm_wrong_type_arg (NULL, 0, x);
  56. }
  57. void
  58. scm_init_boolean ()
  59. {
  60. #include "libguile/boolean.x"
  61. }
  62. /*
  63. Local Variables:
  64. c-file-style: "gnu"
  65. End:
  66. */