1
/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2006 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
21
#include "libguile/_scm.h"
22
#include "libguile/eq.h"
23
#include "libguile/ports.h"
24
#include "libguile/root.h"
25
#include "libguile/smob.h"
26
#include "libguile/deprecation.h"
28
#include "libguile/validate.h"
29
#include "libguile/variable.h"
33
scm_i_variable_print (SCM exp, SCM port, scm_print_state *pstate)
35
scm_puts ("#<variable ", port);
36
scm_uintprint (SCM_UNPACK (exp), 16, port);
37
scm_puts (" value: ", port);
38
scm_iprin1 (SCM_VARIABLE_REF (exp), port, pstate);
45
make_variable (SCM init)
47
return scm_cell (scm_tc7_variable, SCM_UNPACK (init));
50
SCM_DEFINE (scm_make_variable, "make-variable", 1, 0, 0,
52
"Return a variable initialized to value @var{init}.")
53
#define FUNC_NAME s_scm_make_variable
55
return make_variable (init);
60
SCM_DEFINE (scm_make_undefined_variable, "make-undefined-variable", 0, 0, 0,
62
"Return a variable that is initially unbound.")
63
#define FUNC_NAME s_scm_make_undefined_variable
65
return make_variable (SCM_UNDEFINED);
70
SCM_DEFINE (scm_variable_p, "variable?", 1, 0, 0,
72
"Return @code{#t} iff @var{obj} is a variable object, else\n"
74
#define FUNC_NAME s_scm_variable_p
76
return scm_from_bool (SCM_VARIABLEP (obj));
81
SCM_DEFINE (scm_variable_ref, "variable-ref", 1, 0, 0,
83
"Dereference @var{var} and return its value.\n"
84
"@var{var} must be a variable object; see @code{make-variable}\n"
85
"and @code{make-undefined-variable}.")
86
#define FUNC_NAME s_scm_variable_ref
89
SCM_VALIDATE_VARIABLE (1, var);
90
val = SCM_VARIABLE_REF (var);
91
if (val == SCM_UNDEFINED)
92
SCM_MISC_ERROR ("variable is unbound: ~S", scm_list_1 (var));
97
SCM_DEFINE (scm_variable_set_x, "variable-set!", 2, 0, 0,
99
"Set the value of the variable @var{var} to @var{val}.\n"
100
"@var{var} must be a variable object, @var{val} can be any\n"
101
"value. Return an unspecified value.")
102
#define FUNC_NAME s_scm_variable_set_x
104
SCM_VALIDATE_VARIABLE (1, var);
105
SCM_VARIABLE_SET (var, val);
106
return SCM_UNSPECIFIED;
110
SCM_DEFINE (scm_variable_bound_p, "variable-bound?", 1, 0, 0,
112
"Return @code{#t} iff @var{var} is bound to a value.\n"
113
"Throws an error if @var{var} is not a variable object.")
114
#define FUNC_NAME s_scm_variable_bound_p
116
SCM_VALIDATE_VARIABLE (1, var);
117
return scm_from_bool (SCM_VARIABLE_REF (var) != SCM_UNDEFINED);
125
#include "libguile/variable.x"