* Removed lots of deprecated stuff.
[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{
8c494e99
DH
71 SCM z;
72 SCM_NEWCELL (z);
73 SCM_SET_CELL_WORD_1 (z, SCM_UNPACK (init));
74 SCM_SET_CELL_TYPE (z, scm_tc7_variable);
75 scm_remember_upto_here_1 (init);
76 return z;
0f2d19dd
JB
77}
78
86d31dfe
MV
79SCM_DEFINE (scm_make_variable, "make-variable", 1, 0, 0,
80 (SCM init),
81 "Return a variable initialized to value @var{init}.\n")
1bbd0b84 82#define FUNC_NAME s_scm_make_variable
0f2d19dd 83{
86d31dfe 84 return make_variable (init);
0f2d19dd 85}
1bbd0b84 86#undef FUNC_NAME
0f2d19dd
JB
87
88
86d31dfe
MV
89SCM_DEFINE (scm_make_undefined_variable, "make-undefined-variable", 0, 0, 0,
90 (),
91 "Return a variable that is initially unbound.\n")
1bbd0b84 92#define FUNC_NAME s_scm_make_undefined_variable
0f2d19dd 93{
86d31dfe 94 return make_variable (SCM_UNDEFINED);
0f2d19dd 95}
1bbd0b84 96#undef FUNC_NAME
0f2d19dd
JB
97
98
3b3b36dd 99SCM_DEFINE (scm_variable_p, "variable?", 1, 0, 0,
d727c64b 100 (SCM obj),
03ba3d5b
MG
101 "Return @code{#t} iff @var{obj} is a variable object, else\n"
102 "return @code{#f}\n")
1bbd0b84 103#define FUNC_NAME s_scm_variable_p
0f2d19dd 104{
4fd1f652 105 return SCM_BOOL (SCM_VARIABLEP (obj));
0f2d19dd 106}
1bbd0b84 107#undef FUNC_NAME
0f2d19dd
JB
108
109
3b3b36dd 110SCM_DEFINE (scm_variable_ref, "variable-ref", 1, 0, 0,
d727c64b 111 (SCM var),
03ba3d5b
MG
112 "Dereference @var{var} and return its value.\n"
113 "@var{var} must be a variable object; see @code{make-variable}\n"
114 "and @code{make-undefined-variable}.")
1bbd0b84 115#define FUNC_NAME s_scm_variable_ref
0f2d19dd 116{
86d31dfe 117 SCM val;
4fd1f652 118 SCM_VALIDATE_VARIABLE (1, var);
86d31dfe
MV
119 val = SCM_VARIABLE_REF (var);
120 if (val == SCM_UNDEFINED)
1afff620 121 SCM_MISC_ERROR ("variable is unbound: ~S", scm_list_1 (var));
86d31dfe 122 return val;
0f2d19dd 123}
1bbd0b84 124#undef FUNC_NAME
0f2d19dd 125
3b3b36dd 126SCM_DEFINE (scm_variable_set_x, "variable-set!", 2, 0, 0,
d727c64b 127 (SCM var, SCM val),
03ba3d5b
MG
128 "Set the value of the variable @var{var} to @var{val}.\n"
129 "@var{var} must be a variable object, @var{val} can be any\n"
130 "value. Return an unspecified value.\n")
1bbd0b84 131#define FUNC_NAME s_scm_variable_set_x
0f2d19dd 132{
22a52da1 133 SCM_VALIDATE_VARIABLE (1, var);
86d31dfe 134 SCM_VARIABLE_SET (var, val);
0f2d19dd
JB
135 return SCM_UNSPECIFIED;
136}
1bbd0b84 137#undef FUNC_NAME
0f2d19dd 138
3b3b36dd 139SCM_DEFINE (scm_variable_bound_p, "variable-bound?", 1, 0, 0,
d727c64b 140 (SCM var),
03ba3d5b
MG
141 "Return @code{#t} iff @var{var} is bound to a value.\n"
142 "Throws an error if @var{var} is not a variable object.\n")
1bbd0b84 143#define FUNC_NAME s_scm_variable_bound_p
0f2d19dd 144{
22a52da1 145 SCM_VALIDATE_VARIABLE (1, var);
86d31dfe 146 return SCM_BOOL (SCM_VARIABLE_REF (var) != SCM_UNDEFINED);
0f2d19dd 147}
1bbd0b84 148#undef FUNC_NAME
0f2d19dd 149
1cc91f1b 150
0f2d19dd
JB
151void
152scm_init_variable ()
0f2d19dd 153{
8dc9439f 154#ifndef SCM_MAGIC_SNARFER
a0599745 155#include "libguile/variable.x"
8dc9439f 156#endif
0f2d19dd
JB
157}
158
89e00824
ML
159/*
160 Local Variables:
161 c-file-style: "gnu"
162 End:
163*/