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