Make scm_charprint and scm_i_string_wide_chars SCM_INTERNAL.
[bpt/guile.git] / libguile / evalext.c
CommitLineData
e20d7001 1/* Copyright (C) 1998,1999,2000,2001,2002,2003, 2006, 2008, 2009 Free Software Foundation, Inc.
40cf7e92 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.
40cf7e92 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.
40cf7e92 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
40cf7e92 20\f
dbb605f5
LC
21#ifdef HAVE_CONFIG_H
22# include <config.h>
23#endif
40cf7e92 24
a0599745
MD
25#include "libguile/_scm.h"
26#include "libguile/eval.h"
7e73eaee 27#include "libguile/fluids.h"
f58c472a 28#include "libguile/modules.h"
40cf7e92 29
a0599745
MD
30#include "libguile/validate.h"
31#include "libguile/evalext.h"
40cf7e92 32
5ec1d2c8 33SCM_DEFINE (scm_defined_p, "defined?", 1, 1, 0,
1bbd0b84 34 (SCM sym, SCM env),
67dc6a4e 35 "Return @code{#t} if @var{sym} is defined in the lexical "
826e91f3
MV
36 "environment @var{env}. When @var{env} is not specified, "
37 "look in the top-level environment as defined by the "
67dc6a4e 38 "current module.")
5ec1d2c8 39#define FUNC_NAME s_scm_defined_p
40cf7e92 40{
86d31dfe 41 SCM var;
40cf7e92 42
34d19ef6 43 SCM_VALIDATE_SYMBOL (1, sym);
40cf7e92 44
b325a6c8 45 if (SCM_UNBNDP (env))
86d31dfe
MV
46 var = scm_sym2var (sym, scm_current_module_lookup_closure (),
47 SCM_BOOL_F);
b325a6c8
MD
48 else
49 {
50 SCM frames = env;
51 register SCM b;
52 for (; SCM_NIMP (frames); frames = SCM_CDR (frames))
53 {
d2e53ed6 54 SCM_ASSERT (scm_is_pair (frames), env, SCM_ARG2, FUNC_NAME);
b325a6c8 55 b = SCM_CAR (frames);
7888309b 56 if (scm_is_true (scm_procedure_p (b)))
b325a6c8 57 break;
d2e53ed6 58 SCM_ASSERT (scm_is_pair (b), env, SCM_ARG2, FUNC_NAME);
b325a6c8
MD
59 for (b = SCM_CAR (b); SCM_NIMP (b); b = SCM_CDR (b))
60 {
d2e53ed6 61 if (!scm_is_pair (b))
b325a6c8 62 {
bc36d050 63 if (scm_is_eq (b, sym))
b325a6c8
MD
64 return SCM_BOOL_T;
65 else
66 break;
67 }
bc36d050 68 if (scm_is_eq (SCM_CAR (b), sym))
b325a6c8
MD
69 return SCM_BOOL_T;
70 }
71 }
86d31dfe
MV
72 var = scm_sym2var (sym,
73 SCM_NIMP (frames) ? SCM_CAR (frames) : SCM_BOOL_F,
74 SCM_BOOL_F);
b325a6c8
MD
75 }
76
7888309b 77 return (scm_is_false (var) || SCM_UNBNDP (SCM_VARIABLE_REF (var))
b325a6c8
MD
78 ? SCM_BOOL_F
79 : SCM_BOOL_T);
40cf7e92 80}
1bbd0b84 81#undef FUNC_NAME
40cf7e92 82
63dd3413 83
1bbd0b84 84SCM_REGISTER_PROC (s_map_in_order, "map-in-order", 2, 0, 1, scm_map);
285302e1 85
f58c472a 86
93f26b7b
MD
87SCM_DEFINE (scm_self_evaluating_p, "self-evaluating?", 1, 0, 0,
88 (SCM obj),
89 "Return #t for objects which Guile considers self-evaluating")
90#define FUNC_NAME s_scm_self_evaluating_p
91{
92 switch (SCM_ITAG3 (obj))
93 {
94 case scm_tc3_int_1:
95 case scm_tc3_int_2:
96 /* inum */
97 return SCM_BOOL_T;
98 case scm_tc3_imm24:
99 /* characters, booleans, other immediates */
d2e53ed6 100 return scm_from_bool (!scm_is_null (obj));
93f26b7b
MD
101 case scm_tc3_cons:
102 switch (SCM_TYP7 (obj))
103 {
104 case scm_tcs_closures:
105 case scm_tc7_vector:
106 case scm_tc7_wvect:
534c55a9 107 case scm_tc7_number:
93f26b7b
MD
108 case scm_tc7_string:
109 case scm_tc7_smob:
93f26b7b
MD
110 case scm_tc7_pws:
111 case scm_tcs_subrs:
112 case scm_tcs_struct:
113 return SCM_BOOL_T;
114 default:
115 return SCM_BOOL_F;
116 }
117 }
118 SCM_MISC_ERROR ("Internal error: Object ~S has unknown type",
119 scm_list_1 (obj));
120 return SCM_UNSPECIFIED; /* never reached */
121}
122#undef FUNC_NAME
123
40cf7e92
MD
124void
125scm_init_evalext ()
126{
a0599745 127#include "libguile/evalext.x"
40cf7e92 128}
89e00824
ML
129
130/*
131 Local Variables:
132 c-file-style: "gnu"
133 End:
134*/