3 ;;;; Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005
4 ;;;; Free Software Foundation, Inc.
6 ;;;; This library is free software; you can redistribute it and/or
7 ;;;; modify it under the terms of the GNU Lesser General Public
8 ;;;; License as published by the Free Software Foundation; either
9 ;;;; version 2.1 of the License, or (at your option) any later version.
11 ;;;; This library is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;;; Lesser General Public License for more details.
16 ;;;; You should have received a copy of the GNU Lesser General Public
17 ;;;; License along with this library; if not, write to the Free Software
18 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 ;;; This file is the first thing loaded into Guile. It adds many mundane
26 ;;; definitions and a few that are interesting.
28 ;;; The module system (hence the hierarchical namespace) are defined in this
40 (if (not (memq sym *features*))
41 (set! *features* (cons sym *features*))))
43 ;; Return #t iff FEATURE is available to this Guile interpreter. In SLIB,
44 ;; provided? also checks to see if the module is available. We should do that
47 (define (provided? feature)
48 (and (memq feature *features*) #t))
50 ;; let format alias simple-format until the more complete version is loaded
52 (define format simple-format)
54 ;; this is scheme wrapping the C code so the final pred call is a tail call,
56 (define (string-any char_pred s . rest)
57 (let ((start (if (null? rest)
59 (end (if (or (null? rest) (null? (cdr rest)))
60 (string-length s) (cadr rest))))
61 (if (and (procedure? char_pred)
63 (<= end (string-length s))) ;; let c-code handle range error
64 (or (string-any-c-code char_pred s start (1- end))
65 (char_pred (string-ref s (1- end))))
66 (string-any-c-code char_pred s start end))))
68 ;; this is scheme wrapping the C code so the final pred call is a tail call,
70 (define (string-every char_pred s . rest)
71 (let ((start (if (null? rest)
73 (end (if (or (null? rest) (null? (cdr rest)))
74 (string-length s) (cadr rest))))
75 (if (and (procedure? char_pred)
77 (<= end (string-length s))) ;; let c-code handle range error
78 (and (string-every-c-code char_pred s start (1- end))
79 (char_pred (string-ref s (1- end))))
80 (string-every-c-code char_pred s start end))))
82 ;; A variant of string-fill! that we keep for compatability
84 (define (substring-fill! str start end fill)
85 (string-fill! str fill start end))
92 ;; (eval-case ((situation*) forms)* (else forms)?)
94 ;; Evaluate certain code based on the situation that eval-case is used
95 ;; in. The only defined situation right now is `load-toplevel' which
96 ;; triggers for code evaluated at the top-level, for example from the
97 ;; REPL or when loading a file.
100 (procedure->memoizing-macro
102 (define (toplevel-env? env)
103 (or (not (pair? env)) (not (pair? (car env)))))
105 (error "syntax error in eval-case"))
106 (let loop ((clauses (cdr exp)))
110 ((not (list? (car clauses)))
112 ((eq? 'else (caar clauses))
113 (or (null? (cdr clauses))
115 (cons 'begin (cdar clauses)))
116 ((not (list? (caar clauses)))
118 ((and (toplevel-env? env)
119 (memq 'load-toplevel (caar clauses)))
120 (cons 'begin (cdar clauses)))
122 (loop (cdr clauses))))))))
128 ;;; Depends on: features, eval-case
131 (define macro-table (make-weak-key-hash-table 61))
132 (define xformer-table (make-weak-key-hash-table 61))
134 (define (defmacro? m) (hashq-ref macro-table m))
135 (define (assert-defmacro?! m) (hashq-set! macro-table m #t))
136 (define (defmacro-transformer m) (hashq-ref xformer-table m))
137 (define (set-defmacro-transformer! m t) (hashq-set! xformer-table m t))
139 (define defmacro:transformer
141 (let* ((xform (lambda (exp env)
142 (copy-tree (apply f (cdr exp)))))
143 (a (procedure->memoizing-macro xform)))
144 (assert-defmacro?! a)
145 (set-defmacro-transformer! a f)
150 (let ((defmacro-transformer
151 (lambda (name parms . body)
152 (let ((transformer `(lambda ,parms ,@body)))
155 (define ,name (defmacro:transformer ,transformer)))
157 (error "defmacro can only be used at the top level")))))))
158 (defmacro:transformer defmacro-transformer)))
160 (define defmacro:syntax-transformer
164 (copy-tree (apply f (cdr exp)))))))
167 ;; XXX - should the definition of the car really be looked up in the
170 (define (macroexpand-1 e)
172 ((pair? e) (let* ((a (car e))
173 (val (and (symbol? a) (local-ref (list a)))))
175 (apply (defmacro-transformer val) (cdr e))
179 (define (macroexpand e)
181 ((pair? e) (let* ((a (car e))
182 (val (and (symbol? a) (local-ref (list a)))))
184 (macroexpand (apply (defmacro-transformer val) (cdr e)))
194 ;;; Depends on: defmacro
197 (defmacro begin-deprecated forms
198 (if (include-deprecated-features)
204 ;;; {R4RS compliance}
207 (primitive-load-path "ice-9/r4rs.scm")
211 ;;; {Simple Debugging Tools}
214 ;; peek takes any number of arguments, writes them to the
215 ;; current ouput port, and returns the last argument.
216 ;; It is handy to wrap around an expression to look at
217 ;; a value each time is evaluated, e.g.:
219 ;; (+ 10 (troublesome-fn))
220 ;; => (+ 10 (pk 'troublesome-fn-returned (troublesome-fn)))
223 (define (peek . stuff)
228 (car (last-pair stuff)))
232 (define (warn . stuff)
233 (with-output-to-port (current-error-port)
236 (display ";;; WARNING ")
239 (car (last-pair stuff)))))
243 ;;; {Trivial Functions}
246 (define (identity x) x)
247 (define (and=> value procedure) (and value (procedure value)))
248 (define call/cc call-with-current-continuation)
250 ;;; apply-to-args is functionally redundant with apply and, worse,
251 ;;; is less general than apply since it only takes two arguments.
253 ;;; On the other hand, apply-to-args is a syntacticly convenient way to
254 ;;; perform binding in many circumstances when the "let" family of
255 ;;; of forms don't cut it. E.g.:
257 ;;; (apply-to-args (return-3d-mouse-coords)
262 (define (apply-to-args args fn) (apply fn args))
264 (defmacro false-if-exception (expr)
265 `(catch #t (lambda () ,expr)
270 ;;; {General Properties}
273 ;; This is a more modern interface to properties. It will replace all
274 ;; other property-like things eventually.
276 (define (make-object-property)
277 (let ((prop (primitive-make-property #f)))
278 (make-procedure-with-setter
279 (lambda (obj) (primitive-property-ref prop obj))
280 (lambda (obj val) (primitive-property-set! prop obj val)))))
284 ;;; {Symbol Properties}
287 (define (symbol-property sym prop)
288 (let ((pair (assoc prop (symbol-pref sym))))
289 (and pair (cdr pair))))
291 (define (set-symbol-property! sym prop val)
292 (let ((pair (assoc prop (symbol-pref sym))))
295 (symbol-pset! sym (acons prop val (symbol-pref sym))))))
297 (define (symbol-property-remove! sym prop)
298 (let ((pair (assoc prop (symbol-pref sym))))
300 (symbol-pset! sym (delq! pair (symbol-pref sym))))))
307 (define (array-shape a)
308 (map (lambda (ind) (if (number? ind) (list 0 (+ -1 ind)) ind))
309 (array-dimensions a)))
316 (define (kw-arg-ref args kw)
317 (let ((rem (member kw args)))
318 (and rem (pair? (cdr rem)) (cadr rem))))
325 (define (struct-layout s)
326 (struct-ref (struct-vtable s) vtable-index-layout))
333 (define the-environment
338 (define the-root-environment (the-environment))
340 (define (environment-module env)
341 (let ((closure (and (pair? env) (car (last-pair env)))))
342 (and closure (eval-closure-module closure))))
349 ;; Printing records: by default, records are printed as
351 ;; #<type-name field1: val1 field2: val2 ...>
353 ;; You can change that by giving a custom printing function to
354 ;; MAKE-RECORD-TYPE (after the list of field symbols). This function
355 ;; will be called like
357 ;; (<printer> object port)
359 ;; It should print OBJECT to PORT.
361 (define (inherit-print-state old-port new-port)
362 (if (get-print-state old-port)
363 (port-with-print-state new-port (get-print-state old-port))
366 ;; 0: type-name, 1: fields
367 (define record-type-vtable
368 (make-vtable-vtable "prpr" 0
370 (cond ((eq? s record-type-vtable)
371 (display "#<record-type-vtable>" p))
373 (display "#<record-type " p)
374 (display (record-type-name s) p)
377 (define (record-type? obj)
378 (and (struct? obj) (eq? record-type-vtable (struct-vtable obj))))
380 (define (make-record-type type-name fields . opt)
381 (let ((printer-fn (and (pair? opt) (car opt))))
382 (let ((struct (make-struct record-type-vtable 0
385 (map (lambda (f) "pw") fields)))
389 (display type-name p)
390 (let loop ((fields fields)
393 ((not (null? fields))
395 (display (car fields) p)
397 (display (struct-ref s off) p)
398 (loop (cdr fields) (+ 1 off)))))
401 (copy-tree fields))))
402 ;; Temporary solution: Associate a name to the record type descriptor
403 ;; so that the object system can create a wrapper class for it.
404 (set-struct-vtable-name! struct (if (symbol? type-name)
406 (string->symbol type-name)))
409 (define (record-type-name obj)
410 (if (record-type? obj)
411 (struct-ref obj vtable-offset-user)
412 (error 'not-a-record-type obj)))
414 (define (record-type-fields obj)
415 (if (record-type? obj)
416 (struct-ref obj (+ 1 vtable-offset-user))
417 (error 'not-a-record-type obj)))
419 (define (record-constructor rtd . opt)
420 (let ((field-names (if (pair? opt) (car opt) (record-type-fields rtd))))
421 (local-eval `(lambda ,field-names
422 (make-struct ',rtd 0 ,@(map (lambda (f)
423 (if (memq f field-names)
426 (record-type-fields rtd))))
427 the-root-environment)))
429 (define (record-predicate rtd)
430 (lambda (obj) (and (struct? obj) (eq? rtd (struct-vtable obj)))))
432 (define (record-accessor rtd field-name)
433 (let* ((pos (list-index (record-type-fields rtd) field-name)))
435 (error 'no-such-field field-name))
436 (local-eval `(lambda (obj)
437 (and (eq? ',rtd (record-type-descriptor obj))
438 (struct-ref obj ,pos)))
439 the-root-environment)))
441 (define (record-modifier rtd field-name)
442 (let* ((pos (list-index (record-type-fields rtd) field-name)))
444 (error 'no-such-field field-name))
445 (local-eval `(lambda (obj val)
446 (and (eq? ',rtd (record-type-descriptor obj))
447 (struct-set! obj ,pos val)))
448 the-root-environment)))
451 (define (record? obj)
452 (and (struct? obj) (record-type? (struct-vtable obj))))
454 (define (record-type-descriptor obj)
457 (error 'not-a-record obj)))
466 (define (->bool x) (not (not x)))
473 (define (symbol-append . args)
474 (string->symbol (apply string-append (map symbol->string args))))
476 (define (list->symbol . args)
477 (string->symbol (apply list->string args)))
479 (define (symbol . args)
480 (string->symbol (apply string args)))
487 (define (list-index l k)
493 (loop (+ n 1) (cdr l))))))
497 ;;; {and-map and or-map}
499 ;;; (and-map fn lst) is like (and (fn (car lst)) (fn (cadr lst)) (fn...) ...)
500 ;;; (or-map fn lst) is like (or (fn (car lst)) (fn (cadr lst)) (fn...) ...)
505 ;; Apply f to successive elements of l until exhaustion or f returns #f.
506 ;; If returning early, return #f. Otherwise, return the last value returned
507 ;; by f. If f has never been called because l is empty, return #t.
509 (define (and-map f lst)
510 (let loop ((result #t)
515 (loop (f (car l)) (cdr l))))))
519 ;; Apply f to successive elements of l until exhaustion or while f returns #f.
520 ;; If returning early, return the return value of f.
522 (define (or-map f lst)
523 (let loop ((result #f)
527 (loop (f (car l)) (cdr l))))))
531 (if (provided? 'posix)
532 (primitive-load-path "ice-9/posix.scm"))
534 (if (provided? 'socket)
535 (primitive-load-path "ice-9/networking.scm"))
537 ;; For reference, Emacs file-exists-p uses stat in this same way.
538 ;; ENHANCE-ME: Catching an exception from stat is a bit wasteful, do this in
539 ;; C where all that's needed is to inspect the return from stat().
541 (if (provided? 'posix)
543 (->bool (false-if-exception (stat str))))
545 (let ((port (catch 'system-error (lambda () (open-file str OPEN_READ))
547 (if port (begin (close-port port) #t)
550 (define file-is-directory?
551 (if (provided? 'posix)
553 (eq? (stat:type (stat str)) 'directory))
555 (let ((port (catch 'system-error
556 (lambda () (open-file (string-append str "/.")
559 (if port (begin (close-port port) #t)
562 (define (has-suffix? str suffix)
563 (let ((sufl (string-length suffix))
564 (sl (string-length str)))
566 (string=? (substring str (- sl sufl) sl) suffix))))
568 (define (system-error-errno args)
569 (if (eq? (car args) 'system-error)
570 (car (list-ref args 4))
578 (define (error . args)
581 (scm-error 'misc-error #f "?" #f #f)
582 (let loop ((msg "~A")
584 (if (not (null? rest))
585 (loop (string-append msg " ~S")
587 (scm-error 'misc-error #f msg args #f)))))
589 ;; bad-throw is the hook that is called upon a throw to a an unhandled
590 ;; key (unless the throw has four arguments, in which case
591 ;; it's usually interpreted as an error throw.)
592 ;; If the key has a default handler (a throw-handler-default property),
593 ;; it is applied to the throw.
595 (define (bad-throw key . args)
596 (let ((default (symbol-property key 'throw-handler-default)))
597 (or (and default (apply default key args))
598 (apply error "unhandled-exception:" key args))))
602 (define (tm:sec obj) (vector-ref obj 0))
603 (define (tm:min obj) (vector-ref obj 1))
604 (define (tm:hour obj) (vector-ref obj 2))
605 (define (tm:mday obj) (vector-ref obj 3))
606 (define (tm:mon obj) (vector-ref obj 4))
607 (define (tm:year obj) (vector-ref obj 5))
608 (define (tm:wday obj) (vector-ref obj 6))
609 (define (tm:yday obj) (vector-ref obj 7))
610 (define (tm:isdst obj) (vector-ref obj 8))
611 (define (tm:gmtoff obj) (vector-ref obj 9))
612 (define (tm:zone obj) (vector-ref obj 10))
614 (define (set-tm:sec obj val) (vector-set! obj 0 val))
615 (define (set-tm:min obj val) (vector-set! obj 1 val))
616 (define (set-tm:hour obj val) (vector-set! obj 2 val))
617 (define (set-tm:mday obj val) (vector-set! obj 3 val))
618 (define (set-tm:mon obj val) (vector-set! obj 4 val))
619 (define (set-tm:year obj val) (vector-set! obj 5 val))
620 (define (set-tm:wday obj val) (vector-set! obj 6 val))
621 (define (set-tm:yday obj val) (vector-set! obj 7 val))
622 (define (set-tm:isdst obj val) (vector-set! obj 8 val))
623 (define (set-tm:gmtoff obj val) (vector-set! obj 9 val))
624 (define (set-tm:zone obj val) (vector-set! obj 10 val))
626 (define (tms:clock obj) (vector-ref obj 0))
627 (define (tms:utime obj) (vector-ref obj 1))
628 (define (tms:stime obj) (vector-ref obj 2))
629 (define (tms:cutime obj) (vector-ref obj 3))
630 (define (tms:cstime obj) (vector-ref obj 4))
632 (define file-position ftell)
633 (define (file-set-position port offset . whence)
634 (let ((whence (if (eq? whence '()) SEEK_SET (car whence))))
635 (seek port offset whence)))
637 (define (move->fdes fd/port fd)
638 (cond ((integer? fd/port)
639 (dup->fdes fd/port fd)
643 (primitive-move->fdes fd/port fd)
644 (set-port-revealed! fd/port 1)
647 (define (release-port-handle port)
648 (let ((revealed (port-revealed port)))
650 (set-port-revealed! port (- revealed 1)))))
652 (define (dup->port port/fd mode . maybe-fd)
653 (let ((port (fdopen (apply dup->fdes port/fd maybe-fd)
656 (set-port-revealed! port 1))
659 (define (dup->inport port/fd . maybe-fd)
660 (apply dup->port port/fd "r" maybe-fd))
662 (define (dup->outport port/fd . maybe-fd)
663 (apply dup->port port/fd "w" maybe-fd))
665 (define (dup port/fd . maybe-fd)
666 (if (integer? port/fd)
667 (apply dup->fdes port/fd maybe-fd)
668 (apply dup->port port/fd (port-mode port/fd) maybe-fd)))
670 (define (duplicate-port port modes)
671 (dup->port port modes))
673 (define (fdes->inport fdes)
674 (let loop ((rest-ports (fdes->ports fdes)))
675 (cond ((null? rest-ports)
676 (let ((result (fdopen fdes "r")))
677 (set-port-revealed! result 1)
679 ((input-port? (car rest-ports))
680 (set-port-revealed! (car rest-ports)
681 (+ (port-revealed (car rest-ports)) 1))
684 (loop (cdr rest-ports))))))
686 (define (fdes->outport fdes)
687 (let loop ((rest-ports (fdes->ports fdes)))
688 (cond ((null? rest-ports)
689 (let ((result (fdopen fdes "w")))
690 (set-port-revealed! result 1)
692 ((output-port? (car rest-ports))
693 (set-port-revealed! (car rest-ports)
694 (+ (port-revealed (car rest-ports)) 1))
697 (loop (cdr rest-ports))))))
699 (define (port->fdes port)
700 (set-port-revealed! port (+ (port-revealed port) 1))
703 (define (setenv name value)
705 (putenv (string-append name "=" value))
708 (define (unsetenv name)
709 "Remove the entry for NAME from the environment."
717 ;;; Here for backward compatability
719 (define scheme-file-suffix (lambda () ".scm"))
721 (define (in-vicinity vicinity file)
722 (let ((tail (let ((len (string-length vicinity)))
725 (string-ref vicinity (- len 1))))))
726 (string-append vicinity
735 ;;; {Help for scm_shell}
737 ;;; The argument-processing code used by Guile-based shells generates
738 ;;; Scheme code based on the argument list. This page contains help
739 ;;; functions for the code it generates.
742 (define (command-line) (program-arguments))
744 ;; This is mostly for the internal use of the code generated by
745 ;; scm_compile_shell_switches.
747 (define (turn-on-debugging)
748 (debug-enable 'debug)
749 (debug-enable 'backtrace)
750 (read-enable 'positions))
752 (define (load-user-init)
753 (let* ((home (or (getenv "HOME")
754 (false-if-exception (passwd:dir (getpwuid (getuid))))
755 "/")) ;; fallback for cygwin etc.
756 (init-file (in-vicinity home ".guile")))
757 (if (file-exists? init-file)
758 (primitive-load init-file))))
762 ;;; {Loading by paths}
765 ;;; Load a Scheme source file named NAME, searching for it in the
766 ;;; directories listed in %load-path, and applying each of the file
767 ;;; name extensions listed in %load-extensions.
768 (define (load-from-path name)
769 (start-stack 'load-stack
770 (primitive-load-path name)))
775 ;;; {Transcendental Functions}
777 ;;; Derived from "Transcen.scm", Complex trancendental functions for SCM.
778 ;;; Written by Jerry D. Hedden, (C) FSF.
779 ;;; See the file `COPYING' for terms applying to this program.
783 (if (real? z) ($exp z)
784 (make-polar ($exp (real-part z)) (imag-part z))))
787 (if (and (real? z) (>= z 0))
789 (make-rectangular ($log (magnitude z)) (angle z))))
793 (if (negative? z) (make-rectangular 0 ($sqrt (- z)))
795 (make-polar ($sqrt (magnitude z)) (/ (angle z) 2))))
798 (let ((integer-expt integer-expt))
800 (cond ((and (exact? z2) (integer? z2))
801 (integer-expt z1 z2))
802 ((and (real? z2) (real? z1) (>= z1 0))
805 (exp (* z2 (log z1))))))))
808 (if (real? z) ($sinh z)
809 (let ((x (real-part z)) (y (imag-part z)))
810 (make-rectangular (* ($sinh x) ($cos y))
811 (* ($cosh x) ($sin y))))))
813 (if (real? z) ($cosh z)
814 (let ((x (real-part z)) (y (imag-part z)))
815 (make-rectangular (* ($cosh x) ($cos y))
816 (* ($sinh x) ($sin y))))))
818 (if (real? z) ($tanh z)
819 (let* ((x (* 2 (real-part z)))
820 (y (* 2 (imag-part z)))
821 (w (+ ($cosh x) ($cos y))))
822 (make-rectangular (/ ($sinh x) w) (/ ($sin y) w)))))
825 (if (real? z) ($asinh z)
826 (log (+ z (sqrt (+ (* z z) 1))))))
829 (if (and (real? z) (>= z 1))
831 (log (+ z (sqrt (- (* z z) 1))))))
834 (if (and (real? z) (> z -1) (< z 1))
836 (/ (log (/ (+ 1 z) (- 1 z))) 2)))
839 (if (real? z) ($sin z)
840 (let ((x (real-part z)) (y (imag-part z)))
841 (make-rectangular (* ($sin x) ($cosh y))
842 (* ($cos x) ($sinh y))))))
844 (if (real? z) ($cos z)
845 (let ((x (real-part z)) (y (imag-part z)))
846 (make-rectangular (* ($cos x) ($cosh y))
847 (- (* ($sin x) ($sinh y)))))))
849 (if (real? z) ($tan z)
850 (let* ((x (* 2 (real-part z)))
851 (y (* 2 (imag-part z)))
852 (w (+ ($cos x) ($cosh y))))
853 (make-rectangular (/ ($sin x) w) (/ ($sinh y) w)))))
856 (if (and (real? z) (>= z -1) (<= z 1))
858 (* -i (asinh (* +i z)))))
861 (if (and (real? z) (>= z -1) (<= z 1))
863 (+ (/ (angle -1) 2) (* +i (asinh (* +i z))))))
867 (if (real? z) ($atan z)
868 (/ (log (/ (- +i z) (+ +i z))) +2i))
872 (/ (log arg) (log 10)))
876 ;;; {Reader Extensions}
878 ;;; Reader code for various "#c" forms.
881 (read-hash-extend #\' (lambda (c port)
884 (define read-eval? (make-fluid))
885 (fluid-set! read-eval? #f)
886 (read-hash-extend #\.
888 (if (fluid-ref read-eval?)
889 (eval (read port) (interaction-environment))
891 "#. read expansion found and read-eval? is #f."))))
895 ;;; {Command Line Options}
898 (define (get-option argv kw-opts kw-args return)
903 ((or (not (eq? #\- (string-ref (car argv) 0)))
904 (eq? (string-length (car argv)) 1))
905 (return 'normal-arg (car argv) (cdr argv)))
907 ((eq? #\- (string-ref (car argv) 1))
908 (let* ((kw-arg-pos (or (string-index (car argv) #\=)
909 (string-length (car argv))))
910 (kw (symbol->keyword (substring (car argv) 2 kw-arg-pos)))
911 (kw-opt? (member kw kw-opts))
912 (kw-arg? (member kw kw-args))
913 (arg (or (and (not (eq? kw-arg-pos (string-length (car argv))))
914 (substring (car argv)
916 (string-length (car argv))))
918 (begin (set! argv (cdr argv)) (car argv))))))
919 (if (or kw-opt? kw-arg?)
920 (return kw arg (cdr argv))
921 (return 'usage-error kw (cdr argv)))))
924 (let* ((char (substring (car argv) 1 2))
925 (kw (symbol->keyword char)))
929 (let* ((rest-car (substring (car argv) 2 (string-length (car argv))))
930 (new-argv (if (= 0 (string-length rest-car))
932 (cons (string-append "-" rest-car) (cdr argv)))))
933 (return kw #f new-argv)))
936 (let* ((rest-car (substring (car argv) 2 (string-length (car argv))))
937 (arg (if (= 0 (string-length rest-car))
940 (new-argv (if (= 0 (string-length rest-car))
943 (return kw arg new-argv)))
945 (else (return 'usage-error kw argv)))))))
947 (define (for-next-option proc argv kw-opts kw-args)
948 (let loop ((argv argv))
949 (get-option argv kw-opts kw-args
950 (lambda (opt opt-arg argv)
951 (and opt (proc opt opt-arg argv loop))))))
953 (define (display-usage-report kw-desc)
956 (or (eq? (car kw) #t)
959 (help (cadr opt-desc))
960 (opts (car opt-desc))
961 (opts-proper (if (string? (car opts)) (cdr opts) opts))
962 (arg-name (if (string? (car opts))
963 (string-append "<" (car opts) ">")
965 (left-part (string-append
966 (with-output-to-string
968 (map (lambda (x) (display (keyword->symbol x)) (display " "))
971 (middle-part (if (and (< (string-length left-part) 30)
972 (< (string-length help) 40))
973 (make-string (- 30 (string-length left-part)) #\ )
976 (display middle-part)
983 (define (transform-usage-lambda cases)
984 (let* ((raw-usage (delq! 'else (map car cases)))
985 (usage-sans-specials (map (lambda (x)
986 (or (and (not (list? x)) x)
987 (and (symbol? (car x)) #t)
988 (and (boolean? (car x)) #t)
991 (usage-desc (delq! #t usage-sans-specials))
992 (kw-desc (map car usage-desc))
993 (kw-opts (apply append (map (lambda (x) (and (not (string? (car x))) x)) kw-desc)))
994 (kw-args (apply append (map (lambda (x) (and (string? (car x)) (cdr x))) kw-desc)))
995 (transmogrified-cases (map (lambda (case)
996 (cons (let ((opts (car case)))
997 (if (or (boolean? opts) (eq? 'else opts))
1000 ((symbol? (car opts)) opts)
1001 ((boolean? (car opts)) opts)
1002 ((string? (caar opts)) (cdar opts))
1003 (else (car opts)))))
1006 `(let ((%display-usage (lambda () (display-usage-report ',usage-desc))))
1008 (let %next-arg ((%argv %argv))
1012 (lambda (%opt %arg %new-argv)
1014 ,@ transmogrified-cases))))))))
1019 ;;; {Low Level Modules}
1021 ;;; These are the low level data structures for modules.
1023 ;;; Every module object is of the type 'module-type', which is a record
1024 ;;; consisting of the following members:
1026 ;;; - eval-closure: the function that defines for its module the strategy that
1027 ;;; shall be followed when looking up symbols in the module.
1029 ;;; An eval-closure is a function taking two arguments: the symbol to be
1030 ;;; looked up and a boolean value telling whether a binding for the symbol
1031 ;;; should be created if it does not exist yet. If the symbol lookup
1032 ;;; succeeded (either because an existing binding was found or because a new
1033 ;;; binding was created), a variable object representing the binding is
1034 ;;; returned. Otherwise, the value #f is returned. Note that the eval
1035 ;;; closure does not take the module to be searched as an argument: During
1036 ;;; construction of the eval-closure, the eval-closure has to store the
1037 ;;; module it belongs to in its environment. This means, that any
1038 ;;; eval-closure can belong to only one module.
1040 ;;; The eval-closure of a module can be defined arbitrarily. However, three
1041 ;;; special cases of eval-closures are to be distinguished: During startup
1042 ;;; the module system is not yet activated. In this phase, no modules are
1043 ;;; defined and all bindings are automatically stored by the system in the
1044 ;;; pre-modules-obarray. Since no eval-closures exist at this time, the
1045 ;;; functions which require an eval-closure as their argument need to be
1046 ;;; passed the value #f.
1048 ;;; The other two special cases of eval-closures are the
1049 ;;; standard-eval-closure and the standard-interface-eval-closure. Both
1050 ;;; behave equally for the case that no new binding is to be created. The
1051 ;;; difference between the two comes in, when the boolean argument to the
1052 ;;; eval-closure indicates that a new binding shall be created if it is not
1055 ;;; Given that no new binding shall be created, both standard eval-closures
1056 ;;; define the following standard strategy of searching bindings in the
1057 ;;; module: First, the module's obarray is searched for the symbol. Second,
1058 ;;; if no binding for the symbol was found in the module's obarray, the
1059 ;;; module's binder procedure is exececuted. If this procedure did not
1060 ;;; return a binding for the symbol, the modules referenced in the module's
1061 ;;; uses list are recursively searched for a binding of the symbol. If the
1062 ;;; binding can not be found in these modules also, the symbol lookup has
1065 ;;; If a new binding shall be created, the standard-interface-eval-closure
1066 ;;; immediately returns indicating failure. That is, it does not even try
1067 ;;; to look up the symbol. In contrast, the standard-eval-closure would
1068 ;;; first search the obarray, and if no binding was found there, would
1069 ;;; create a new binding in the obarray, therefore not calling the binder
1070 ;;; procedure or searching the modules in the uses list.
1072 ;;; The explanation of the following members obarray, binder and uses
1073 ;;; assumes that the symbol lookup follows the strategy that is defined in
1074 ;;; the standard-eval-closure and the standard-interface-eval-closure.
1076 ;;; - obarray: a hash table that maps symbols to variable objects. In this
1077 ;;; hash table, the definitions are found that are local to the module (that
1078 ;;; is, not imported from other modules). When looking up bindings in the
1079 ;;; module, this hash table is searched first.
1081 ;;; - binder: either #f or a function taking a module and a symbol argument.
1082 ;;; If it is a function it is called after the obarray has been
1083 ;;; unsuccessfully searched for a binding. It then can provide bindings
1084 ;;; that would otherwise not be found locally in the module.
1086 ;;; - uses: a list of modules from which non-local bindings can be inherited.
1087 ;;; These modules are the third place queried for bindings after the obarray
1088 ;;; has been unsuccessfully searched and the binder function did not deliver
1089 ;;; a result either.
1091 ;;; - transformer: either #f or a function taking a scheme expression as
1092 ;;; delivered by read. If it is a function, it will be called to perform
1093 ;;; syntax transformations (e. g. makro expansion) on the given scheme
1094 ;;; expression. The output of the transformer function will then be passed
1095 ;;; to Guile's internal memoizer. This means that the output must be valid
1096 ;;; scheme code. The only exception is, that the output may make use of the
1097 ;;; syntax extensions provided to identify the modules that a binding
1100 ;;; - name: the name of the module. This is used for all kinds of printing
1101 ;;; outputs. In certain places the module name also serves as a way of
1102 ;;; identification. When adding a module to the uses list of another
1103 ;;; module, it is made sure that the new uses list will not contain two
1104 ;;; modules of the same name.
1106 ;;; - kind: classification of the kind of module. The value is (currently?)
1107 ;;; only used for printing. It has no influence on how a module is treated.
1108 ;;; Currently the following values are used when setting the module kind:
1109 ;;; 'module, 'directory, 'interface, 'custom-interface. If no explicit kind
1110 ;;; is set, it defaults to 'module.
1112 ;;; - duplicates-handlers
1114 ;;; - duplicates-interface
1118 ;;; - weak-observers
1122 ;;; In addition, the module may (must?) contain a binding for
1123 ;;; %module-public-interface... More explanations here...
1125 ;;; !!! warning: The interface to lazy binder procedures is going
1126 ;;; to be changed in an incompatible way to permit all the basic
1127 ;;; module ops to be virtualized.
1129 ;;; (make-module size use-list lazy-binding-proc) => module
1130 ;;; module-{obarray,uses,binder}[|-set!]
1131 ;;; (module? obj) => [#t|#f]
1132 ;;; (module-locally-bound? module symbol) => [#t|#f]
1133 ;;; (module-bound? module symbol) => [#t|#f]
1134 ;;; (module-symbol-locally-interned? module symbol) => [#t|#f]
1135 ;;; (module-symbol-interned? module symbol) => [#t|#f]
1136 ;;; (module-local-variable module symbol) => [#<variable ...> | #f]
1137 ;;; (module-variable module symbol) => [#<variable ...> | #f]
1138 ;;; (module-symbol-binding module symbol opt-value)
1139 ;;; => [ <obj> | opt-value | an error occurs ]
1140 ;;; (module-make-local-var! module symbol) => #<variable...>
1141 ;;; (module-add! module symbol var) => unspecified
1142 ;;; (module-remove! module symbol) => unspecified
1143 ;;; (module-for-each proc module) => unspecified
1144 ;;; (make-scm-module) => module ; a lazy copy of the symhash module
1145 ;;; (set-current-module module) => unspecified
1146 ;;; (current-module) => #<module...>
1152 ;;; {Printing Modules}
1155 ;; This is how modules are printed. You can re-define it.
1156 ;; (Redefining is actually more complicated than simply redefining
1157 ;; %print-module because that would only change the binding and not
1158 ;; the value stored in the vtable that determines how record are
1161 (define (%print-module mod port) ; unused args: depth length style table)
1163 (display (or (module-kind mod) "module") port)
1164 (let ((name (module-name mod)))
1168 (display name port))))
1170 (display (number->string (object-address mod) 16) port)
1175 ;; A module is characterized by an obarray in which local symbols
1176 ;; are interned, a list of modules, "uses", from which non-local
1177 ;; bindings can be inherited, and an optional lazy-binder which
1178 ;; is a (CLOSURE module symbol) which, as a last resort, can provide
1179 ;; bindings that would otherwise not be found locally in the module.
1181 ;; NOTE: If you change anything here, you also need to change
1182 ;; libguile/modules.h.
1185 (make-record-type 'module
1186 '(obarray uses binder eval-closure transformer name kind
1187 duplicates-handlers duplicates-interface
1188 observers weak-observers observer-id)
1191 ;; make-module &opt size uses binder
1193 ;; Create a new module, perhaps with a particular size of obarray,
1194 ;; initial uses list, or binding procedure.
1199 (define (parse-arg index default)
1200 (if (> (length args) index)
1201 (list-ref args index)
1204 (if (> (length args) 3)
1205 (error "Too many args to make-module." args))
1207 (let ((size (parse-arg 0 31))
1208 (uses (parse-arg 1 '()))
1209 (binder (parse-arg 2 #f)))
1211 (if (not (integer? size))
1212 (error "Illegal size to make-module." size))
1213 (if (not (and (list? uses)
1214 (and-map module? uses)))
1215 (error "Incorrect use list." uses))
1216 (if (and binder (not (procedure? binder)))
1218 "Lazy-binder expected to be a procedure or #f." binder))
1220 (let ((module (module-constructor (make-hash-table size)
1221 uses binder #f #f #f #f #f #f
1223 (make-weak-value-hash-table 31)
1226 ;; We can't pass this as an argument to module-constructor,
1227 ;; because we need it to close over a pointer to the module
1229 (set-module-eval-closure! module (standard-eval-closure module))
1233 (define module-constructor (record-constructor module-type))
1234 (define module-obarray (record-accessor module-type 'obarray))
1235 (define set-module-obarray! (record-modifier module-type 'obarray))
1236 (define module-uses (record-accessor module-type 'uses))
1237 (define set-module-uses! (record-modifier module-type 'uses))
1238 (define module-binder (record-accessor module-type 'binder))
1239 (define set-module-binder! (record-modifier module-type 'binder))
1241 ;; NOTE: This binding is used in libguile/modules.c.
1242 (define module-eval-closure (record-accessor module-type 'eval-closure))
1244 (define module-transformer (record-accessor module-type 'transformer))
1245 (define set-module-transformer! (record-modifier module-type 'transformer))
1246 (define module-name (record-accessor module-type 'name))
1247 (define set-module-name! (record-modifier module-type 'name))
1248 (define module-kind (record-accessor module-type 'kind))
1249 (define set-module-kind! (record-modifier module-type 'kind))
1250 (define module-duplicates-handlers
1251 (record-accessor module-type 'duplicates-handlers))
1252 (define set-module-duplicates-handlers!
1253 (record-modifier module-type 'duplicates-handlers))
1254 (define module-duplicates-interface
1255 (record-accessor module-type 'duplicates-interface))
1256 (define set-module-duplicates-interface!
1257 (record-modifier module-type 'duplicates-interface))
1258 (define module-observers (record-accessor module-type 'observers))
1259 (define set-module-observers! (record-modifier module-type 'observers))
1260 (define module-weak-observers (record-accessor module-type 'weak-observers))
1261 (define module-observer-id (record-accessor module-type 'observer-id))
1262 (define set-module-observer-id! (record-modifier module-type 'observer-id))
1263 (define module? (record-predicate module-type))
1265 (define set-module-eval-closure!
1266 (let ((setter (record-modifier module-type 'eval-closure)))
1267 (lambda (module closure)
1268 (setter module closure)
1269 ;; Make it possible to lookup the module from the environment.
1270 ;; This implementation is correct since an eval closure can belong
1271 ;; to maximally one module.
1272 (set-procedure-property! closure 'module module))))
1276 ;;; {Observer protocol}
1279 (define (module-observe module proc)
1280 (set-module-observers! module (cons proc (module-observers module)))
1283 (define (module-observe-weak module proc)
1284 (let ((id (module-observer-id module)))
1285 (hash-set! (module-weak-observers module) id proc)
1286 (set-module-observer-id! module (+ 1 id))
1289 (define (module-unobserve token)
1290 (let ((module (car token))
1293 (hash-remove! (module-weak-observers module) id)
1294 (set-module-observers! module (delq1! id (module-observers module)))))
1297 (define module-defer-observers #f)
1298 (define module-defer-observers-mutex (make-mutex))
1299 (define module-defer-observers-table (make-hash-table))
1301 (define (module-modified m)
1302 (if module-defer-observers
1303 (hash-set! module-defer-observers-table m #t)
1304 (module-call-observers m)))
1306 ;;; This function can be used to delay calls to observers so that they
1307 ;;; can be called once only in the face of massive updating of modules.
1309 (define (call-with-deferred-observers thunk)
1312 (lock-mutex module-defer-observers-mutex)
1313 (set! module-defer-observers #t))
1316 (set! module-defer-observers #f)
1317 (hash-for-each (lambda (m dummy)
1318 (module-call-observers m))
1319 module-defer-observers-table)
1320 (hash-clear! module-defer-observers-table)
1321 (unlock-mutex module-defer-observers-mutex))))
1323 (define (module-call-observers m)
1324 (for-each (lambda (proc) (proc m)) (module-observers m))
1325 (hash-fold (lambda (id proc res) (proc m)) #f (module-weak-observers m)))
1329 ;;; {Module Searching in General}
1331 ;;; We sometimes want to look for properties of a symbol
1332 ;;; just within the obarray of one module. If the property
1333 ;;; holds, then it is said to hold ``locally'' as in, ``The symbol
1334 ;;; DISPLAY is locally rebound in the module `safe-guile'.''
1337 ;;; Other times, we want to test for a symbol property in the obarray
1338 ;;; of M and, if it is not found there, try each of the modules in the
1339 ;;; uses list of M. This is the normal way of testing for some
1340 ;;; property, so we state these properties without qualification as
1341 ;;; in: ``The symbol 'fnord is interned in module M because it is
1342 ;;; interned locally in module M2 which is a member of the uses list
1346 ;; module-search fn m
1348 ;; return the first non-#f result of FN applied to M and then to
1349 ;; the modules in the uses of m, and so on recursively. If all applications
1350 ;; return #f, then so does this function.
1352 (define (module-search fn m v)
1355 (or (module-search fn (car pos) v)
1358 (loop (module-uses m))))
1361 ;;; {Is a symbol bound in a module?}
1363 ;;; Symbol S in Module M is bound if S is interned in M and if the binding
1364 ;;; of S in M has been set to some well-defined value.
1367 ;; module-locally-bound? module symbol
1369 ;; Is a symbol bound (interned and defined) locally in a given module?
1371 (define (module-locally-bound? m v)
1372 (let ((var (module-local-variable m v)))
1374 (variable-bound? var))))
1376 ;; module-bound? module symbol
1378 ;; Is a symbol bound (interned and defined) anywhere in a given module
1381 (define (module-bound? m v)
1382 (module-search module-locally-bound? m v))
1384 ;;; {Is a symbol interned in a module?}
1386 ;;; Symbol S in Module M is interned if S occurs in
1387 ;;; of S in M has been set to some well-defined value.
1389 ;;; It is possible to intern a symbol in a module without providing
1390 ;;; an initial binding for the corresponding variable. This is done
1392 ;;; (module-add! module symbol (make-undefined-variable))
1394 ;;; In that case, the symbol is interned in the module, but not
1395 ;;; bound there. The unbound symbol shadows any binding for that
1396 ;;; symbol that might otherwise be inherited from a member of the uses list.
1399 (define (module-obarray-get-handle ob key)
1400 ((if (symbol? key) hashq-get-handle hash-get-handle) ob key))
1402 (define (module-obarray-ref ob key)
1403 ((if (symbol? key) hashq-ref hash-ref) ob key))
1405 (define (module-obarray-set! ob key val)
1406 ((if (symbol? key) hashq-set! hash-set!) ob key val))
1408 (define (module-obarray-remove! ob key)
1409 ((if (symbol? key) hashq-remove! hash-remove!) ob key))
1411 ;; module-symbol-locally-interned? module symbol
1413 ;; is a symbol interned (not neccessarily defined) locally in a given module
1414 ;; or its uses? Interned symbols shadow inherited bindings even if
1415 ;; they are not themselves bound to a defined value.
1417 (define (module-symbol-locally-interned? m v)
1418 (not (not (module-obarray-get-handle (module-obarray m) v))))
1420 ;; module-symbol-interned? module symbol
1422 ;; is a symbol interned (not neccessarily defined) anywhere in a given module
1423 ;; or its uses? Interned symbols shadow inherited bindings even if
1424 ;; they are not themselves bound to a defined value.
1426 (define (module-symbol-interned? m v)
1427 (module-search module-symbol-locally-interned? m v))
1430 ;;; {Mapping modules x symbols --> variables}
1433 ;; module-local-variable module symbol
1434 ;; return the local variable associated with a MODULE and SYMBOL.
1436 ;;; This function is very important. It is the only function that can
1437 ;;; return a variable from a module other than the mutators that store
1438 ;;; new variables in modules. Therefore, this function is the location
1439 ;;; of the "lazy binder" hack.
1441 ;;; If symbol is defined in MODULE, and if the definition binds symbol
1442 ;;; to a variable, return that variable object.
1444 ;;; If the symbols is not found at first, but the module has a lazy binder,
1445 ;;; then try the binder.
1447 ;;; If the symbol is not found at all, return #f.
1449 (define (module-local-variable m v)
1452 (let ((b (module-obarray-ref (module-obarray m) v)))
1453 (or (and (variable? b) b)
1454 (and (module-binder m)
1455 ((module-binder m) m v #f)))))
1458 ;; module-variable module symbol
1460 ;; like module-local-variable, except search the uses in the
1461 ;; case V is not found in M.
1463 ;; NOTE: This function is superseded with C code (see modules.c)
1464 ;;; when using the standard eval closure.
1466 (define (module-variable m v)
1467 (module-search module-local-variable m v))
1470 ;;; {Mapping modules x symbols --> bindings}
1472 ;;; These are similar to the mapping to variables, except that the
1473 ;;; variable is dereferenced.
1476 ;; module-symbol-binding module symbol opt-value
1478 ;; return the binding of a variable specified by name within
1479 ;; a given module, signalling an error if the variable is unbound.
1480 ;; If the OPT-VALUE is passed, then instead of signalling an error,
1481 ;; return OPT-VALUE.
1483 (define (module-symbol-local-binding m v . opt-val)
1484 (let ((var (module-local-variable m v)))
1485 (if (and var (variable-bound? var))
1487 (if (not (null? opt-val))
1489 (error "Locally unbound variable." v)))))
1491 ;; module-symbol-binding module symbol opt-value
1493 ;; return the binding of a variable specified by name within
1494 ;; a given module, signalling an error if the variable is unbound.
1495 ;; If the OPT-VALUE is passed, then instead of signalling an error,
1496 ;; return OPT-VALUE.
1498 (define (module-symbol-binding m v . opt-val)
1499 (let ((var (module-variable m v)))
1500 (if (and var (variable-bound? var))
1502 (if (not (null? opt-val))
1504 (error "Unbound variable." v)))))
1509 ;;; {Adding Variables to Modules}
1512 ;; module-make-local-var! module symbol
1514 ;; ensure a variable for V in the local namespace of M.
1515 ;; If no variable was already there, then create a new and uninitialzied
1518 ;; This function is used in modules.c.
1520 (define (module-make-local-var! m v)
1521 (or (let ((b (module-obarray-ref (module-obarray m) v)))
1524 ;; Mark as modified since this function is called when
1525 ;; the standard eval closure defines a binding
1529 ;; No local variable yet, so we need to create a new one. That
1530 ;; new variable is initialized with the old imported value of V,
1532 (let ((imported-var (module-variable m v))
1533 (local-var (or (and (module-binder m)
1534 ((module-binder m) m v #t))
1536 (let ((answer (make-undefined-variable)))
1537 (module-add! m v answer)
1539 (if (and imported-var (not (variable-bound? local-var)))
1540 (variable-set! local-var (variable-ref imported-var)))
1543 ;; module-ensure-local-variable! module symbol
1545 ;; Ensure that there is a local variable in MODULE for SYMBOL. If
1546 ;; there is no binding for SYMBOL, create a new uninitialized
1547 ;; variable. Return the local variable.
1549 (define (module-ensure-local-variable! module symbol)
1550 (or (module-local-variable module symbol)
1551 (let ((var (make-undefined-variable)))
1552 (module-add! module symbol var)
1555 ;; module-add! module symbol var
1557 ;; ensure a particular variable for V in the local namespace of M.
1559 (define (module-add! m v var)
1560 (if (not (variable? var))
1561 (error "Bad variable to module-add!" var))
1562 (module-obarray-set! (module-obarray m) v var)
1563 (module-modified m))
1567 ;; make sure that a symbol is undefined in the local namespace of M.
1569 (define (module-remove! m v)
1570 (module-obarray-remove! (module-obarray m) v)
1571 (module-modified m))
1573 (define (module-clear! m)
1574 (hash-clear! (module-obarray m))
1575 (module-modified m))
1577 ;; MODULE-FOR-EACH -- exported
1579 ;; Call PROC on each symbol in MODULE, with arguments of (SYMBOL VARIABLE).
1581 (define (module-for-each proc module)
1582 (hash-for-each proc (module-obarray module)))
1584 (define (module-map proc module)
1585 (hash-map->list proc (module-obarray module)))
1589 ;;; {Low Level Bootstrapping}
1594 ;; A root module uses the pre-modules-obarray as its obarray. This
1595 ;; special obarray accumulates all bindings that have been established
1596 ;; before the module system is fully booted.
1598 ;; (The obarray continues to be used by code that has been closed over
1599 ;; before the module system has been booted.)
1601 (define (make-root-module)
1602 (let ((m (make-module 0)))
1603 (set-module-obarray! m (%get-pre-modules-obarray))
1608 ;; The root interface is a module that uses the same obarray as the
1609 ;; root module. It does not allow new definitions, tho.
1611 (define (make-scm-module)
1612 (let ((m (make-module 0)))
1613 (set-module-obarray! m (%get-pre-modules-obarray))
1614 (set-module-eval-closure! m (standard-interface-eval-closure m))
1620 ;;; {Module-based Loading}
1623 (define (save-module-excursion thunk)
1624 (let ((inner-module (current-module))
1626 (dynamic-wind (lambda ()
1627 (set! outer-module (current-module))
1628 (set-current-module inner-module)
1629 (set! inner-module #f))
1632 (set! inner-module (current-module))
1633 (set-current-module outer-module)
1634 (set! outer-module #f)))))
1636 (define basic-load load)
1638 (define (load-module filename . reader)
1639 (save-module-excursion
1641 (let ((oldname (and (current-load-port)
1642 (port-filename (current-load-port)))))
1645 (> (string-length filename) 0)
1646 (not (char=? (string-ref filename 0) #\/))
1647 (not (string=? (dirname oldname) ".")))
1648 (string-append (dirname oldname) "/" filename)
1655 ;;; {MODULE-REF -- exported}
1658 ;; Returns the value of a variable called NAME in MODULE or any of its
1659 ;; used modules. If there is no such variable, then if the optional third
1660 ;; argument DEFAULT is present, it is returned; otherwise an error is signaled.
1662 (define (module-ref module name . rest)
1663 (let ((variable (module-variable module name)))
1664 (if (and variable (variable-bound? variable))
1665 (variable-ref variable)
1667 (error "No variable named" name 'in module)
1668 (car rest) ; default value
1671 ;; MODULE-SET! -- exported
1673 ;; Sets the variable called NAME in MODULE (or in a module that MODULE uses)
1674 ;; to VALUE; if there is no such variable, an error is signaled.
1676 (define (module-set! module name value)
1677 (let ((variable (module-variable module name)))
1679 (variable-set! variable value)
1680 (error "No variable named" name 'in module))))
1682 ;; MODULE-DEFINE! -- exported
1684 ;; Sets the variable called NAME in MODULE to VALUE; if there is no such
1685 ;; variable, it is added first.
1687 (define (module-define! module name value)
1688 (let ((variable (module-local-variable module name)))
1691 (variable-set! variable value)
1692 (module-modified module))
1693 (let ((variable (make-variable value)))
1694 (module-add! module name variable)))))
1696 ;; MODULE-DEFINED? -- exported
1698 ;; Return #t iff NAME is defined in MODULE (or in a module that MODULE
1701 (define (module-defined? module name)
1702 (let ((variable (module-variable module name)))
1703 (and variable (variable-bound? variable))))
1705 ;; MODULE-USE! module interface
1707 ;; Add INTERFACE to the list of interfaces used by MODULE.
1709 (define (module-use! module interface)
1710 (set-module-uses! module
1713 (not (equal? (module-name m)
1714 (module-name interface))))
1715 (module-uses module))))
1716 (module-modified module))
1718 ;; MODULE-USE-INTERFACES! module interfaces
1720 ;; Same as MODULE-USE! but add multiple interfaces and check for duplicates
1722 (define (module-use-interfaces! module interfaces)
1723 (let* ((duplicates-handlers? (or (module-duplicates-handlers module)
1724 (default-duplicate-binding-procedures)))
1725 (uses (module-uses module)))
1726 ;; remove duplicates-interface
1727 (set! uses (delq! (module-duplicates-interface module) uses))
1728 ;; remove interfaces to be added
1729 (for-each (lambda (interface)
1732 (not (equal? (module-name m)
1733 (module-name interface))))
1736 ;; add interfaces to use list
1737 (set-module-uses! module uses)
1738 (for-each (lambda (interface)
1739 (and duplicates-handlers?
1740 ;; perform duplicate checking
1741 (process-duplicates module interface))
1742 (set! uses (cons interface uses))
1743 (set-module-uses! module uses))
1745 ;; add duplicates interface
1746 (if (module-duplicates-interface module)
1747 (set-module-uses! module
1748 (cons (module-duplicates-interface module) uses)))
1749 (module-modified module)))
1753 ;;; {Recursive Namespaces}
1755 ;;; A hierarchical namespace emerges if we consider some module to be
1756 ;;; root, and variables bound to modules as nested namespaces.
1758 ;;; The routines in this file manage variable names in hierarchical namespace.
1759 ;;; Each variable name is a list of elements, looked up in successively nested
1762 ;;; (nested-ref some-root-module '(foo bar baz))
1763 ;;; => <value of a variable named baz in the module bound to bar in
1764 ;;; the module bound to foo in some-root-module>
1769 ;;; ;; a-root is a module
1770 ;;; ;; name is a list of symbols
1772 ;;; nested-ref a-root name
1773 ;;; nested-set! a-root name val
1774 ;;; nested-define! a-root name val
1775 ;;; nested-remove! a-root name
1778 ;;; (current-module) is a natural choice for a-root so for convenience there are
1781 ;;; local-ref name == nested-ref (current-module) name
1782 ;;; local-set! name val == nested-set! (current-module) name val
1783 ;;; local-define! name val == nested-define! (current-module) name val
1784 ;;; local-remove! name == nested-remove! (current-module) name
1788 (define (nested-ref root names)
1789 (let loop ((cur root)
1793 ((not (module? cur)) #f)
1794 (else (loop (module-ref cur (car elts) #f) (cdr elts))))))
1796 (define (nested-set! root names val)
1797 (let loop ((cur root)
1799 (if (null? (cdr elts))
1800 (module-set! cur (car elts) val)
1801 (loop (module-ref cur (car elts)) (cdr elts)))))
1803 (define (nested-define! root names val)
1804 (let loop ((cur root)
1806 (if (null? (cdr elts))
1807 (module-define! cur (car elts) val)
1808 (loop (module-ref cur (car elts)) (cdr elts)))))
1810 (define (nested-remove! root names)
1811 (let loop ((cur root)
1813 (if (null? (cdr elts))
1814 (module-remove! cur (car elts))
1815 (loop (module-ref cur (car elts)) (cdr elts)))))
1817 (define (local-ref names) (nested-ref (current-module) names))
1818 (define (local-set! names val) (nested-set! (current-module) names val))
1819 (define (local-define names val) (nested-define! (current-module) names val))
1820 (define (local-remove names) (nested-remove! (current-module) names))
1825 ;;; {The (%app) module}
1827 ;;; The root of conventionally named objects not directly in the top level.
1830 ;;; (%app modules guile)
1832 ;;; The directory of all modules and the standard root module.
1835 (define (module-public-interface m)
1836 (module-ref m '%module-public-interface #f))
1837 (define (set-module-public-interface! m i)
1838 (module-define! m '%module-public-interface i))
1839 (define (set-system-module! m s)
1840 (set-procedure-property! (module-eval-closure m) 'system-module s))
1841 (define the-root-module (make-root-module))
1842 (define the-scm-module (make-scm-module))
1843 (set-module-public-interface! the-root-module the-scm-module)
1844 (set-module-name! the-root-module '(guile))
1845 (set-module-name! the-scm-module '(guile))
1846 (set-module-kind! the-scm-module 'interface)
1847 (for-each set-system-module! (list the-root-module the-scm-module) '(#t #t))
1849 ;; NOTE: This binding is used in libguile/modules.c.
1851 (define (make-modules-in module name)
1855 ((module-ref module (car name) #f)
1856 => (lambda (m) (make-modules-in m (cdr name))))
1857 (else (let ((m (make-module 31)))
1858 (set-module-kind! m 'directory)
1859 (set-module-name! m (append (or (module-name module)
1862 (module-define! module (car name) m)
1863 (make-modules-in m (cdr name)))))))
1865 (define (beautify-user-module! module)
1866 (let ((interface (module-public-interface module)))
1867 (if (or (not interface)
1868 (eq? interface module))
1869 (let ((interface (make-module 31)))
1870 (set-module-name! interface (module-name module))
1871 (set-module-kind! interface 'interface)
1872 (set-module-public-interface! module interface))))
1873 (if (and (not (memq the-scm-module (module-uses module)))
1874 (not (eq? module the-root-module)))
1875 (set-module-uses! module
1876 (append (module-uses module) (list the-scm-module)))))
1878 ;; NOTE: This binding is used in libguile/modules.c.
1880 (define (resolve-module name . maybe-autoload)
1881 (let ((full-name (append '(%app modules) name)))
1882 (let ((already (nested-ref the-root-module full-name)))
1884 ;; The module already exists...
1885 (if (and (or (null? maybe-autoload) (car maybe-autoload))
1886 (not (module-public-interface already)))
1887 ;; ...but we are told to load and it doesn't contain source, so
1889 (try-load-module name)
1891 ;; simply return it.
1894 ;; Try to autoload it if we are told so
1895 (if (or (null? maybe-autoload) (car maybe-autoload))
1896 (try-load-module name))
1898 (make-modules-in (current-module) full-name))))))
1900 ;; Cheat. These bindings are needed by modules.c, but we don't want
1901 ;; to move their real definition here because that would be unnatural.
1903 (define try-module-autoload #f)
1904 (define process-define-module #f)
1905 (define process-use-modules #f)
1906 (define module-export! #f)
1908 ;; This boots the module system. All bindings needed by modules.c
1909 ;; must have been defined by now.
1911 (set-current-module the-root-module)
1913 (define %app (make-module 31))
1914 (define app %app) ;; for backwards compatability
1915 (local-define '(%app modules) (make-module 31))
1916 (local-define '(%app modules guile) the-root-module)
1918 ;; (define-special-value '(%app modules new-ws) (lambda () (make-scm-module)))
1920 (define (try-load-module name)
1921 (or (begin-deprecated (try-module-linked name))
1922 (try-module-autoload name)
1923 (begin-deprecated (try-module-dynamic-link name))))
1925 (define (purify-module! module)
1926 "Removes bindings in MODULE which are inherited from the (guile) module."
1927 (let ((use-list (module-uses module)))
1928 (if (and (pair? use-list)
1929 (eq? (car (last-pair use-list)) the-scm-module))
1930 (set-module-uses! module (reverse (cdr (reverse use-list)))))))
1932 ;; Return a module that is an interface to the module designated by
1935 ;; `resolve-interface' takes four keyword arguments:
1937 ;; #:select SELECTION
1939 ;; SELECTION is a list of binding-specs to be imported; A binding-spec
1940 ;; is either a symbol or a pair of symbols (ORIG . SEEN), where ORIG
1941 ;; is the name in the used module and SEEN is the name in the using
1942 ;; module. Note that SEEN is also passed through RENAMER, below. The
1943 ;; default is to select all bindings. If you specify no selection but
1944 ;; a renamer, only the bindings that already exist in the used module
1945 ;; are made available in the interface. Bindings that are added later
1946 ;; are not picked up.
1950 ;; BINDINGS is a list of bindings which should not be imported.
1954 ;; PREFIX is a symbol that will be appended to each exported name.
1955 ;; The default is to not perform any renaming.
1957 ;; #:renamer RENAMER
1959 ;; RENAMER is a procedure that takes a symbol and returns its new
1960 ;; name. The default is not perform any renaming.
1962 ;; Signal "no code for module" error if module name is not resolvable
1963 ;; or its public interface is not available. Signal "no binding"
1964 ;; error if selected binding does not exist in the used module.
1966 (define (resolve-interface name . args)
1968 (define (get-keyword-arg args kw def)
1969 (cond ((memq kw args)
1971 (if (null? (cdr kw-arg))
1972 (error "keyword without value: " kw))
1977 (let* ((select (get-keyword-arg args #:select #f))
1978 (hide (get-keyword-arg args #:hide '()))
1979 (renamer (or (get-keyword-arg args #:renamer #f)
1980 (let ((prefix (get-keyword-arg args #:prefix #f)))
1981 (and prefix (symbol-prefix-proc prefix)))
1983 (module (resolve-module name))
1984 (public-i (and module (module-public-interface module))))
1985 (and (or (not module) (not public-i))
1986 (error "no code for module" name))
1987 (if (and (not select) (null? hide) (eq? renamer identity))
1989 (let ((selection (or select (module-map (lambda (sym var) sym)
1991 (custom-i (make-module 31)))
1992 (set-module-kind! custom-i 'custom-interface)
1993 (set-module-name! custom-i name)
1994 ;; XXX - should use a lazy binder so that changes to the
1995 ;; used module are picked up automatically.
1996 (for-each (lambda (bspec)
1997 (let* ((direct? (symbol? bspec))
1998 (orig (if direct? bspec (car bspec)))
1999 (seen (if direct? bspec (cdr bspec)))
2000 (var (or (module-local-variable public-i orig)
2001 (module-local-variable module orig)
2003 ;; fixme: format manually for now
2005 #f "no binding `~A' in module ~A"
2007 (if (memq orig hide)
2008 (set! hide (delq! orig hide))
2009 (module-add! custom-i
2013 ;; Check that we are not hiding bindings which don't exist
2014 (for-each (lambda (binding)
2015 (if (not (module-local-variable public-i binding))
2018 #f "no binding `~A' to hide in module ~A"
2023 (define (symbol-prefix-proc prefix)
2025 (symbol-append prefix symbol)))
2027 ;; This function is called from "modules.c". If you change it, be
2028 ;; sure to update "modules.c" as well.
2030 (define (process-define-module args)
2031 (let* ((module-id (car args))
2032 (module (resolve-module module-id #f))
2034 (unrecognized (lambda (arg)
2035 (error "unrecognized define-module argument" arg))))
2036 (beautify-user-module! module)
2037 (let loop ((kws kws)
2038 (reversed-interfaces '())
2044 (call-with-deferred-observers
2046 (module-use-interfaces! module (reverse reversed-interfaces))
2047 (module-export! module exports)
2048 (module-replace! module replacements)
2049 (module-re-export! module re-exports)))
2051 ((#:use-module #:use-syntax)
2052 (or (pair? (cdr kws))
2054 (let* ((interface-args (cadr kws))
2055 (interface (apply resolve-interface interface-args)))
2056 (and (eq? (car kws) #:use-syntax)
2057 (or (symbol? (caar interface-args))
2058 (error "invalid module name for use-syntax"
2059 (car interface-args)))
2060 (set-module-transformer!
2062 (module-ref interface
2063 (car (last-pair (car interface-args)))
2066 (cons interface reversed-interfaces)
2071 (or (and (pair? (cdr kws)) (pair? (cddr kws)))
2074 (cons (make-autoload-interface module
2077 reversed-interfaces)
2082 (set-system-module! module #t)
2083 (loop (cdr kws) reversed-interfaces exports re-exports replacements))
2085 (purify-module! module)
2086 (loop (cdr kws) reversed-interfaces exports re-exports replacements))
2088 (if (not (pair? (cdr kws)))
2090 (set-module-duplicates-handlers!
2092 (lookup-duplicates-handlers (cadr kws)))
2093 (loop (cddr kws) reversed-interfaces exports re-exports replacements))
2094 ((#:export #:export-syntax)
2095 (or (pair? (cdr kws))
2099 (append (cadr kws) exports)
2102 ((#:re-export #:re-export-syntax)
2103 (or (pair? (cdr kws))
2108 (append (cadr kws) re-exports)
2110 ((#:replace #:replace-syntax)
2111 (or (pair? (cdr kws))
2117 (append (cadr kws) replacements)))
2119 (unrecognized kws)))))
2120 (run-hook module-defined-hook module)
2123 ;; `module-defined-hook' is a hook that is run whenever a new module
2124 ;; is defined. Its members are called with one argument, the new
2126 (define module-defined-hook (make-hook 1))
2133 (define (make-autoload-interface module name bindings)
2134 (let ((b (lambda (a sym definep)
2135 (and (memq sym bindings)
2136 (let ((i (module-public-interface (resolve-module name))))
2138 (error "missing interface for module" name))
2139 ;; Replace autoload-interface with interface
2140 (set-car! (memq a (module-uses module)) i)
2141 (module-local-variable i sym))))))
2142 (module-constructor (make-hash-table 0) '() b #f #f name 'autoload #f #f
2143 '() (make-weak-value-hash-table 31) 0)))
2145 ;;; {Compiled module}
2147 (define load-compiled #f)
2151 ;;; {Autoloading modules}
2154 (define autoloads-in-progress '())
2156 ;; This function is called from "modules.c". If you change it, be
2157 ;; sure to update "modules.c" as well.
2159 (define (try-module-autoload module-name)
2160 (let* ((reverse-name (reverse module-name))
2161 (name (symbol->string (car reverse-name)))
2162 (dir-hint-module-name (reverse (cdr reverse-name)))
2163 (dir-hint (apply string-append
2165 (string-append (symbol->string elt) "/"))
2166 dir-hint-module-name))))
2167 (resolve-module dir-hint-module-name #f)
2168 (and (not (autoload-done-or-in-progress? dir-hint name))
2170 (define (load-file proc file)
2171 (save-module-excursion (lambda () (proc file)))
2174 (lambda () (autoload-in-progress! dir-hint name))
2176 (let ((file (in-vicinity dir-hint name)))
2177 (cond ((and load-compiled
2178 (%search-load-path (string-append file ".go")))
2180 (load-file load-compiled full)))
2181 ((%search-load-path file)
2183 (load-file primitive-load full))))))
2184 (lambda () (set-autoloaded! dir-hint name didit)))
2189 ;;; {Dynamic linking of modules}
2192 (define autoloads-done '((guile . guile)))
2194 (define (autoload-done-or-in-progress? p m)
2195 (let ((n (cons p m)))
2196 (->bool (or (member n autoloads-done)
2197 (member n autoloads-in-progress)))))
2199 (define (autoload-done! p m)
2200 (let ((n (cons p m)))
2201 (set! autoloads-in-progress
2202 (delete! n autoloads-in-progress))
2203 (or (member n autoloads-done)
2204 (set! autoloads-done (cons n autoloads-done)))))
2206 (define (autoload-in-progress! p m)
2207 (let ((n (cons p m)))
2208 (set! autoloads-done
2209 (delete! n autoloads-done))
2210 (set! autoloads-in-progress (cons n autoloads-in-progress))))
2212 (define (set-autoloaded! p m done?)
2214 (autoload-done! p m)
2215 (let ((n (cons p m)))
2216 (set! autoloads-done (delete! n autoloads-done))
2217 (set! autoloads-in-progress (delete! n autoloads-in-progress)))))
2221 ;;; {Run-time options}
2224 (define define-option-interface
2225 (let* ((option-name car)
2227 (option-documentation caddr)
2229 (print-option (lambda (option)
2230 (display (option-name option))
2231 (if (< (string-length
2232 (symbol->string (option-name option)))
2236 (display (option-value option))
2238 (display (option-documentation option))
2241 ;; Below follow the macros defining the run-time option interfaces.
2243 (make-options (lambda (interface)
2245 (cond ((null? args) (,interface))
2247 (,interface (car args)) (,interface))
2248 (else (for-each ,print-option
2249 (,interface #t)))))))
2251 (make-enable (lambda (interface)
2253 (,interface (append flags (,interface)))
2256 (make-disable (lambda (interface)
2258 (let ((options (,interface)))
2259 (for-each (lambda (flag)
2260 (set! options (delq! flag options)))
2262 (,interface options)
2264 (procedure->memoizing-macro
2266 (let* ((option-group (cadr exp))
2267 (interface (car option-group))
2268 (options/enable/disable (cadr option-group)))
2270 (define ,(car options/enable/disable)
2271 ,(make-options interface))
2272 (define ,(cadr options/enable/disable)
2273 ,(make-enable interface))
2274 (define ,(caddr options/enable/disable)
2275 ,(make-disable interface))
2276 (defmacro ,(caaddr option-group) (opt val)
2277 `(,,(car options/enable/disable)
2278 (append (,,(car options/enable/disable))
2279 (list ',opt ,val))))))))))
2281 (define-option-interface
2282 (eval-options-interface
2283 (eval-options eval-enable eval-disable)
2286 (define-option-interface
2287 (debug-options-interface
2288 (debug-options debug-enable debug-disable)
2291 (define-option-interface
2292 (evaluator-traps-interface
2293 (traps trap-enable trap-disable)
2296 (define-option-interface
2297 (read-options-interface
2298 (read-options read-enable read-disable)
2301 (define-option-interface
2302 (print-options-interface
2303 (print-options print-enable print-disable)
2311 (define (repl read evaler print)
2312 (let loop ((source (read (current-input-port))))
2313 (print (evaler source))
2314 (loop (read (current-input-port)))))
2316 ;; A provisional repl that acts like the SCM repl:
2318 (define scm-repl-silent #f)
2319 (define (assert-repl-silence v) (set! scm-repl-silent v))
2321 (define *unspecified* (if #f #f))
2322 (define (unspecified? v) (eq? v *unspecified*))
2324 (define scm-repl-print-unspecified #f)
2325 (define (assert-repl-print-unspecified v) (set! scm-repl-print-unspecified v))
2327 (define scm-repl-verbose #f)
2328 (define (assert-repl-verbosity v) (set! scm-repl-verbose v))
2330 (define scm-repl-prompt "guile> ")
2332 (define (set-repl-prompt! v) (set! scm-repl-prompt v))
2334 (define (default-lazy-handler key . args)
2335 (save-stack lazy-handler-dispatch)
2336 (apply throw key args))
2338 (define (lazy-handler-dispatch key . args)
2339 (apply default-lazy-handler key args))
2341 (define abort-hook (make-hook))
2343 ;; these definitions are used if running a script.
2344 ;; otherwise redefined in error-catching-loop.
2345 (define (set-batch-mode?! arg) #t)
2346 (define (batch-mode?) #t)
2348 (define (error-catching-loop thunk)
2351 (define (loop first)
2358 (call-with-unblocked-asyncs
2364 ;; This line is needed because mark
2365 ;; doesn't do closures quite right.
2366 ;; Unreferenced locals should be
2370 (let loop ((v (thunk)))
2374 ;; Note that having just
2375 ;; `lazy-handler-dispatch' here is
2376 ;; connected with the mechanism that
2377 ;; produces a nice backtrace upon
2378 ;; error. If, for example, this is
2379 ;; replaced with (lambda args (apply
2380 ;; lazy-handler-dispatch args)), the
2381 ;; stack cutting (in save-stack)
2382 ;; goes wrong and ends up saving no
2383 ;; stack at all, so there is no
2385 lazy-handler-dispatch))
2387 (lambda (key . args)
2394 (apply throw 'switch-repl args))
2397 ;; This is one of the closures that require
2398 ;; (set! first #f) above
2401 (run-hook abort-hook)
2402 (force-output (current-output-port))
2403 (display "ABORT: " (current-error-port))
2404 (write args (current-error-port))
2405 (newline (current-error-port))
2409 (not has-shown-debugger-hint?)
2410 (not (memq 'backtrace
2411 (debug-options-interface)))
2412 (stack? (fluid-ref the-last-stack)))
2414 (newline (current-error-port))
2416 "Type \"(backtrace)\" to get more information or \"(debug)\" to enter the debugger.\n"
2417 (current-error-port))
2418 (set! has-shown-debugger-hint? #t)))
2419 (force-output (current-error-port)))
2421 (primitive-exit 1)))
2422 (set! stack-saved? #f)))
2425 ;; This is the other cons-leak closure...
2427 (cond ((= (length args) 4)
2428 (apply handle-system-error key args))
2430 (apply bad-throw key args))))))))))
2431 (if next (loop next) status)))
2432 (set! set-batch-mode?! (lambda (arg)
2434 (set! interactive #f)
2437 (error "sorry, not implemented")))))
2438 (set! batch-mode? (lambda () (not interactive)))
2439 (call-with-blocked-asyncs
2440 (lambda () (loop (lambda () #t))))))
2442 ;;(define the-last-stack (make-fluid)) Defined by scm_init_backtrace ()
2443 (define before-signal-stack (make-fluid))
2444 (define stack-saved? #f)
2446 (define (save-stack . narrowing)
2448 (cond ((not (memq 'debug (debug-options-interface)))
2449 (fluid-set! the-last-stack #f)
2450 (set! stack-saved? #t))
2456 (apply make-stack #t save-stack primitive-eval #t 0 narrowing))
2458 (apply make-stack #t save-stack 0 #t 0 narrowing))
2460 (apply make-stack #t save-stack tk-stack-mark #t 0 narrowing))
2462 (apply make-stack #t save-stack 0 1 narrowing))
2464 (let ((id (stack-id #t)))
2465 (and (procedure? id)
2466 (apply make-stack #t save-stack id #t 0 narrowing))))))
2467 (set! stack-saved? #t)))))
2469 (define before-error-hook (make-hook))
2470 (define after-error-hook (make-hook))
2471 (define before-backtrace-hook (make-hook))
2472 (define after-backtrace-hook (make-hook))
2474 (define has-shown-debugger-hint? #f)
2476 (define (handle-system-error key . args)
2477 (let ((cep (current-error-port)))
2478 (cond ((not (stack? (fluid-ref the-last-stack))))
2479 ((memq 'backtrace (debug-options-interface))
2480 (let ((highlights (if (or (eq? key 'wrong-type-arg)
2481 (eq? key 'out-of-range))
2484 (run-hook before-backtrace-hook)
2486 (display "Backtrace:\n")
2487 (display-backtrace (fluid-ref the-last-stack) cep
2490 (run-hook after-backtrace-hook))))
2491 (run-hook before-error-hook)
2492 (apply display-error (fluid-ref the-last-stack) cep args)
2493 (run-hook after-error-hook)
2495 (throw 'abort key)))
2497 (define (quit . args)
2498 (apply throw 'quit args))
2502 ;;(define has-shown-backtrace-hint? #f) Defined by scm_init_backtrace ()
2504 ;; Replaced by C code:
2505 ;;(define (backtrace)
2506 ;; (if (fluid-ref the-last-stack)
2509 ;; (display-backtrace (fluid-ref the-last-stack) (current-output-port))
2511 ;; (if (and (not has-shown-backtrace-hint?)
2512 ;; (not (memq 'backtrace (debug-options-interface))))
2515 ;;"Type \"(debug-enable 'backtrace)\" if you would like a backtrace
2516 ;;automatically if an error occurs in the future.\n")
2517 ;; (set! has-shown-backtrace-hint? #t))))
2518 ;; (display "No backtrace available.\n")))
2520 (define (error-catching-repl r e p)
2521 (error-catching-loop
2523 (call-with-values (lambda () (e (r)))
2524 (lambda the-values (for-each p the-values))))))
2526 (define (gc-run-time)
2527 (cdr (assq 'gc-time-taken (gc-stats))))
2529 (define before-read-hook (make-hook))
2530 (define after-read-hook (make-hook))
2531 (define before-eval-hook (make-hook 1))
2532 (define after-eval-hook (make-hook 1))
2533 (define before-print-hook (make-hook 1))
2534 (define after-print-hook (make-hook 1))
2536 ;;; The default repl-reader function. We may override this if we've
2537 ;;; the readline library.
2542 (run-hook before-read-hook)
2543 (read (current-input-port))))
2545 (define (scm-style-repl)
2550 (repl-report-start-timing (lambda ()
2551 (set! start-gc-rt (gc-run-time))
2552 (set! start-rt (get-internal-run-time))))
2553 (repl-report (lambda ()
2555 (display (inexact->exact
2556 (* 1000 (/ (- (get-internal-run-time) start-rt)
2557 internal-time-units-per-second))))
2559 (display (inexact->exact
2560 (* 1000 (/ (- (gc-run-time) start-gc-rt)
2561 internal-time-units-per-second))))
2562 (display " msec in gc)\n")))
2564 (consume-trailing-whitespace
2566 (let ((ch (peek-char)))
2569 ((or (char=? ch #\space) (char=? ch #\tab))
2571 (consume-trailing-whitespace))
2572 ((char=? ch #\newline)
2576 (let ((prompt (cond ((string? scm-repl-prompt)
2578 ((thunk? scm-repl-prompt)
2580 (scm-repl-prompt "> ")
2582 (repl-reader prompt))))
2584 ;; As described in R4RS, the READ procedure updates the
2585 ;; port to point to the first character past the end of
2586 ;; the external representation of the object. This
2587 ;; means that it doesn't consume the newline typically
2588 ;; found after an expression. This means that, when
2589 ;; debugging Guile with GDB, GDB gets the newline, which
2590 ;; it often interprets as a "continue" command, making
2591 ;; breakpoints kind of useless. So, consume any
2592 ;; trailing newline here, as well as any whitespace
2594 ;; But not if EOF, for control-D.
2595 (if (not (eof-object? val))
2596 (consume-trailing-whitespace))
2597 (run-hook after-read-hook)
2598 (if (eof-object? val)
2600 (repl-report-start-timing)
2601 (if scm-repl-verbose
2604 (display ";;; EOF -- quitting")
2609 (-eval (lambda (sourc)
2610 (repl-report-start-timing)
2611 (run-hook before-eval-hook sourc)
2612 (let ((val (start-stack 'repl-stack
2613 ;; If you change this procedure
2614 ;; (primitive-eval), please also
2615 ;; modify the repl-stack case in
2616 ;; save-stack so that stack cutting
2617 ;; continues to work.
2618 (primitive-eval sourc))))
2619 (run-hook after-eval-hook sourc)
2623 (-print (let ((maybe-print (lambda (result)
2624 (if (or scm-repl-print-unspecified
2625 (not (unspecified? result)))
2630 (if (not scm-repl-silent)
2632 (run-hook before-print-hook result)
2633 (maybe-print result)
2634 (run-hook after-print-hook result)
2635 (if scm-repl-verbose
2639 (-quit (lambda (args)
2640 (if scm-repl-verbose
2642 (display ";;; QUIT executed, repl exitting")
2648 (if scm-repl-verbose
2650 (display ";;; ABORT executed.")
2653 (repl -read -eval -print))))
2655 (let ((status (error-catching-repl -read
2663 ;;; {IOTA functions: generating lists of numbers}
2667 (let loop ((count (1- n)) (result '()))
2668 (if (< count 0) result
2669 (loop (1- count) (cons count result)))))
2675 ;;; Similar to `begin' but returns a list of the results of all constituent
2676 ;;; forms instead of the result of the last form.
2677 ;;; (The definition relies on the current left-to-right
2678 ;;; order of evaluation of operands in applications.)
2681 (defmacro collect forms
2689 ;; with-fluids is a convenience wrapper for the builtin procedure
2690 ;; `with-fluids*'. The syntax is just like `let':
2692 ;; (with-fluids ((fluid val)
2696 (defmacro with-fluids (bindings . body)
2697 (let ((fluids (map car bindings))
2698 (values (map cadr bindings)))
2699 (if (and (= (length fluids) 1) (= (length values) 1))
2700 `(with-fluid* ,(car fluids) ,(car values) (lambda () ,@body))
2701 `(with-fluids* (list ,@fluids) (list ,@values)
2702 (lambda () ,@body)))))
2709 ;; actually....hobbit might be able to hack these with a little
2713 (define (primitive-macro? m)
2715 (not (macro-transformer m))))
2717 (defmacro define-macro (first . rest)
2718 (let ((name (if (symbol? first) first (car first)))
2722 `(lambda ,(cdr first) ,@rest))))
2725 (define ,name (defmacro:transformer ,transformer)))
2727 (error "define-macro can only be used at the top level")))))
2730 (defmacro define-syntax-macro (first . rest)
2731 (let ((name (if (symbol? first) first (car first)))
2735 `(lambda ,(cdr first) ,@rest))))
2738 (define ,name (defmacro:syntax-transformer ,transformer)))
2740 (error "define-syntax-macro can only be used at the top level")))))
2746 ;;; with `continue' and `break'.
2749 ;; The inner `do' loop avoids re-establishing a catch every iteration,
2750 ;; that's only necessary if continue is actually used. A new key is
2751 ;; generated every time, so break and continue apply to their originating
2752 ;; `while' even when recursing. `while-helper' is an easy way to keep the
2753 ;; `key' binding away from the cond and body code.
2755 ;; FIXME: This is supposed to have an `unquote' on the `do' the same used
2756 ;; for lambda and not, so as to protect against any user rebinding of that
2757 ;; symbol, but unfortunately an unquote breaks with ice-9 syncase, eg.
2759 ;; (use-modules (ice-9 syncase))
2761 ;; => ERROR: invalid syntax ()
2763 ;; This is probably a bug in syncase.
2765 (define-macro (while cond . body)
2766 (define (while-helper proc)
2767 (do ((key (make-symbol "while-key")))
2770 (proc (lambda () (throw key #t))
2771 (lambda () (throw key #f))))
2772 (lambda (key arg) arg)))))
2773 `(,while-helper (,lambda (break continue)
2782 ;;; {Module System Macros}
2785 ;; Return a list of expressions that evaluate to the appropriate
2786 ;; arguments for resolve-interface according to SPEC.
2788 (define (compile-interface-spec spec)
2789 (define (make-keyarg sym key quote?)
2790 (cond ((or (memq sym spec)
2794 (list key (list 'quote (cadr rest)))
2795 (list key (cadr rest)))))
2798 (define (map-apply func list)
2799 (map (lambda (args) (apply func args)) list))
2802 '((:select #:select #t)
2804 (:prefix #:prefix #t)
2805 (:renamer #:renamer #f)))
2806 (if (not (pair? (car spec)))
2809 ,@(apply append (map-apply make-keyarg keys)))))
2811 (define (keyword-like-symbol->keyword sym)
2812 (symbol->keyword (string->symbol (substring (symbol->string sym) 1))))
2814 (define (compile-define-module-args args)
2815 ;; Just quote everything except #:use-module and #:use-syntax. We
2816 ;; need to know about all arguments regardless since we want to turn
2817 ;; symbols that look like keywords into real keywords, and the
2818 ;; keyword args in a define-module form are not regular
2819 ;; (i.e. no-backtrace doesn't take a value).
2820 (let loop ((compiled-args `((quote ,(car args))))
2823 (reverse! compiled-args))
2824 ;; symbol in keyword position
2825 ((symbol? (car args))
2827 (cons (keyword-like-symbol->keyword (car args)) (cdr args))))
2828 ((memq (car args) '(#:no-backtrace #:pure))
2829 (loop (cons (car args) compiled-args)
2832 (error "keyword without value:" (car args)))
2833 ((memq (car args) '(#:use-module #:use-syntax))
2834 (loop (cons* `(list ,@(compile-interface-spec (cadr args)))
2838 ((eq? (car args) #:autoload)
2839 (loop (cons* `(quote ,(caddr args))
2840 `(quote ,(cadr args))
2845 (loop (cons* `(quote ,(cadr args))
2850 (defmacro define-module args
2853 (let ((m (process-define-module
2854 (list ,@(compile-define-module-args args)))))
2855 (set-current-module m)
2858 (error "define-module can only be used at the top level"))))
2860 ;; The guts of the use-modules macro. Add the interfaces of the named
2861 ;; modules to the use-list of the current module, in order.
2863 ;; This function is called by "modules.c". If you change it, be sure
2864 ;; to change scm_c_use_module as well.
2866 (define (process-use-modules module-interface-args)
2867 (let ((interfaces (map (lambda (mif-args)
2868 (or (apply resolve-interface mif-args)
2869 (error "no such module" mif-args)))
2870 module-interface-args)))
2871 (call-with-deferred-observers
2873 (module-use-interfaces! (current-module) interfaces)))))
2875 (defmacro use-modules modules
2878 (process-use-modules
2879 (list ,@(map (lambda (m)
2880 `(list ,@(compile-interface-spec m)))
2884 (error "use-modules can only be used at the top level"))))
2886 (defmacro use-syntax (spec)
2890 `((process-use-modules (list
2891 (list ,@(compile-interface-spec spec))))
2892 (set-module-transformer! (current-module)
2893 ,(car (last-pair spec))))
2894 `((set-module-transformer! (current-module) ,spec)))
2897 (error "use-syntax can only be used at the top level"))))
2899 ;; Dirk:FIXME:: This incorrect (according to R5RS) syntax needs to be changed
2900 ;; as soon as guile supports hygienic macros.
2901 (define define-private define)
2903 (defmacro define-public args
2905 (error "bad syntax" (list 'define-public args)))
2906 (define (defined-name n)
2909 ((pair? n) (defined-name (car n)))
2915 (let ((name (defined-name (car args))))
2917 (define-private ,@args)
2918 (eval-case ((load-toplevel) (export ,name))))))))
2920 (defmacro defmacro-public args
2922 (error "bad syntax" (list 'defmacro-public args)))
2923 (define (defined-name n)
2931 (let ((name (defined-name (car args))))
2933 (eval-case ((load-toplevel) (export-syntax ,name)))
2934 (defmacro ,@args))))))
2936 ;; Export a local variable
2938 ;; This function is called from "modules.c". If you change it, be
2939 ;; sure to update "modules.c" as well.
2941 (define (module-export! m names)
2942 (let ((public-i (module-public-interface m)))
2943 (for-each (lambda (name)
2944 (let ((var (module-ensure-local-variable! m name)))
2945 (module-add! public-i name var)))
2948 (define (module-replace! m names)
2949 (let ((public-i (module-public-interface m)))
2950 (for-each (lambda (name)
2951 (let ((var (module-ensure-local-variable! m name)))
2952 (set-object-property! var 'replace #t)
2953 (module-add! public-i name var)))
2956 ;; Re-export a imported variable
2958 (define (module-re-export! m names)
2959 (let ((public-i (module-public-interface m)))
2960 (for-each (lambda (name)
2961 (let ((var (module-variable m name)))
2963 (error "Undefined variable:" name))
2964 ((eq? var (module-local-variable m name))
2965 (error "re-exporting local variable:" name))
2967 (module-add! public-i name var)))))
2970 (defmacro export names
2973 (call-with-deferred-observers
2975 (module-export! (current-module) ',names))))
2977 (error "export can only be used at the top level"))))
2979 (defmacro re-export names
2982 (call-with-deferred-observers
2984 (module-re-export! (current-module) ',names))))
2986 (error "re-export can only be used at the top level"))))
2988 (defmacro export-syntax names
2991 (defmacro re-export-syntax names
2992 `(re-export ,@names))
2994 (define load load-module)
2996 ;; The following macro allows one to write, for example,
2998 ;; (@ (ice-9 pretty-print) pretty-print)
3000 ;; to refer directly to the pretty-print variable in module (ice-9
3001 ;; pretty-print). It works by looking up the variable and inserting
3002 ;; it directly into the code. This is understood by the evaluator.
3003 ;; Indeed, all references to global variables are memoized into such
3004 ;; variable objects.
3006 (define-macro (@ mod-name var-name)
3007 (let ((var (module-variable (resolve-interface mod-name) var-name)))
3009 (error "no such public variable" (list '@ mod-name var-name)))
3012 ;; The '@@' macro is like '@' but it can also access bindings that
3013 ;; have not been explicitely exported.
3015 (define-macro (@@ mod-name var-name)
3016 (let ((var (module-variable (resolve-module mod-name) var-name)))
3018 (error "no such variable" (list '@@ mod-name var-name)))
3026 (define make-mutable-parameter
3027 (let ((make (lambda (fluid converter)
3031 (fluid-set! fluid (converter (car args))))))))
3032 (lambda (init . converter)
3033 (let ((fluid (make-fluid))
3034 (converter (if (null? converter)
3037 (fluid-set! fluid (converter init))
3038 (make fluid converter)))))
3042 ;;; {Handling of duplicate imported bindings}
3045 ;; Duplicate handlers take the following arguments:
3047 ;; module importing module
3048 ;; name conflicting name
3049 ;; int1 old interface where name occurs
3050 ;; val1 value of binding in old interface
3051 ;; int2 new interface where name occurs
3052 ;; val2 value of binding in new interface
3053 ;; var previous resolution or #f
3054 ;; val value of previous resolution
3056 ;; A duplicate handler can take three alternative actions:
3058 ;; 1. return #f => leave responsibility to next handler
3059 ;; 2. exit with an error
3060 ;; 3. return a variable resolving the conflict
3063 (define duplicate-handlers
3064 (let ((m (make-module 7)))
3066 (define (check module name int1 val1 int2 val2 var val)
3067 (scm-error 'misc-error
3069 "~A: `~A' imported from both ~A and ~A"
3070 (list (module-name module)
3076 (define (warn module name int1 val1 int2 val2 var val)
3078 "WARNING: ~A: `~A' imported from both ~A and ~A\n"
3079 (module-name module)
3085 (define (replace module name int1 val1 int2 val2 var val)
3086 (let ((old (or (and var (object-property var 'replace) var)
3087 (module-variable int1 name)))
3088 (new (module-variable int2 name)))
3089 (if (object-property old 'replace)
3090 (and (or (eq? old new)
3091 (not (object-property new 'replace)))
3093 (and (object-property new 'replace)
3096 (define (warn-override-core module name int1 val1 int2 val2 var val)
3097 (and (eq? int1 the-scm-module)
3100 "WARNING: ~A: imported module ~A overrides core binding `~A'\n"
3101 (module-name module)
3104 (module-local-variable int2 name))))
3106 (define (first module name int1 val1 int2 val2 var val)
3107 (or var (module-local-variable int1 name)))
3109 (define (last module name int1 val1 int2 val2 var val)
3110 (module-local-variable int2 name))
3112 (define (noop module name int1 val1 int2 val2 var val)
3115 (set-module-name! m 'duplicate-handlers)
3116 (set-module-kind! m 'interface)
3117 (module-define! m 'check check)
3118 (module-define! m 'warn warn)
3119 (module-define! m 'replace replace)
3120 (module-define! m 'warn-override-core warn-override-core)
3121 (module-define! m 'first first)
3122 (module-define! m 'last last)
3123 (module-define! m 'merge-generics noop)
3124 (module-define! m 'merge-accessors noop)
3127 (define (lookup-duplicates-handlers handler-names)
3129 (map (lambda (handler-name)
3130 (or (module-symbol-local-binding
3131 duplicate-handlers handler-name #f)
3132 (error "invalid duplicate handler name:"
3134 (if (list? handler-names)
3136 (list handler-names)))))
3138 (define default-duplicate-binding-procedures
3139 (make-mutable-parameter #f))
3141 (define default-duplicate-binding-handler
3142 (make-mutable-parameter '(replace warn-override-core warn last)
3143 (lambda (handler-names)
3144 (default-duplicate-binding-procedures
3145 (lookup-duplicates-handlers handler-names))
3148 (define (make-duplicates-interface)
3149 (let ((m (make-module)))
3150 (set-module-kind! m 'custom-interface)
3151 (set-module-name! m 'duplicates)
3154 (define (process-duplicates module interface)
3155 (let* ((duplicates-handlers (or (module-duplicates-handlers module)
3156 (default-duplicate-binding-procedures)))
3157 (duplicates-interface (module-duplicates-interface module)))
3160 (cond ((module-import-interface module name)
3162 (lambda (prev-interface)
3163 (let ((var1 (module-local-variable prev-interface name))
3164 (var2 (module-local-variable interface name)))
3165 (if (not (eq? var1 var2))
3167 (if (not duplicates-interface)
3169 (set! duplicates-interface
3170 (make-duplicates-interface))
3171 (set-module-duplicates-interface!
3173 duplicates-interface)))
3174 (let* ((var (module-local-variable duplicates-interface
3177 (variable-bound? var)
3178 (variable-ref var))))
3179 (let loop ((duplicates-handlers duplicates-handlers))
3180 (cond ((null? duplicates-handlers))
3181 (((car duplicates-handlers)
3185 (and (variable-bound? var1)
3186 (variable-ref var1))
3188 (and (variable-bound? var2)
3189 (variable-ref var2))
3194 (module-add! duplicates-interface name var)))
3196 (loop (cdr duplicates-handlers)))))))))))))
3201 ;;; {`cond-expand' for SRFI-0 support.}
3203 ;;; This syntactic form expands into different commands or
3204 ;;; definitions, depending on the features provided by the Scheme
3210 ;;; --> (cond-expand <cond-expand-clause>+)
3211 ;;; | (cond-expand <cond-expand-clause>* (else <command-or-definition>))
3212 ;;; <cond-expand-clause>
3213 ;;; --> (<feature-requirement> <command-or-definition>*)
3214 ;;; <feature-requirement>
3215 ;;; --> <feature-identifier>
3216 ;;; | (and <feature-requirement>*)
3217 ;;; | (or <feature-requirement>*)
3218 ;;; | (not <feature-requirement>)
3219 ;;; <feature-identifier>
3220 ;;; --> <a symbol which is the name or alias of a SRFI>
3222 ;;; Additionally, this implementation provides the
3223 ;;; <feature-identifier>s `guile' and `r5rs', so that programs can
3224 ;;; determine the implementation type and the supported standard.
3226 ;;; Currently, the following feature identifiers are supported:
3228 ;;; guile r5rs srfi-0 srfi-4 srfi-6 srfi-13 srfi-14 srfi-55 srfi-61
3230 ;;; Remember to update the features list when adding more SRFIs.
3233 (define %cond-expand-features
3234 ;; Adjust the above comment when changing this.
3237 srfi-0 ;; cond-expand itself
3238 srfi-4 ;; homogenous numeric vectors
3239 srfi-6 ;; open-input-string etc, in the guile core
3240 srfi-13 ;; string library
3241 srfi-14 ;; character sets
3242 srfi-55 ;; require-extension
3243 srfi-61 ;; general cond clause
3246 ;; This table maps module public interfaces to the list of features.
3248 (define %cond-expand-table (make-hash-table 31))
3250 ;; Add one or more features to the `cond-expand' feature list of the
3253 (define (cond-expand-provide module features)
3254 (let ((mod (module-public-interface module)))
3256 (hashq-set! %cond-expand-table mod
3257 (append (hashq-ref %cond-expand-table mod '())
3261 (procedure->memoizing-macro
3263 (let ((clauses (cdr exp))
3264 (syntax-error (lambda (cl)
3265 (error "invalid clause in `cond-expand'" cl))))
3271 (or (memq clause %cond-expand-features)
3272 (let lp ((uses (module-uses (env-module env))))
3275 (hashq-ref %cond-expand-table
3281 ((eq? 'and (car clause))
3282 (let lp ((l (cdr clause)))
3286 (and (test-clause (car l)) (lp (cdr l))))
3288 (syntax-error clause)))))
3289 ((eq? 'or (car clause))
3290 (let lp ((l (cdr clause)))
3294 (or (test-clause (car l)) (lp (cdr l))))
3296 (syntax-error clause)))))
3297 ((eq? 'not (car clause))
3298 (cond ((not (pair? (cdr clause)))
3299 (syntax-error clause))
3300 ((pair? (cddr clause))
3301 ((syntax-error clause))))
3302 (not (test-clause (cadr clause))))
3304 (syntax-error clause))))
3306 (syntax-error clause))))))
3307 (let lp ((c clauses))
3310 (error "Unfulfilled `cond-expand'"))
3313 ((not (pair? (car c)))
3314 (syntax-error (car c)))
3315 ((test-clause (caar c))
3316 `(begin ,@(cdar c)))
3317 ((eq? (caar c) 'else)
3320 `(begin ,@(cdar c)))
3322 (lp (cdr c))))))))))
3324 ;; This procedure gets called from the startup code with a list of
3325 ;; numbers, which are the numbers of the SRFIs to be loaded on startup.
3327 (define (use-srfis srfis)
3330 (let* ((srfi (string->symbol
3331 (string-append "srfi-" (number->string (car s)))))
3332 (mod-i (resolve-interface (list 'srfi srfi))))
3333 (module-use! (current-module) mod-i)
3338 ;;; srfi-55: require-extension
3341 (define-macro (require-extension extension-spec)
3342 ;; This macro only handles the srfi extension, which, at present, is
3343 ;; the only one defined by the standard.
3344 (if (not (pair? extension-spec))
3345 (scm-error 'wrong-type-arg "require-extension"
3346 "Not an extension: ~S" (list extension-spec) #f))
3347 (let ((extension (car extension-spec))
3348 (extension-args (cdr extension-spec)))
3351 (let ((use-list '()))
3354 (if (not (integer? i))
3355 (scm-error 'wrong-type-arg "require-extension"
3356 "Invalid srfi name: ~S" (list i) #f))
3357 (let ((srfi-sym (string->symbol
3358 (string-append "srfi-" (number->string i)))))
3359 (if (not (memq srfi-sym %cond-expand-features))
3360 (set! use-list (cons `(use-modules (srfi ,srfi-sym))
3363 (if (pair? use-list)
3364 ;; i.e. (begin (use-modules x) (use-modules y) (use-modules z))
3365 `(begin ,@(reverse! use-list)))))
3368 'wrong-type-arg "require-extension"
3369 "Not a recognized extension type: ~S" (list extension) #f)))))
3373 ;;; {Load emacs interface support if emacs option is given.}
3376 (define (named-module-use! user usee)
3377 (module-use! (resolve-module user) (resolve-interface usee)))
3379 (define (load-emacs-interface)
3380 (and (provided? 'debug-extensions)
3381 (debug-enable 'backtrace))
3382 (named-module-use! '(guile-user) '(ice-9 emacs)))
3386 (define using-readline?
3387 (let ((using-readline? (make-fluid)))
3388 (make-procedure-with-setter
3389 (lambda () (fluid-ref using-readline?))
3390 (lambda (v) (fluid-set! using-readline? v)))))
3393 (let ((guile-user-module (resolve-module '(guile-user))))
3395 ;; Load emacs interface support if emacs option is given.
3396 (if (and (module-defined? guile-user-module 'use-emacs-interface)
3397 (module-ref guile-user-module 'use-emacs-interface))
3398 (load-emacs-interface))
3400 ;; Use some convenient modules (in reverse order)
3402 (if (provided? 'regex)
3403 (module-use! guile-user-module (resolve-interface '(ice-9 regex))))
3404 (if (provided? 'threads)
3405 (module-use! guile-user-module (resolve-interface '(ice-9 threads))))
3406 ;; load debugger on demand
3407 (module-use! guile-user-module
3408 (make-autoload-interface guile-user-module
3409 '(ice-9 debugger) '(debug)))
3410 (module-use! guile-user-module (resolve-interface '(ice-9 session)))
3411 (module-use! guile-user-module (resolve-interface '(ice-9 debug)))
3412 ;; so that builtin bindings will be checked first
3413 (module-use! guile-user-module (resolve-interface '(ice-9 r5rs)))
3414 (module-use! guile-user-module (resolve-interface '(guile)))
3416 (set-current-module guile-user-module)
3418 (let ((old-handlers #f)
3419 (signals (if (provided? 'posix)
3420 `((,SIGINT . "User interrupt")
3421 (,SIGFPE . "Arithmetic error")
3422 (,SIGBUS . "Bad memory access (bus error)")
3424 . "Bad memory access (Segmentation violation)"))
3431 (let ((make-handler (lambda (msg)
3433 ;; Make a backup copy of the stack
3434 (fluid-set! before-signal-stack
3435 (fluid-ref the-last-stack))
3443 (map (lambda (sig-msg)
3444 (sigaction (car sig-msg)
3445 (make-handler (cdr sig-msg))))
3448 ;; the protected thunk.
3450 (let ((status (scm-style-repl)))
3451 (run-hook exit-hook)
3456 (map (lambda (sig-msg old-handler)
3457 (if (not (car old-handler))
3458 ;; restore original C handler.
3459 (sigaction (car sig-msg) #f)
3460 ;; restore Scheme handler, SIG_IGN or SIG_DFL.
3461 (sigaction (car sig-msg)
3463 (cdr old-handler))))
3464 signals old-handlers))))))
3466 ;;; This hook is run at the very end of an interactive session.
3468 (define exit-hook (make-hook))
3472 ;;; {Deprecated stuff}
3476 (define (feature? sym)
3477 (issue-deprecation-warning
3478 "`feature?' is deprecated. Use `provided?' instead.")
3482 (primitive-load-path "ice-9/deprecated.scm"))
3486 ;;; Place the user in the guile-user module.
3489 (define-module (guile-user))
3491 ;;; boot-9.scm ends here