*** empty log message ***
[bpt/guile.git] / libguile / deprecated.c
1 /* This file contains definitions for deprecated features. When you
2 deprecate something, move it here when that is feasible.
3 */
4
5 /* Copyright (C) 2003 Free Software Foundation, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #include "libguile/_scm.h"
23 #include "libguile/deprecated.h"
24 #include "libguile/deprecation.h"
25 #include "libguile/snarf.h"
26 #include "libguile/validate.h"
27 #include "libguile/strings.h"
28 #include "libguile/strop.h"
29 #include "libguile/modules.h"
30 #include "libguile/eval.h"
31 #include "libguile/smob.h"
32 #include "libguile/procprop.h"
33 #include "libguile/vectors.h"
34 #include "libguile/hashtab.h"
35 #include "libguile/struct.h"
36 #include "libguile/variable.h"
37 #include "libguile/fluids.h"
38 #include "libguile/ports.h"
39 #include "libguile/eq.h"
40 #include "libguile/read.h"
41 #include "libguile/strports.h"
42 #include "libguile/smob.h"
43 #include "libguile/alist.h"
44
45 #include <stdio.h>
46 #include <string.h>
47
48 #if (SCM_ENABLE_DEPRECATED == 1)
49
50 /* From eval.c: Error messages of the evaluator. These were deprecated in
51 * guile 1.7.0 on 2003-06-02. */
52 const char scm_s_expression[] = "missing or extra expression";
53 const char scm_s_test[] = "bad test";
54 const char scm_s_body[] = "bad body";
55 const char scm_s_bindings[] = "bad bindings";
56 const char scm_s_variable[] = "bad variable";
57 const char scm_s_clauses[] = "bad or missing clauses";
58 const char scm_s_formals[] = "bad formals";
59
60
61 SCM_REGISTER_PROC(s_substring_move_left_x, "substring-move-left!", 5, 0, 0, scm_substring_move_x);
62
63 SCM_REGISTER_PROC(s_substring_move_right_x, "substring-move-right!", 5, 0, 0, scm_substring_move_x);
64
65 SCM
66 scm_wta (SCM arg, const char *pos, const char *s_subr)
67 {
68 if (!s_subr || !*s_subr)
69 s_subr = NULL;
70 if ((~0x1fL) & (long) pos)
71 {
72 /* error string supplied. */
73 scm_misc_error (s_subr, pos, scm_list_1 (arg));
74 }
75 else
76 {
77 /* numerical error code. */
78 scm_t_bits error = (scm_t_bits) pos;
79
80 switch (error)
81 {
82 case SCM_ARGn:
83 scm_wrong_type_arg (s_subr, 0, arg);
84 case SCM_ARG1:
85 scm_wrong_type_arg (s_subr, 1, arg);
86 case SCM_ARG2:
87 scm_wrong_type_arg (s_subr, 2, arg);
88 case SCM_ARG3:
89 scm_wrong_type_arg (s_subr, 3, arg);
90 case SCM_ARG4:
91 scm_wrong_type_arg (s_subr, 4, arg);
92 case SCM_ARG5:
93 scm_wrong_type_arg (s_subr, 5, arg);
94 case SCM_ARG6:
95 scm_wrong_type_arg (s_subr, 6, arg);
96 case SCM_ARG7:
97 scm_wrong_type_arg (s_subr, 7, arg);
98 case SCM_WNA:
99 scm_wrong_num_args (arg);
100 case SCM_OUTOFRANGE:
101 scm_out_of_range (s_subr, arg);
102 case SCM_NALLOC:
103 scm_memory_error (s_subr);
104 default:
105 /* this shouldn't happen. */
106 scm_misc_error (s_subr, "Unknown error", SCM_EOL);
107 }
108 }
109 return SCM_UNSPECIFIED;
110 }
111
112 /* Module registry
113 */
114
115 /* We can't use SCM objects here. One should be able to call
116 SCM_REGISTER_MODULE from a C++ constructor for a static
117 object. This happens before main and thus before libguile is
118 initialized. */
119
120 struct moddata {
121 struct moddata *link;
122 char *module_name;
123 void *init_func;
124 };
125
126 static struct moddata *registered_mods = NULL;
127
128 void
129 scm_register_module_xxx (char *module_name, void *init_func)
130 {
131 struct moddata *md;
132
133 scm_c_issue_deprecation_warning
134 ("`scm_register_module_xxx' is deprecated. Use extensions instead.");
135
136 /* XXX - should we (and can we) DEFER_INTS here? */
137
138 for (md = registered_mods; md; md = md->link)
139 if (!strcmp (md->module_name, module_name))
140 {
141 md->init_func = init_func;
142 return;
143 }
144
145 md = (struct moddata *) malloc (sizeof (struct moddata));
146 if (md == NULL)
147 {
148 fprintf (stderr,
149 "guile: can't register module (%s): not enough memory",
150 module_name);
151 return;
152 }
153
154 md->module_name = module_name;
155 md->init_func = init_func;
156 md->link = registered_mods;
157 registered_mods = md;
158 }
159
160 SCM_DEFINE (scm_registered_modules, "c-registered-modules", 0, 0, 0,
161 (),
162 "Return a list of the object code modules that have been imported into\n"
163 "the current Guile process. Each element of the list is a pair whose\n"
164 "car is the name of the module, and whose cdr is the function handle\n"
165 "for that module's initializer function. The name is the string that\n"
166 "has been passed to scm_register_module_xxx.")
167 #define FUNC_NAME s_scm_registered_modules
168 {
169 SCM res;
170 struct moddata *md;
171
172 res = SCM_EOL;
173 for (md = registered_mods; md; md = md->link)
174 res = scm_cons (scm_cons (scm_makfrom0str (md->module_name),
175 scm_ulong2num ((unsigned long) md->init_func)),
176 res);
177 return res;
178 }
179 #undef FUNC_NAME
180
181 SCM_DEFINE (scm_clear_registered_modules, "c-clear-registered-modules", 0, 0, 0,
182 (),
183 "Destroy the list of modules registered with the current Guile process.\n"
184 "The return value is unspecified. @strong{Warning:} this function does\n"
185 "not actually unlink or deallocate these modules, but only destroys the\n"
186 "records of which modules have been loaded. It should therefore be used\n"
187 "only by module bookkeeping operations.")
188 #define FUNC_NAME s_scm_clear_registered_modules
189 {
190 struct moddata *md1, *md2;
191
192 SCM_DEFER_INTS;
193
194 for (md1 = registered_mods; md1; md1 = md2)
195 {
196 md2 = md1->link;
197 free (md1);
198 }
199 registered_mods = NULL;
200
201 SCM_ALLOW_INTS;
202 return SCM_UNSPECIFIED;
203 }
204 #undef FUNC_NAME
205
206 void
207 scm_remember (SCM *ptr)
208 {
209 scm_c_issue_deprecation_warning ("`scm_remember' is deprecated. "
210 "Use the `scm_remember_upto_here*' family of functions instead.");
211 }
212
213 SCM
214 scm_protect_object (SCM obj)
215 {
216 scm_c_issue_deprecation_warning ("`scm_protect_object' is deprecated. "
217 "Use `scm_gc_protect_object' instead.");
218 return scm_gc_protect_object (obj);
219 }
220
221 SCM
222 scm_unprotect_object (SCM obj)
223 {
224 scm_c_issue_deprecation_warning ("`scm_unprotect_object' is deprecated. "
225 "Use `scm_gc_unprotect_object' instead.");
226 return scm_gc_unprotect_object (obj);
227 }
228
229 SCM_SYMBOL (scm_sym_app, "app");
230 SCM_SYMBOL (scm_sym_modules, "modules");
231 static SCM module_prefix = SCM_BOOL_F;
232 static SCM make_modules_in_var;
233 static SCM beautify_user_module_x_var;
234 static SCM try_module_autoload_var;
235
236 static void
237 init_module_stuff ()
238 {
239 #define PERM(x) scm_permanent_object(x)
240
241 if (module_prefix == SCM_BOOL_F)
242 {
243 module_prefix = PERM (scm_list_2 (scm_sym_app, scm_sym_modules));
244 make_modules_in_var = PERM (scm_c_lookup ("make-modules-in"));
245 beautify_user_module_x_var =
246 PERM (scm_c_lookup ("beautify-user-module!"));
247 try_module_autoload_var = PERM (scm_c_lookup ("try-module-autoload"));
248 }
249 }
250
251 SCM
252 scm_the_root_module ()
253 {
254 init_module_stuff ();
255 scm_c_issue_deprecation_warning ("`scm_the_root_module' is deprecated. "
256 "Use `scm_c_resolve_module (\"guile\")' "
257 "instead.");
258
259 return scm_c_resolve_module ("guile");
260 }
261
262 static SCM
263 scm_module_full_name (SCM name)
264 {
265 init_module_stuff ();
266 if (SCM_EQ_P (SCM_CAR (name), scm_sym_app))
267 return name;
268 else
269 return scm_append (scm_list_2 (module_prefix, name));
270 }
271
272 SCM
273 scm_make_module (SCM name)
274 {
275 init_module_stuff ();
276 scm_c_issue_deprecation_warning ("`scm_make_module' is deprecated. "
277 "Use `scm_c_define_module instead.");
278
279 return scm_call_2 (SCM_VARIABLE_REF (make_modules_in_var),
280 scm_the_root_module (),
281 scm_module_full_name (name));
282 }
283
284 SCM
285 scm_ensure_user_module (SCM module)
286 {
287 init_module_stuff ();
288 scm_c_issue_deprecation_warning ("`scm_ensure_user_module' is deprecated. "
289 "Use `scm_c_define_module instead.");
290
291 scm_call_1 (SCM_VARIABLE_REF (beautify_user_module_x_var), module);
292 return SCM_UNSPECIFIED;
293 }
294
295 SCM
296 scm_load_scheme_module (SCM name)
297 {
298 init_module_stuff ();
299 scm_c_issue_deprecation_warning ("`scm_load_scheme_module' is deprecated. "
300 "Use `scm_c_resolve_module instead.");
301
302 return scm_call_1 (SCM_VARIABLE_REF (try_module_autoload_var), name);
303 }
304
305 /* This is implemented in C solely for SCM_COERCE_OUTPORT ... */
306
307 static void
308 maybe_close_port (void *data, SCM port)
309 {
310 SCM except = (SCM)data;
311
312 while (!SCM_NULLP (except))
313 {
314 SCM p = SCM_COERCE_OUTPORT (SCM_CAR (except));
315 if (SCM_EQ_P (p, port))
316 return;
317 except = SCM_CDR (except);
318 }
319
320 scm_close_port (port);
321 }
322
323 SCM_DEFINE (scm_close_all_ports_except, "close-all-ports-except", 0, 0, 1,
324 (SCM ports),
325 "[DEPRECATED] Close all open file ports used by the interpreter\n"
326 "except for those supplied as arguments. This procedure\n"
327 "was intended to be used before an exec call to close file descriptors\n"
328 "which are not needed in the new process. However it has the\n"
329 "undesirable side effect of flushing buffers, so it's deprecated.\n"
330 "Use port-for-each instead.")
331 #define FUNC_NAME s_scm_close_all_ports_except
332 {
333 SCM p;
334 SCM_VALIDATE_REST_ARGUMENT (ports);
335
336 for (p = ports; !SCM_NULLP (p); p = SCM_CDR (p))
337 SCM_VALIDATE_OPPORT (SCM_ARG1, SCM_COERCE_OUTPORT (SCM_CAR (p)));
338
339 scm_c_port_for_each (maybe_close_port, ports);
340
341 return SCM_UNSPECIFIED;
342 }
343 #undef FUNC_NAME
344
345 SCM_DEFINE (scm_variable_set_name_hint, "variable-set-name-hint!", 2, 0, 0,
346 (SCM var, SCM hint),
347 "Do not use this function.")
348 #define FUNC_NAME s_scm_variable_set_name_hint
349 {
350 SCM_VALIDATE_VARIABLE (1, var);
351 SCM_VALIDATE_SYMBOL (2, hint);
352 scm_c_issue_deprecation_warning
353 ("'variable-set-name-hint!' is deprecated. Do not use it.");
354 return SCM_UNSPECIFIED;
355 }
356 #undef FUNC_NAME
357
358 SCM_DEFINE (scm_builtin_variable, "builtin-variable", 1, 0, 0,
359 (SCM name),
360 "Do not use this function.")
361 #define FUNC_NAME s_scm_builtin_variable
362 {
363 SCM_VALIDATE_SYMBOL (1,name);
364 scm_c_issue_deprecation_warning ("`builtin-variable' is deprecated. "
365 "Use module system operations instead.");
366 return scm_sym2var (name, SCM_BOOL_F, SCM_BOOL_T);
367 }
368 #undef FUNC_NAME
369
370 SCM
371 scm_makstr (size_t len, int dummy)
372 {
373 scm_c_issue_deprecation_warning
374 ("'scm_makstr' is deprecated. Use 'scm_allocate_string' instead.");
375 return scm_allocate_string (len);
376 }
377
378 SCM
379 scm_makfromstr (const char *src, size_t len, int dummy SCM_UNUSED)
380 {
381 scm_c_issue_deprecation_warning ("`scm_makfromstr' is deprecated. "
382 "Use `scm_mem2string' instead.");
383
384 return scm_mem2string (src, len);
385 }
386
387 SCM
388 scm_internal_with_fluids (SCM fluids, SCM values, SCM (*cproc) (), void *cdata)
389 {
390 scm_c_issue_deprecation_warning ("`scm_internal_with_fluids' is deprecated. "
391 "Use `scm_c_with_fluids' instead.");
392
393 return scm_c_with_fluids (fluids, values, cproc, cdata);
394 }
395
396 SCM
397 scm_make_gsubr (const char *name, int req, int opt, int rst, SCM (*fcn)())
398 {
399 scm_c_issue_deprecation_warning
400 ("`scm_make_gsubr' is deprecated. Use `scm_c_define_gsubr' instead.");
401
402 return scm_c_define_gsubr (name, req, opt, rst, fcn);
403 }
404
405 SCM
406 scm_make_gsubr_with_generic (const char *name,
407 int req, int opt, int rst,
408 SCM (*fcn)(), SCM *gf)
409 {
410 scm_c_issue_deprecation_warning
411 ("`scm_make_gsubr_with_generic' is deprecated. "
412 "Use `scm_c_define_gsubr_with_generic' instead.");
413
414 return scm_c_define_gsubr_with_generic (name, req, opt, rst, fcn, gf);
415 }
416
417 SCM
418 scm_create_hook (const char *name, int n_args)
419 {
420 scm_c_issue_deprecation_warning
421 ("'scm_create_hook' is deprecated. "
422 "Use 'scm_make_hook' and 'scm_c_define' instead.");
423 {
424 SCM hook = scm_make_hook (SCM_MAKINUM (n_args));
425 scm_c_define (name, hook);
426 return scm_permanent_object (hook);
427 }
428 }
429
430 SCM_DEFINE (scm_sloppy_memq, "sloppy-memq", 2, 0, 0,
431 (SCM x, SCM lst),
432 "This procedure behaves like @code{memq}, but does no type or error checking.\n"
433 "Its use is recommended only in writing Guile internals,\n"
434 "not for high-level Scheme programs.")
435 #define FUNC_NAME s_scm_sloppy_memq
436 {
437 scm_c_issue_deprecation_warning
438 ("'sloppy-memq' is deprecated. Use 'memq' instead.");
439
440 for(; SCM_CONSP (lst); lst = SCM_CDR(lst))
441 {
442 if (SCM_EQ_P (SCM_CAR (lst), x))
443 return lst;
444 }
445 return lst;
446 }
447 #undef FUNC_NAME
448
449
450 SCM_DEFINE (scm_sloppy_memv, "sloppy-memv", 2, 0, 0,
451 (SCM x, SCM lst),
452 "This procedure behaves like @code{memv}, but does no type or error checking.\n"
453 "Its use is recommended only in writing Guile internals,\n"
454 "not for high-level Scheme programs.")
455 #define FUNC_NAME s_scm_sloppy_memv
456 {
457 scm_c_issue_deprecation_warning
458 ("'sloppy-memv' is deprecated. Use 'memv' instead.");
459
460 for(; SCM_CONSP (lst); lst = SCM_CDR(lst))
461 {
462 if (! SCM_FALSEP (scm_eqv_p (SCM_CAR (lst), x)))
463 return lst;
464 }
465 return lst;
466 }
467 #undef FUNC_NAME
468
469
470 SCM_DEFINE (scm_sloppy_member, "sloppy-member", 2, 0, 0,
471 (SCM x, SCM lst),
472 "This procedure behaves like @code{member}, but does no type or error checking.\n"
473 "Its use is recommended only in writing Guile internals,\n"
474 "not for high-level Scheme programs.")
475 #define FUNC_NAME s_scm_sloppy_member
476 {
477 scm_c_issue_deprecation_warning
478 ("'sloppy-member' is deprecated. Use 'member' instead.");
479
480 for(; SCM_CONSP (lst); lst = SCM_CDR(lst))
481 {
482 if (! SCM_FALSEP (scm_equal_p (SCM_CAR (lst), x)))
483 return lst;
484 }
485 return lst;
486 }
487 #undef FUNC_NAME
488
489 SCM_SYMBOL (scm_end_of_file_key, "end-of-file");
490
491 SCM_DEFINE (scm_read_and_eval_x, "read-and-eval!", 0, 1, 0,
492 (SCM port),
493 "Read a form from @var{port} (standard input by default), and evaluate it\n"
494 "(memoizing it in the process) in the top-level environment. If no data\n"
495 "is left to be read from @var{port}, an @code{end-of-file} error is\n"
496 "signalled.")
497 #define FUNC_NAME s_scm_read_and_eval_x
498 {
499 SCM form;
500
501 scm_c_issue_deprecation_warning
502 ("'read-and-eval!' is deprecated. Use 'read' and 'eval' instead.");
503
504 form = scm_read (port);
505 if (SCM_EOF_OBJECT_P (form))
506 scm_ithrow (scm_end_of_file_key, SCM_EOL, 1);
507 return scm_eval_x (form, scm_current_module ());
508 }
509 #undef FUNC_NAME
510
511 SCM
512 scm_make_subr_opt (const char *name, int type, SCM (*fcn) (), int set)
513 {
514 scm_c_issue_deprecation_warning
515 ("`scm_make_subr_opt' is deprecated. Use `scm_c_make_subr' or "
516 "`scm_c_define_subr' instead.");
517
518 if (set)
519 return scm_c_define_subr (name, type, fcn);
520 else
521 return scm_c_make_subr (name, type, fcn);
522 }
523
524 SCM
525 scm_make_subr (const char *name, int type, SCM (*fcn) ())
526 {
527 scm_c_issue_deprecation_warning
528 ("`scm_make_subr' is deprecated. Use `scm_c_define_subr' instead.");
529
530 return scm_c_define_subr (name, type, fcn);
531 }
532
533 SCM
534 scm_make_subr_with_generic (const char *name, int type, SCM (*fcn) (), SCM *gf)
535 {
536 scm_c_issue_deprecation_warning
537 ("`scm_make_subr_with_generic' is deprecated. Use "
538 "`scm_c_define_subr_with_generic' instead.");
539
540 return scm_c_define_subr_with_generic (name, type, fcn, gf);
541 }
542
543 /* Call thunk(closure) underneath a top-level error handler.
544 * If an error occurs, pass the exitval through err_filter and return it.
545 * If no error occurs, return the value of thunk.
546 */
547
548 #ifdef _UNICOS
549 typedef int setjmp_type;
550 #else
551 typedef long setjmp_type;
552 #endif
553
554 struct cce_handler_data {
555 SCM (*err_filter) ();
556 void *closure;
557 };
558
559 static SCM
560 invoke_err_filter (void *d, SCM tag, SCM args)
561 {
562 struct cce_handler_data *data = (struct cce_handler_data *)d;
563 return data->err_filter (SCM_BOOL_F, data->closure);
564 }
565
566 SCM
567 scm_call_catching_errors (SCM (*thunk)(), SCM (*err_filter)(), void *closure)
568 {
569 scm_c_issue_deprecation_warning
570 ("'scm_call_catching_errors' is deprecated. "
571 "Use 'scm_internal_catch' instead.");
572
573 {
574 struct cce_handler_data data;
575 data.err_filter = err_filter;
576 data.closure = closure;
577 return scm_internal_catch (SCM_BOOL_T,
578 (scm_t_catch_body)thunk, closure,
579 (scm_t_catch_handler)invoke_err_filter, &data);
580 }
581 }
582
583 long
584 scm_make_smob_type_mfpe (char *name, size_t size,
585 SCM (*mark) (SCM),
586 size_t (*free) (SCM),
587 int (*print) (SCM, SCM, scm_print_state *),
588 SCM (*equalp) (SCM, SCM))
589 {
590 scm_c_issue_deprecation_warning
591 ("'scm_make_smob_type_mfpe' is deprecated. "
592 "Use 'scm_make_smob_type' plus 'scm_set_smob_*' instead.");
593
594 {
595 long answer = scm_make_smob_type (name, size);
596 scm_set_smob_mfpe (answer, mark, free, print, equalp);
597 return answer;
598 }
599 }
600
601 void
602 scm_set_smob_mfpe (long tc,
603 SCM (*mark) (SCM),
604 size_t (*free) (SCM),
605 int (*print) (SCM, SCM, scm_print_state *),
606 SCM (*equalp) (SCM, SCM))
607 {
608 scm_c_issue_deprecation_warning
609 ("'scm_set_smob_mfpe' is deprecated. "
610 "Use 'scm_set_smob_mark' instead, for example.");
611
612 if (mark) scm_set_smob_mark (tc, mark);
613 if (free) scm_set_smob_free (tc, free);
614 if (print) scm_set_smob_print (tc, print);
615 if (equalp) scm_set_smob_equalp (tc, equalp);
616 }
617
618 SCM
619 scm_read_0str (char *expr)
620 {
621 scm_c_issue_deprecation_warning
622 ("scm_read_0str is deprecated. Use scm_c_read_string instead.");
623
624 return scm_c_read_string (expr);
625 }
626
627 SCM
628 scm_eval_0str (const char *expr)
629 {
630 scm_c_issue_deprecation_warning
631 ("scm_eval_0str is deprecated. Use scm_c_eval_string instead.");
632
633 return scm_c_eval_string (expr);
634 }
635
636 SCM
637 scm_strprint_obj (SCM obj)
638 {
639 scm_c_issue_deprecation_warning
640 ("scm_strprint_obj is deprecated. Use scm_object_to_string instead.");
641 return scm_object_to_string (obj, SCM_UNDEFINED);
642 }
643
644 char *
645 scm_i_object_chars (SCM obj)
646 {
647 scm_c_issue_deprecation_warning
648 ("SCM_CHARS is deprecated. Use SCM_STRING_CHARS or "
649 "SCM_SYMBOL_CHARS instead.");
650 if (SCM_STRINGP (obj))
651 return SCM_STRING_CHARS (obj);
652 if (SCM_SYMBOLP (obj))
653 return SCM_SYMBOL_CHARS (obj);
654 abort ();
655 }
656
657 long
658 scm_i_object_length (SCM obj)
659 {
660 scm_c_issue_deprecation_warning
661 ("SCM_LENGTH is deprecated. Use SCM_STRING_LENGTH instead, for example.");
662 if (SCM_STRINGP (obj))
663 return SCM_STRING_LENGTH (obj);
664 if (SCM_SYMBOLP (obj))
665 return SCM_SYMBOL_LENGTH (obj);
666 if (SCM_VECTORP (obj))
667 return SCM_VECTOR_LENGTH (obj);
668 abort ();
669 }
670
671 SCM
672 scm_sym2ovcell_soft (SCM sym, SCM obarray)
673 {
674 SCM lsym, z;
675 size_t hash = SCM_SYMBOL_HASH (sym) % SCM_VECTOR_LENGTH (obarray);
676
677 scm_c_issue_deprecation_warning ("`scm_sym2ovcell_soft' is deprecated. "
678 "Use hashtables instead.");
679
680 SCM_REDEFER_INTS;
681 for (lsym = SCM_VECTOR_REF (obarray, hash);
682 SCM_NIMP (lsym);
683 lsym = SCM_CDR (lsym))
684 {
685 z = SCM_CAR (lsym);
686 if (SCM_EQ_P (SCM_CAR (z), sym))
687 {
688 SCM_REALLOW_INTS;
689 return z;
690 }
691 }
692 SCM_REALLOW_INTS;
693 return SCM_BOOL_F;
694 }
695
696
697 SCM
698 scm_sym2ovcell (SCM sym, SCM obarray)
699 #define FUNC_NAME "scm_sym2ovcell"
700 {
701 SCM answer;
702
703 scm_c_issue_deprecation_warning ("`scm_sym2ovcell' is deprecated. "
704 "Use hashtables instead.");
705
706 answer = scm_sym2ovcell_soft (sym, obarray);
707 if (!SCM_FALSEP (answer))
708 return answer;
709 SCM_MISC_ERROR ("uninterned symbol: ~S", scm_list_1 (sym));
710 return SCM_UNSPECIFIED; /* not reached */
711 }
712 #undef FUNC_NAME
713
714
715 /* Intern a symbol whose name is the LEN characters at NAME in OBARRAY.
716
717 OBARRAY should be a vector of lists, indexed by the name's hash
718 value, modulo OBARRAY's length. Each list has the form
719 ((SYMBOL . VALUE) ...), where SYMBOL is a symbol, and VALUE is the
720 value associated with that symbol (in the current module? in the
721 system module?)
722
723 To "intern" a symbol means: if OBARRAY already contains a symbol by
724 that name, return its (SYMBOL . VALUE) pair; otherwise, create a
725 new symbol, add the pair (SYMBOL . SCM_UNDEFINED) to the
726 appropriate list of the OBARRAY, and return the pair.
727
728 If softness is non-zero, don't create a symbol if it isn't already
729 in OBARRAY; instead, just return #f.
730
731 If OBARRAY is SCM_BOOL_F, create a symbol listed in no obarray and
732 return (SYMBOL . SCM_UNDEFINED). */
733
734
735 SCM
736 scm_intern_obarray_soft (const char *name,size_t len,SCM obarray,unsigned int softness)
737 {
738 SCM symbol = scm_mem2symbol (name, len);
739 size_t raw_hash = SCM_SYMBOL_HASH (symbol);
740 size_t hash;
741 SCM lsym;
742
743 scm_c_issue_deprecation_warning ("`scm_intern_obarray_soft' is deprecated. "
744 "Use hashtables instead.");
745
746 if (SCM_FALSEP (obarray))
747 {
748 if (softness)
749 return SCM_BOOL_F;
750 else
751 return scm_cons (symbol, SCM_UNDEFINED);
752 }
753
754 hash = raw_hash % SCM_VECTOR_LENGTH (obarray);
755
756 for (lsym = SCM_VECTOR_REF(obarray, hash);
757 SCM_NIMP (lsym); lsym = SCM_CDR (lsym))
758 {
759 SCM a = SCM_CAR (lsym);
760 SCM z = SCM_CAR (a);
761 if (SCM_EQ_P (z, symbol))
762 return a;
763 }
764
765 if (softness)
766 {
767 return SCM_BOOL_F;
768 }
769 else
770 {
771 SCM cell = scm_cons (symbol, SCM_UNDEFINED);
772 SCM slot = SCM_VECTOR_REF (obarray, hash);
773
774 SCM_VECTOR_SET (obarray, hash, scm_cons (cell, slot));
775
776 return cell;
777 }
778 }
779
780
781 SCM
782 scm_intern_obarray (const char *name,size_t len,SCM obarray)
783 {
784 scm_c_issue_deprecation_warning ("`scm_intern_obarray' is deprecated. "
785 "Use hashtables instead.");
786
787 return scm_intern_obarray_soft (name, len, obarray, 0);
788 }
789
790 /* Lookup the value of the symbol named by the nul-terminated string
791 NAME in the current module. */
792 SCM
793 scm_symbol_value0 (const char *name)
794 {
795 scm_c_issue_deprecation_warning ("`scm_symbol_value0' is deprecated. "
796 "Use `scm_lookup' instead.");
797
798 return scm_variable_ref (scm_c_lookup (name));
799 }
800
801 SCM_DEFINE (scm_string_to_obarray_symbol, "string->obarray-symbol", 2, 1, 0,
802 (SCM o, SCM s, SCM softp),
803 "Intern a new symbol in @var{obarray}, a symbol table, with name\n"
804 "@var{string}.\n\n"
805 "If @var{obarray} is @code{#f}, use the default system symbol table. If\n"
806 "@var{obarray} is @code{#t}, the symbol should not be interned in any\n"
807 "symbol table; merely return the pair (@var{symbol}\n"
808 ". @var{#<undefined>}).\n\n"
809 "The @var{soft?} argument determines whether new symbol table entries\n"
810 "should be created when the specified symbol is not already present in\n"
811 "@var{obarray}. If @var{soft?} is specified and is a true value, then\n"
812 "new entries should not be added for symbols not already present in the\n"
813 "table; instead, simply return @code{#f}.")
814 #define FUNC_NAME s_scm_string_to_obarray_symbol
815 {
816 SCM vcell;
817 SCM answer;
818 int softness;
819
820 SCM_VALIDATE_STRING (2, s);
821 SCM_ASSERT (SCM_BOOLP (o) || SCM_VECTORP (o), o, SCM_ARG1, FUNC_NAME);
822
823 scm_c_issue_deprecation_warning ("`string->obarray-symbol' is deprecated. "
824 "Use hashtables instead.");
825
826 softness = (!SCM_UNBNDP (softp) && !SCM_FALSEP(softp));
827 /* iron out some screwy calling conventions */
828 if (SCM_FALSEP (o))
829 {
830 /* nothing interesting to do here. */
831 return scm_string_to_symbol (s);
832 }
833 else if (SCM_EQ_P (o, SCM_BOOL_T))
834 o = SCM_BOOL_F;
835
836 vcell = scm_intern_obarray_soft (SCM_STRING_CHARS(s),
837 SCM_STRING_LENGTH (s),
838 o,
839 softness);
840 if (SCM_FALSEP (vcell))
841 return vcell;
842 answer = SCM_CAR (vcell);
843 return answer;
844 }
845 #undef FUNC_NAME
846
847 SCM_DEFINE (scm_intern_symbol, "intern-symbol", 2, 0, 0,
848 (SCM o, SCM s),
849 "Add a new symbol to @var{obarray} with name @var{string}, bound to an\n"
850 "unspecified initial value. The symbol table is not modified if a symbol\n"
851 "with this name is already present.")
852 #define FUNC_NAME s_scm_intern_symbol
853 {
854 size_t hval;
855 SCM_VALIDATE_SYMBOL (2,s);
856 if (SCM_FALSEP (o))
857 return SCM_UNSPECIFIED;
858
859 scm_c_issue_deprecation_warning ("`intern-symbol' is deprecated. "
860 "Use hashtables instead.");
861
862 SCM_VALIDATE_VECTOR (1,o);
863 hval = SCM_SYMBOL_HASH (s) % SCM_VECTOR_LENGTH (o);
864 /* If the symbol is already interned, simply return. */
865 SCM_REDEFER_INTS;
866 {
867 SCM lsym;
868 SCM sym;
869 for (lsym = SCM_VECTOR_REF (o, hval);
870 SCM_NIMP (lsym);
871 lsym = SCM_CDR (lsym))
872 {
873 sym = SCM_CAR (lsym);
874 if (SCM_EQ_P (SCM_CAR (sym), s))
875 {
876 SCM_REALLOW_INTS;
877 return SCM_UNSPECIFIED;
878 }
879 }
880 SCM_VECTOR_SET (o, hval,
881 scm_acons (s, SCM_UNDEFINED,
882 SCM_VECTOR_REF (o, hval)));
883 }
884 SCM_REALLOW_INTS;
885 return SCM_UNSPECIFIED;
886 }
887 #undef FUNC_NAME
888
889 SCM_DEFINE (scm_unintern_symbol, "unintern-symbol", 2, 0, 0,
890 (SCM o, SCM s),
891 "Remove the symbol with name @var{string} from @var{obarray}. This\n"
892 "function returns @code{#t} if the symbol was present and @code{#f}\n"
893 "otherwise.")
894 #define FUNC_NAME s_scm_unintern_symbol
895 {
896 size_t hval;
897
898 scm_c_issue_deprecation_warning ("`unintern-symbol' is deprecated. "
899 "Use hashtables instead.");
900
901 SCM_VALIDATE_SYMBOL (2,s);
902 if (SCM_FALSEP (o))
903 return SCM_BOOL_F;
904 SCM_VALIDATE_VECTOR (1,o);
905 hval = SCM_SYMBOL_HASH (s) % SCM_VECTOR_LENGTH (o);
906 SCM_DEFER_INTS;
907 {
908 SCM lsym_follow;
909 SCM lsym;
910 SCM sym;
911 for (lsym = SCM_VECTOR_REF (o, hval), lsym_follow = SCM_BOOL_F;
912 SCM_NIMP (lsym);
913 lsym_follow = lsym, lsym = SCM_CDR (lsym))
914 {
915 sym = SCM_CAR (lsym);
916 if (SCM_EQ_P (SCM_CAR (sym), s))
917 {
918 /* Found the symbol to unintern. */
919 if (SCM_FALSEP (lsym_follow))
920 SCM_VECTOR_SET (o, hval, lsym);
921 else
922 SCM_SETCDR (lsym_follow, SCM_CDR(lsym));
923 SCM_ALLOW_INTS;
924 return SCM_BOOL_T;
925 }
926 }
927 }
928 SCM_ALLOW_INTS;
929 return SCM_BOOL_F;
930 }
931 #undef FUNC_NAME
932
933 SCM_DEFINE (scm_symbol_binding, "symbol-binding", 2, 0, 0,
934 (SCM o, SCM s),
935 "Look up in @var{obarray} the symbol whose name is @var{string}, and\n"
936 "return the value to which it is bound. If @var{obarray} is @code{#f},\n"
937 "use the global symbol table. If @var{string} is not interned in\n"
938 "@var{obarray}, an error is signalled.")
939 #define FUNC_NAME s_scm_symbol_binding
940 {
941 SCM vcell;
942
943 scm_c_issue_deprecation_warning ("`symbol-binding' is deprecated. "
944 "Use hashtables instead.");
945
946 SCM_VALIDATE_SYMBOL (2,s);
947 if (SCM_FALSEP (o))
948 return scm_variable_ref (scm_lookup (s));
949 SCM_VALIDATE_VECTOR (1,o);
950 vcell = scm_sym2ovcell (s, o);
951 return SCM_CDR(vcell);
952 }
953 #undef FUNC_NAME
954
955 #if 0
956 SCM_DEFINE (scm_symbol_interned_p, "symbol-interned?", 2, 0, 0,
957 (SCM o, SCM s),
958 "Return @code{#t} if @var{obarray} contains a symbol with name\n"
959 "@var{string}, and @code{#f} otherwise.")
960 #define FUNC_NAME s_scm_symbol_interned_p
961 {
962 SCM vcell;
963
964 scm_c_issue_deprecation_warning ("`symbol-interned?' is deprecated. "
965 "Use hashtables instead.");
966
967 SCM_VALIDATE_SYMBOL (2,s);
968 if (SCM_FALSEP (o))
969 {
970 SCM var = scm_sym2var (s, SCM_BOOL_F, SCM_BOOL_F);
971 if (var != SCM_BOOL_F)
972 return SCM_BOOL_T;
973 return SCM_BOOL_F;
974 }
975 SCM_VALIDATE_VECTOR (1,o);
976 vcell = scm_sym2ovcell_soft (s, o);
977 return (SCM_NIMP(vcell)
978 ? SCM_BOOL_T
979 : SCM_BOOL_F);
980 }
981 #undef FUNC_NAME
982 #endif
983
984 SCM_DEFINE (scm_symbol_bound_p, "symbol-bound?", 2, 0, 0,
985 (SCM o, SCM s),
986 "Return @code{#t} if @var{obarray} contains a symbol with name\n"
987 "@var{string} bound to a defined value. This differs from\n"
988 "@var{symbol-interned?} in that the mere mention of a symbol\n"
989 "usually causes it to be interned; @code{symbol-bound?}\n"
990 "determines whether a symbol has been given any meaningful\n"
991 "value.")
992 #define FUNC_NAME s_scm_symbol_bound_p
993 {
994 SCM vcell;
995
996 scm_c_issue_deprecation_warning ("`symbol-bound?' is deprecated. "
997 "Use hashtables instead.");
998
999 SCM_VALIDATE_SYMBOL (2,s);
1000 if (SCM_FALSEP (o))
1001 {
1002 SCM var = scm_sym2var (s, SCM_BOOL_F, SCM_BOOL_F);
1003 if (SCM_VARIABLEP(var) && !SCM_UNBNDP(SCM_VARIABLE_REF(var)))
1004 return SCM_BOOL_T;
1005 return SCM_BOOL_F;
1006 }
1007 SCM_VALIDATE_VECTOR (1,o);
1008 vcell = scm_sym2ovcell_soft (s, o);
1009 return SCM_BOOL (SCM_NIMP (vcell) && !SCM_UNBNDP (SCM_CDR (vcell)));
1010 }
1011 #undef FUNC_NAME
1012
1013
1014 SCM_DEFINE (scm_symbol_set_x, "symbol-set!", 3, 0, 0,
1015 (SCM o, SCM s, SCM v),
1016 "Find the symbol in @var{obarray} whose name is @var{string}, and rebind\n"
1017 "it to @var{value}. An error is signalled if @var{string} is not present\n"
1018 "in @var{obarray}.")
1019 #define FUNC_NAME s_scm_symbol_set_x
1020 {
1021 SCM vcell;
1022
1023 scm_c_issue_deprecation_warning ("`symbol-set!' is deprecated. "
1024 "Use the module system instead.");
1025
1026 SCM_VALIDATE_SYMBOL (2,s);
1027 if (SCM_FALSEP (o))
1028 {
1029 scm_define (s, v);
1030 return SCM_UNSPECIFIED;
1031 }
1032 SCM_VALIDATE_VECTOR (1,o);
1033 vcell = scm_sym2ovcell (s, o);
1034 SCM_SETCDR (vcell, v);
1035 return SCM_UNSPECIFIED;
1036 }
1037 #undef FUNC_NAME
1038
1039 #define MAX_PREFIX_LENGTH 30
1040
1041 static int gentemp_counter;
1042
1043 SCM_DEFINE (scm_gentemp, "gentemp", 0, 2, 0,
1044 (SCM prefix, SCM obarray),
1045 "Create a new symbol with a name unique in an obarray.\n"
1046 "The name is constructed from an optional string @var{prefix}\n"
1047 "and a counter value. The default prefix is @code{t}. The\n"
1048 "@var{obarray} is specified as a second optional argument.\n"
1049 "Default is the system obarray where all normal symbols are\n"
1050 "interned. The counter is increased by 1 at each\n"
1051 "call. There is no provision for resetting the counter.")
1052 #define FUNC_NAME s_scm_gentemp
1053 {
1054 char buf[MAX_PREFIX_LENGTH + SCM_INTBUFLEN];
1055 char *name = buf;
1056 int len, n_digits;
1057
1058 scm_c_issue_deprecation_warning ("`gentemp' is deprecated. "
1059 "Use `gensym' instead.");
1060
1061 if (SCM_UNBNDP (prefix))
1062 {
1063 name[0] = 't';
1064 len = 1;
1065 }
1066 else
1067 {
1068 SCM_VALIDATE_STRING (1, prefix);
1069 len = SCM_STRING_LENGTH (prefix);
1070 if (len > MAX_PREFIX_LENGTH)
1071 name = SCM_MUST_MALLOC (MAX_PREFIX_LENGTH + SCM_INTBUFLEN);
1072 strncpy (name, SCM_STRING_CHARS (prefix), len);
1073 }
1074
1075 if (SCM_UNBNDP (obarray))
1076 return scm_gensym (prefix);
1077 else
1078 SCM_ASSERT ((SCM_VECTORP (obarray) || SCM_WVECTP (obarray)),
1079 obarray,
1080 SCM_ARG2,
1081 FUNC_NAME);
1082 do
1083 n_digits = scm_iint2str (gentemp_counter++, 10, &name[len]);
1084 while (!SCM_FALSEP (scm_intern_obarray_soft (name,
1085 len + n_digits,
1086 obarray,
1087 1)));
1088 {
1089 SCM vcell = scm_intern_obarray_soft (name,
1090 len + n_digits,
1091 obarray,
1092 0);
1093 if (name != buf)
1094 scm_must_free (name);
1095 return SCM_CAR (vcell);
1096 }
1097 }
1098 #undef FUNC_NAME
1099
1100 void
1101 scm_i_init_deprecated ()
1102 {
1103 #include "libguile/deprecated.x"
1104 }
1105
1106 #endif