1 /* Copyright (C) 1995,1996,1997,1998,2000,2001, 2006, 2008 Free Software Foundation, Inc.
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.
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.
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
24 #include "libguile/_scm.h"
25 #include "libguile/eq.h"
26 #include "libguile/ports.h"
27 #include "libguile/root.h"
28 #include "libguile/smob.h"
29 #include "libguile/deprecation.h"
31 #include "libguile/validate.h"
32 #include "libguile/variable.h"
36 scm_i_variable_print (SCM exp
, SCM port
, scm_print_state
*pstate
)
38 scm_puts ("#<variable ", port
);
39 scm_uintprint (SCM_UNPACK (exp
), 16, port
);
40 scm_puts (" value: ", port
);
41 scm_iprin1 (SCM_VARIABLE_REF (exp
), port
, pstate
);
48 make_variable (SCM init
)
50 return scm_cell (scm_tc7_variable
, SCM_UNPACK (init
));
53 SCM_DEFINE (scm_make_variable
, "make-variable", 1, 0, 0,
55 "Return a variable initialized to value @var{init}.")
56 #define FUNC_NAME s_scm_make_variable
58 return make_variable (init
);
63 SCM_DEFINE (scm_make_undefined_variable
, "make-undefined-variable", 0, 0, 0,
65 "Return a variable that is initially unbound.")
66 #define FUNC_NAME s_scm_make_undefined_variable
68 return make_variable (SCM_UNDEFINED
);
73 SCM_DEFINE (scm_variable_p
, "variable?", 1, 0, 0,
75 "Return @code{#t} iff @var{obj} is a variable object, else\n"
77 #define FUNC_NAME s_scm_variable_p
79 return scm_from_bool (SCM_VARIABLEP (obj
));
84 SCM_DEFINE (scm_variable_ref
, "variable-ref", 1, 0, 0,
86 "Dereference @var{var} and return its value.\n"
87 "@var{var} must be a variable object; see @code{make-variable}\n"
88 "and @code{make-undefined-variable}.")
89 #define FUNC_NAME s_scm_variable_ref
92 SCM_VALIDATE_VARIABLE (1, var
);
93 val
= SCM_VARIABLE_REF (var
);
94 if (val
== SCM_UNDEFINED
)
95 SCM_MISC_ERROR ("variable is unbound: ~S", scm_list_1 (var
));
100 SCM_DEFINE (scm_variable_set_x
, "variable-set!", 2, 0, 0,
102 "Set the value of the variable @var{var} to @var{val}.\n"
103 "@var{var} must be a variable object, @var{val} can be any\n"
104 "value. Return an unspecified value.")
105 #define FUNC_NAME s_scm_variable_set_x
107 SCM_VALIDATE_VARIABLE (1, var
);
108 SCM_VARIABLE_SET (var
, val
);
109 return SCM_UNSPECIFIED
;
113 SCM_DEFINE (scm_variable_bound_p
, "variable-bound?", 1, 0, 0,
115 "Return @code{#t} iff @var{var} is bound to a value.\n"
116 "Throws an error if @var{var} is not a variable object.")
117 #define FUNC_NAME s_scm_variable_bound_p
119 SCM_VALIDATE_VARIABLE (1, var
);
120 return scm_from_bool (SCM_VARIABLE_REF (var
) != SCM_UNDEFINED
);
128 #include "libguile/variable.x"