*** empty log message ***
[bpt/guile.git] / libguile / variable.c
CommitLineData
22a52da1 1/* Copyright (C) 1995,1996,1997,1998,2000,2001 Free Software Foundation, Inc.
0f2d19dd
JB
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program 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
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
82892bed
JB
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
0f2d19dd
JB
17 *
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
20 *
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
37 *
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
82892bed 40 * If you do not wish that, delete this exception notice. */
1bbd0b84 41
1bbd0b84 42
0f2d19dd
JB
43\f
44
a0599745
MD
45#include "libguile/_scm.h"
46#include "libguile/eq.h"
47#include "libguile/ports.h"
48#include "libguile/root.h"
49#include "libguile/smob.h"
86d31dfe 50#include "libguile/deprecation.h"
a0599745
MD
51
52#include "libguile/validate.h"
53#include "libguile/variable.h"
0f2d19dd 54\f
1cc91f1b 55
dbf5dfb3
MV
56void
57scm_i_variable_print (SCM exp, SCM port, scm_print_state *pstate)
0f2d19dd 58{
b7f3516f 59 scm_puts ("#<variable ", port);
22a52da1 60 scm_intprint (SCM_UNPACK (exp), 16, port);
2b1d120c 61 scm_puts (" value: ", port);
86d31dfe 62 scm_iprin1 (SCM_VARIABLE_REF (exp), port, pstate);
b7f3516f 63 scm_putc('>', port);
0f2d19dd
JB
64}
65
0f2d19dd
JB
66\f
67
0f2d19dd 68static SCM
86d31dfe 69make_variable (SCM init)
0f2d19dd 70{
228a24ef 71 return scm_cell (scm_tc7_variable, SCM_UNPACK (init));
0f2d19dd
JB
72}
73
86d31dfe
MV
74SCM_DEFINE (scm_make_variable, "make-variable", 1, 0, 0,
75 (SCM init),
9401323e 76 "Return a variable initialized to value @var{init}.")
1bbd0b84 77#define FUNC_NAME s_scm_make_variable
0f2d19dd 78{
86d31dfe 79 return make_variable (init);
0f2d19dd 80}
1bbd0b84 81#undef FUNC_NAME
0f2d19dd
JB
82
83
86d31dfe
MV
84SCM_DEFINE (scm_make_undefined_variable, "make-undefined-variable", 0, 0, 0,
85 (),
9401323e 86 "Return a variable that is initially unbound.")
1bbd0b84 87#define FUNC_NAME s_scm_make_undefined_variable
0f2d19dd 88{
86d31dfe 89 return make_variable (SCM_UNDEFINED);
0f2d19dd 90}
1bbd0b84 91#undef FUNC_NAME
0f2d19dd
JB
92
93
3b3b36dd 94SCM_DEFINE (scm_variable_p, "variable?", 1, 0, 0,
d727c64b 95 (SCM obj),
03ba3d5b 96 "Return @code{#t} iff @var{obj} is a variable object, else\n"
9401323e 97 "return @code{#f}.")
1bbd0b84 98#define FUNC_NAME s_scm_variable_p
0f2d19dd 99{
4fd1f652 100 return SCM_BOOL (SCM_VARIABLEP (obj));
0f2d19dd 101}
1bbd0b84 102#undef FUNC_NAME
0f2d19dd
JB
103
104
3b3b36dd 105SCM_DEFINE (scm_variable_ref, "variable-ref", 1, 0, 0,
d727c64b 106 (SCM var),
03ba3d5b
MG
107 "Dereference @var{var} and return its value.\n"
108 "@var{var} must be a variable object; see @code{make-variable}\n"
109 "and @code{make-undefined-variable}.")
1bbd0b84 110#define FUNC_NAME s_scm_variable_ref
0f2d19dd 111{
86d31dfe 112 SCM val;
4fd1f652 113 SCM_VALIDATE_VARIABLE (1, var);
86d31dfe
MV
114 val = SCM_VARIABLE_REF (var);
115 if (val == SCM_UNDEFINED)
1afff620 116 SCM_MISC_ERROR ("variable is unbound: ~S", scm_list_1 (var));
86d31dfe 117 return val;
0f2d19dd 118}
1bbd0b84 119#undef FUNC_NAME
0f2d19dd 120
3b3b36dd 121SCM_DEFINE (scm_variable_set_x, "variable-set!", 2, 0, 0,
d727c64b 122 (SCM var, SCM val),
03ba3d5b
MG
123 "Set the value of the variable @var{var} to @var{val}.\n"
124 "@var{var} must be a variable object, @var{val} can be any\n"
9401323e 125 "value. Return an unspecified value.")
1bbd0b84 126#define FUNC_NAME s_scm_variable_set_x
0f2d19dd 127{
22a52da1 128 SCM_VALIDATE_VARIABLE (1, var);
86d31dfe 129 SCM_VARIABLE_SET (var, val);
0f2d19dd
JB
130 return SCM_UNSPECIFIED;
131}
1bbd0b84 132#undef FUNC_NAME
0f2d19dd 133
3b3b36dd 134SCM_DEFINE (scm_variable_bound_p, "variable-bound?", 1, 0, 0,
d727c64b 135 (SCM var),
03ba3d5b 136 "Return @code{#t} iff @var{var} is bound to a value.\n"
9401323e 137 "Throws an error if @var{var} is not a variable object.")
1bbd0b84 138#define FUNC_NAME s_scm_variable_bound_p
0f2d19dd 139{
22a52da1 140 SCM_VALIDATE_VARIABLE (1, var);
86d31dfe 141 return SCM_BOOL (SCM_VARIABLE_REF (var) != SCM_UNDEFINED);
0f2d19dd 142}
1bbd0b84 143#undef FUNC_NAME
0f2d19dd 144
1cc91f1b 145
0f2d19dd
JB
146void
147scm_init_variable ()
0f2d19dd 148{
a0599745 149#include "libguile/variable.x"
0f2d19dd
JB
150}
151
89e00824
ML
152/*
153 Local Variables:
154 c-file-style: "gnu"
155 End:
156*/