boolean.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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
  5. * License as published by the Free Software Foundation; either
  6. * version 2.1 of the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but 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 02110-1301 USA
  16. */
  17. #ifdef HAVE_CONFIG_H
  18. # include <config.h>
  19. #endif
  20. #include "libguile/_scm.h"
  21. #include "libguile/validate.h"
  22. #include "libguile/boolean.h"
  23. #include "libguile/lang.h"
  24. #include "libguile/tags.h"
  25. SCM_DEFINE (scm_not, "not", 1, 0, 0,
  26. (SCM x),
  27. "Return @code{#t} iff @var{x} is @code{#f}, else return @code{#f}.")
  28. #define FUNC_NAME s_scm_not
  29. {
  30. return scm_from_bool (scm_is_false (x) || SCM_NILP (x));
  31. }
  32. #undef FUNC_NAME
  33. SCM_DEFINE (scm_boolean_p, "boolean?", 1, 0, 0,
  34. (SCM obj),
  35. "Return @code{#t} iff @var{obj} is either @code{#t} or @code{#f}.")
  36. #define FUNC_NAME s_scm_boolean_p
  37. {
  38. return scm_from_bool (scm_is_bool (obj) || SCM_NILP (obj));
  39. }
  40. #undef FUNC_NAME
  41. int
  42. scm_is_bool (SCM x)
  43. {
  44. return scm_is_eq (x, SCM_BOOL_F) || scm_is_eq (x, SCM_BOOL_T);
  45. }
  46. int
  47. scm_to_bool (SCM x)
  48. {
  49. if (scm_is_eq (x, SCM_BOOL_F))
  50. return 0;
  51. else if (scm_is_eq (x, SCM_BOOL_T))
  52. return 1;
  53. else
  54. scm_wrong_type_arg (NULL, 0, x);
  55. }
  56. void
  57. scm_init_boolean ()
  58. {
  59. #include "libguile/boolean.x"
  60. }
  61. /*
  62. Local Variables:
  63. c-file-style: "gnu"
  64. End:
  65. */