evalext.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Copyright (C) 1998,1999,2000,2001,2002,2003, 2006, 2008, 2009 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/eval.h"
  23. #include "libguile/fluids.h"
  24. #include "libguile/modules.h"
  25. #include "libguile/validate.h"
  26. #include "libguile/evalext.h"
  27. SCM_DEFINE (scm_defined_p, "defined?", 1, 1, 0,
  28. (SCM sym, SCM module),
  29. "Return @code{#t} if @var{sym} is defined in the module "
  30. "@var{module} or the current module when @var{module} is not"
  31. "specified.")
  32. #define FUNC_NAME s_scm_defined_p
  33. {
  34. SCM var;
  35. SCM_VALIDATE_SYMBOL (1, sym);
  36. if (SCM_UNBNDP (module))
  37. module = scm_current_module ();
  38. else
  39. SCM_VALIDATE_MODULE (2, module);
  40. var = scm_module_variable (module, sym);
  41. return (scm_is_false (var) || SCM_UNBNDP (SCM_VARIABLE_REF (var))
  42. ? SCM_BOOL_F
  43. : SCM_BOOL_T);
  44. }
  45. #undef FUNC_NAME
  46. SCM_REGISTER_PROC (s_map_in_order, "map-in-order", 2, 0, 1, scm_map);
  47. SCM_DEFINE (scm_self_evaluating_p, "self-evaluating?", 1, 0, 0,
  48. (SCM obj),
  49. "Return #t for objects which Guile considers self-evaluating")
  50. #define FUNC_NAME s_scm_self_evaluating_p
  51. {
  52. switch (SCM_ITAG3 (obj))
  53. {
  54. case scm_tc3_int_1:
  55. case scm_tc3_int_2:
  56. /* inum */
  57. return SCM_BOOL_T;
  58. case scm_tc3_imm24:
  59. /* characters, booleans, other immediates */
  60. return scm_from_bool (!scm_is_null (obj));
  61. case scm_tc3_cons:
  62. switch (SCM_TYP7 (obj))
  63. {
  64. case scm_tcs_closures:
  65. case scm_tc7_vector:
  66. case scm_tc7_wvect:
  67. case scm_tc7_number:
  68. case scm_tc7_string:
  69. case scm_tc7_smob:
  70. case scm_tc7_pws:
  71. case scm_tcs_subrs:
  72. case scm_tcs_struct:
  73. return SCM_BOOL_T;
  74. default:
  75. return SCM_BOOL_F;
  76. }
  77. }
  78. SCM_MISC_ERROR ("Internal error: Object ~S has unknown type",
  79. scm_list_1 (obj));
  80. return SCM_UNSPECIFIED; /* never reached */
  81. }
  82. #undef FUNC_NAME
  83. void
  84. scm_init_evalext ()
  85. {
  86. #include "libguile/evalext.x"
  87. }
  88. /*
  89. Local Variables:
  90. c-file-style: "gnu"
  91. End:
  92. */