1 ;;;; Copyright (C) 1997, 2000 Free Software Foundation, Inc.
3 ;;;; This program is free software; you can redistribute it and/or modify
4 ;;;; it under the terms of the GNU General Public License as published by
5 ;;;; the Free Software Foundation; either version 2, or (at your option)
6 ;;;; any later version.
8 ;;;; This program is distributed in the hope that it will be useful,
9 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ;;;; GNU General Public License for more details.
13 ;;;; You should have received a copy of the GNU General Public License
14 ;;;; along with this software; see the file COPYING. If not, write to
15 ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 ;;;; Boston, MA 02111-1307 USA
20 (define-module (ice-9 session)
21 :use-module (ice-9 doc)
32 Prints useful information. Try `(help)'."
33 (if (not (= (length exp) 2))
35 (let* ((sym (cadr exp))
41 (cond ;; *fixme*: when we have GOOPS
42 ;;((or obj (not sym)) (describe obj))
43 ((and (or obj (not sym))
44 (cond ((procedure? obj)
45 (display (proc-doc obj))
48 ((and (macro? obj) (macro-transformer obj))
49 (display (proc-doc (macro-transformer obj)))
55 (display "No documentation for `")
61 (display "Usage: (help NAME) gives documentation about NAME
62 (help) gives this text
67 Other useful sources of helpful information:
71 (name PROCEDURE-OR-MACRO)
72 (source PROCEDURE-OR-MACRO)
76 (backtrace) ;show backtrace from last error
77 (debug) ;enter the debugger
78 (trace [PROCEDURE]) ;trace procedure (no arg => show)
79 (untrace [PROCEDURE]) ;untrace (no arg => untrace all)
81 (OPTIONSET-options 'full) ;display option information
82 (OPTIONSET-enable 'OPTION)
83 (OPTIONSET-disable 'OPTION)
84 (OPTIONSET-set! OPTION VALUE)
86 where OPTIONSET is one of debug, read, eval, print
92 ;;; Author: Roland Orre <orre@nada.kth.se>
97 (define-public (apropos rgx . options)
98 "Search for bindings: apropos regexp {options= 'full 'shadow 'value}"
99 (if (zero? (string-length rgx))
100 "Empty string not allowed"
101 (let* ((match (make-regexp rgx))
102 (modules (cons (current-module)
103 (module-uses (current-module))))
105 (shadow (member 'shadow options))
106 (value (member 'value options)))
107 (cond ((member 'full options)
112 (let* ((builtin (or (eq? module the-scm-module)
113 (eq? module the-root-module)))
114 (name (module-name module))
115 (obarrays (if builtin
116 (list (builtin-weak-bindings)
118 (list (module-obarray module))))
119 (get-refs (if builtin
121 (list variable-ref)))
124 (lambda (obarray get-ref)
129 (cond ((regexp-exec match (car x))
133 (cond ((procedure? (get-ref (cdr x)))
135 (display (get-ref (cdr x))))
138 (display (get-ref (cdr x)))))
140 (not (eq? (module-ref module
142 (module-ref (current-module)
144 (display " shadowed"))
152 (define-public (apropos-internal rgx)
153 "Return a list of accessible variable names."
154 (letrec ((match (make-regexp rgx))
155 (recorded (make-vector 61 '()))
157 (lambda (obarray names)
158 (hash-fold (lambda (name var vars)
159 (if (and (regexp-exec match name)
160 (not (hashq-get-handle recorded name)))
162 (hashq-set! recorded name #t)
167 (do ((modules (cons (current-module) (module-uses (current-module)))
170 (if (or (eq? (car modules) the-scm-module)
171 (eq? (car modules) the-root-module))
172 (obarray-names (builtin-weak-bindings)
173 (obarray-names (builtin-bindings)
175 (obarray-names (module-obarray (car modules))
177 ((null? modules) names))))
179 (define-public (name obj)
180 (cond ((procedure? obj) (procedure-name obj))
181 ((macro? obj) (macro-name obj))
184 (define-public (source obj)
185 (cond ((procedure? obj) (procedure-source obj))
186 ((macro? obj) (procedure-source (macro-transformer obj)))
189 (define-public (arity obj)
190 (let ((arity (procedure-property obj 'arity)))
191 (display (car arity))
193 (display " or more"))
194 ((not (zero? (cadr arity)))
195 (display " required and ")
196 (display (cadr arity))
197 (display " optional")))
198 (if (and (not (caddr arity))
201 (display " argument")
202 (display " arguments"))
204 (let ((formals (cadr (procedure-source obj))))
208 (display (car formals))
209 (let loop ((ls (cdr formals)))
213 (display "', the rest in `")
228 (define-public system-module
231 (let* ((m (nested-ref the-root-module
232 (append '(app modules) (cadr exp)))))
234 (error "Couldn't find any module named" (cadr exp)))
235 (let ((s (not (procedure-property (module-eval-closure m)
237 (set-system-module! m s)
238 (string-append "Module " (symbol->string (module-name m))
239 " is now a " (if s "system" "user") " module."))))))