2003-01-20 10:12:39 +00:00
|
|
|
|
/* Copyright (C) 1998,1999,2000,2001,2002, 2003 Free Software Foundation, Inc.
|
1998-10-31 13:31:25 +00:00
|
|
|
|
*
|
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
|
* any later version.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
|
* along with this software; see the file COPYING. If not, write to
|
|
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
|
|
* Boston, MA 02111-1307 USA
|
|
|
|
|
|
*
|
|
|
|
|
|
* As a special exception, the Free Software Foundation gives permission
|
|
|
|
|
|
* for additional uses of the text contained in its release of GUILE.
|
|
|
|
|
|
*
|
|
|
|
|
|
* The exception is that, if you link the GUILE library with other files
|
|
|
|
|
|
* to produce an executable, this does not by itself cause the
|
|
|
|
|
|
* resulting executable to be covered by the GNU General Public License.
|
|
|
|
|
|
* Your use of that executable is in no way restricted on account of
|
|
|
|
|
|
* linking the GUILE library code into it.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This exception does not however invalidate any other reasons why
|
|
|
|
|
|
* the executable file might be covered by the GNU General Public License.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This exception applies only to the code released by the
|
|
|
|
|
|
* Free Software Foundation under the name GUILE. If you copy
|
|
|
|
|
|
* code from other Free Software Foundation releases into a copy of
|
|
|
|
|
|
* GUILE, as the General Public License permits, the exception does
|
|
|
|
|
|
* not apply to the code that you add in this way. To avoid misleading
|
|
|
|
|
|
* anyone as to the status of such modified files, you must delete
|
|
|
|
|
|
* this exception notice from them.
|
|
|
|
|
|
*
|
|
|
|
|
|
* If you write modifications of your own for GUILE, it is your choice
|
|
|
|
|
|
* whether to permit this exception to apply to your modifications.
|
|
|
|
|
|
* If you do not wish that, delete this exception notice. */
|
1999-12-12 02:36:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "libguile/_scm.h"
|
|
|
|
|
|
#include "libguile/eval.h"
|
|
|
|
|
|
#include "libguile/macros.h"
|
|
|
|
|
|
#include "libguile/modules.h"
|
2000-06-21 02:46:01 +00:00
|
|
|
|
#include "libguile/fluids.h"
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "libguile/validate.h"
|
|
|
|
|
|
#include "libguile/evalext.h"
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
1999-03-11 11:45:34 +00:00
|
|
|
|
SCM_SYMBOL (scm_sym_setter, "setter");
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
2001-06-07 21:12:19 +00:00
|
|
|
|
scm_m_generalized_set_x (SCM xorig, SCM env SCM_UNUSED)
|
1999-03-11 11:45:34 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM x = SCM_CDR (xorig);
|
2001-03-15 09:50:20 +00:00
|
|
|
|
SCM_ASSYNT (2 == scm_ilength (x), scm_s_expression, scm_s_set_x);
|
1999-12-16 20:48:05 +00:00
|
|
|
|
if (SCM_SYMBOLP (SCM_CAR (x)))
|
1999-03-11 11:45:34 +00:00
|
|
|
|
return scm_cons (SCM_IM_SET_X, x);
|
1999-12-16 20:48:05 +00:00
|
|
|
|
else if (SCM_CONSP (SCM_CAR (x)))
|
* list.h (scm_list_1, scm_list_2, scm_list_3, scm_list_4, scm_list_5,
scm_list_n): New functions.
(SCM_LIST0, SCM_LIST1, SCM_LIST2, SCM_LIST3, SCM_LIST4, SCM_LIST5,
SCM_LIST6, SCM_LIST7, SCM_LIST8, SCM_LIST9, scm_listify): Deprecated.
(lots of files): Use the new functions.
* goops.c (CALL_GF1, CALL_GF2, CALL_GF3, CALL_GF4): Use scm_call_N.
* strings.c: #include "libguile/deprecation.h".
2001-06-28 01:11:59 +00:00
|
|
|
|
return scm_cons (scm_list_2 (scm_sym_setter, SCM_CAAR (x)),
|
|
|
|
|
|
scm_append (scm_list_2 (SCM_CDAR (x), SCM_CDR (x))));
|
2001-03-04 17:09:34 +00:00
|
|
|
|
else
|
|
|
|
|
|
scm_misc_error (scm_s_set_x, scm_s_variable, SCM_EOL);
|
1999-03-11 11:45:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2002-10-19 09:07:23 +00:00
|
|
|
|
SCM_DEFINE (scm_defined_p, "defined?", 1, 1, 0,
|
1999-12-12 02:36:16 +00:00
|
|
|
|
(SCM sym, SCM env),
|
2001-05-05 19:03:42 +00:00
|
|
|
|
"Return @code{#t} if @var{sym} is defined in the lexical "
|
2001-05-06 00:02:06 +00:00
|
|
|
|
"environment @var{env}. When @var{env} is not specified, "
|
|
|
|
|
|
"look in the top-level environment as defined by the "
|
2001-05-05 19:03:42 +00:00
|
|
|
|
"current module.")
|
2002-10-19 09:07:23 +00:00
|
|
|
|
#define FUNC_NAME s_scm_defined_p
|
1998-10-31 13:31:25 +00:00
|
|
|
|
{
|
2001-05-15 14:57:22 +00:00
|
|
|
|
SCM var;
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
2002-07-20 14:08:34 +00:00
|
|
|
|
SCM_VALIDATE_SYMBOL (1, sym);
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
1998-11-20 17:14:41 +00:00
|
|
|
|
if (SCM_UNBNDP (env))
|
2001-05-15 14:57:22 +00:00
|
|
|
|
var = scm_sym2var (sym, scm_current_module_lookup_closure (),
|
|
|
|
|
|
SCM_BOOL_F);
|
1998-11-20 17:14:41 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM frames = env;
|
|
|
|
|
|
register SCM b;
|
|
|
|
|
|
for (; SCM_NIMP (frames); frames = SCM_CDR (frames))
|
|
|
|
|
|
{
|
1999-12-12 02:36:16 +00:00
|
|
|
|
SCM_ASSERT (SCM_CONSP (frames), env, SCM_ARG2, FUNC_NAME);
|
1998-11-20 17:14:41 +00:00
|
|
|
|
b = SCM_CAR (frames);
|
|
|
|
|
|
if (SCM_NFALSEP (scm_procedure_p (b)))
|
|
|
|
|
|
break;
|
2000-01-12 01:51:18 +00:00
|
|
|
|
SCM_ASSERT (SCM_CONSP (b), env, SCM_ARG2, FUNC_NAME);
|
1998-11-20 17:14:41 +00:00
|
|
|
|
for (b = SCM_CAR (b); SCM_NIMP (b); b = SCM_CDR (b))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SCM_NCONSP (b))
|
|
|
|
|
|
{
|
2000-04-03 08:47:51 +00:00
|
|
|
|
if (SCM_EQ_P (b, sym))
|
1998-11-20 17:14:41 +00:00
|
|
|
|
return SCM_BOOL_T;
|
|
|
|
|
|
else
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2000-04-03 08:47:51 +00:00
|
|
|
|
if (SCM_EQ_P (SCM_CAR (b), sym))
|
1998-11-20 17:14:41 +00:00
|
|
|
|
return SCM_BOOL_T;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2001-05-15 14:57:22 +00:00
|
|
|
|
var = scm_sym2var (sym,
|
|
|
|
|
|
SCM_NIMP (frames) ? SCM_CAR (frames) : SCM_BOOL_F,
|
|
|
|
|
|
SCM_BOOL_F);
|
1998-11-20 17:14:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-05-15 14:57:22 +00:00
|
|
|
|
return (SCM_FALSEP (var) || SCM_UNBNDP (SCM_VARIABLE_REF (var))
|
1998-11-20 17:14:41 +00:00
|
|
|
|
? SCM_BOOL_F
|
|
|
|
|
|
: SCM_BOOL_T);
|
1998-10-31 13:31:25 +00:00
|
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#undef FUNC_NAME
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
2002-11-24 18:21:48 +00:00
|
|
|
|
#if (SCM_ENABLE_DEPRECATED == 1)
|
1998-12-14 15:19:59 +00:00
|
|
|
|
|
|
|
|
|
|
SCM_SYNTAX (s_undefine, "undefine", scm_makacro, scm_m_undefine);
|
1998-10-31 13:31:25 +00:00
|
|
|
|
|
|
|
|
|
|
SCM
|
1999-12-12 20:35:02 +00:00
|
|
|
|
scm_m_undefine (SCM x, SCM env)
|
1998-10-31 13:31:25 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM arg1 = x;
|
|
|
|
|
|
x = SCM_CDR (x);
|
2001-03-15 09:50:20 +00:00
|
|
|
|
SCM_ASSYNT (SCM_TOP_LEVEL (env), "bad placement ", s_undefine);
|
2000-04-03 08:47:51 +00:00
|
|
|
|
SCM_ASSYNT (SCM_CONSP (x) && SCM_NULLP (SCM_CDR (x)),
|
2001-03-15 09:50:20 +00:00
|
|
|
|
scm_s_expression, s_undefine);
|
1998-10-31 13:31:25 +00:00
|
|
|
|
x = SCM_CAR (x);
|
2001-03-15 09:50:20 +00:00
|
|
|
|
SCM_ASSYNT (SCM_SYMBOLP (x), scm_s_variable, s_undefine);
|
2001-05-15 14:57:22 +00:00
|
|
|
|
arg1 = scm_sym2var (x, scm_env_top_level (env), SCM_BOOL_F);
|
|
|
|
|
|
SCM_ASSYNT (SCM_NFALSEP (arg1) && !SCM_UNBNDP (SCM_VARIABLE_REF (arg1)),
|
2001-03-15 09:50:20 +00:00
|
|
|
|
"variable already unbound ", s_undefine);
|
2001-05-15 14:57:22 +00:00
|
|
|
|
SCM_VARIABLE_SET (arg1, SCM_UNDEFINED);
|
1998-10-31 13:31:25 +00:00
|
|
|
|
#ifdef SICP
|
2001-05-15 14:57:22 +00:00
|
|
|
|
return x;
|
1998-10-31 13:31:25 +00:00
|
|
|
|
#else
|
|
|
|
|
|
return SCM_UNSPECIFIED;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-11-24 18:21:48 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
1999-12-12 02:36:16 +00:00
|
|
|
|
SCM_REGISTER_PROC (s_map_in_order, "map-in-order", 2, 0, 1, scm_map);
|
1998-12-07 16:48:35 +00:00
|
|
|
|
|
2003-01-20 10:12:39 +00:00
|
|
|
|
SCM_DEFINE (scm_self_evaluating_p, "self-evaluating?", 1, 0, 0,
|
|
|
|
|
|
(SCM obj),
|
|
|
|
|
|
"Return #t for objects which Guile considers self-evaluating")
|
|
|
|
|
|
#define FUNC_NAME s_scm_self_evaluating_p
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (SCM_ITAG3 (obj))
|
|
|
|
|
|
{
|
|
|
|
|
|
case scm_tc3_int_1:
|
|
|
|
|
|
case scm_tc3_int_2:
|
|
|
|
|
|
/* inum */
|
|
|
|
|
|
return SCM_BOOL_T;
|
|
|
|
|
|
case scm_tc3_imm24:
|
|
|
|
|
|
/* characters, booleans, other immediates */
|
|
|
|
|
|
return SCM_BOOL (!SCM_NULLP (obj));
|
|
|
|
|
|
case scm_tc3_cons:
|
|
|
|
|
|
switch (SCM_TYP7 (obj))
|
|
|
|
|
|
{
|
|
|
|
|
|
case scm_tcs_closures:
|
|
|
|
|
|
case scm_tc7_vector:
|
|
|
|
|
|
case scm_tc7_wvect:
|
2003-03-25 23:54:35 +00:00
|
|
|
|
#ifdef SCM_HAVE_ARRAYS
|
2003-01-20 10:12:39 +00:00
|
|
|
|
case scm_tc7_bvect:
|
|
|
|
|
|
case scm_tc7_byvect:
|
|
|
|
|
|
case scm_tc7_svect:
|
|
|
|
|
|
case scm_tc7_ivect:
|
|
|
|
|
|
case scm_tc7_uvect:
|
|
|
|
|
|
case scm_tc7_fvect:
|
|
|
|
|
|
case scm_tc7_dvect:
|
|
|
|
|
|
case scm_tc7_cvect:
|
2003-03-25 23:54:35 +00:00
|
|
|
|
#if SCM_SIZEOF_LONG_LONG != 0
|
2003-01-20 10:12:39 +00:00
|
|
|
|
case scm_tc7_llvect:
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#endif
|
|
|
|
|
|
case scm_tc7_string:
|
|
|
|
|
|
case scm_tc7_smob:
|
|
|
|
|
|
case scm_tc7_cclo:
|
|
|
|
|
|
case scm_tc7_pws:
|
|
|
|
|
|
case scm_tcs_subrs:
|
|
|
|
|
|
case scm_tcs_struct:
|
|
|
|
|
|
return SCM_BOOL_T;
|
|
|
|
|
|
default:
|
|
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
SCM_MISC_ERROR ("Internal error: Object ~S has unknown type",
|
|
|
|
|
|
scm_list_1 (obj));
|
|
|
|
|
|
return SCM_UNSPECIFIED; /* never reached */
|
|
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
1998-10-31 13:31:25 +00:00
|
|
|
|
void
|
|
|
|
|
|
scm_init_evalext ()
|
|
|
|
|
|
{
|
1999-03-11 11:45:34 +00:00
|
|
|
|
scm_make_synt (scm_s_set_x, scm_makmmacro, scm_m_generalized_set_x);
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "libguile/evalext.x"
|
1998-10-31 13:31:25 +00:00
|
|
|
|
}
|
2000-03-19 19:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
|
End:
|
|
|
|
|
|
*/
|