1 ;;;; Copyright (C) 1997 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, 675 Mass Ave, Cambridge, MA 02139, USA.
19 (define-module (ice-9 session))
25 ;;; Author: Roland Orre <orre@nada.kth.se>
30 (define-public (apropos rgx . options)
31 "Search for bindings: apropos regexp {options= 'full 'shadow 'value}"
32 (if (zero? (string-length rgx))
33 "Empty string not allowed"
34 (let* ((match (make-regexp rgx))
35 (modules (cons (current-module)
36 (module-uses (current-module))))
38 (shadow (member 'shadow options))
39 (value (member 'value options)))
40 (cond ((member 'full options)
45 (let* ((builtin (or (eq? module the-scm-module)
46 (eq? module the-root-module)))
47 (name (module-name module))
49 (list (builtin-weak-bindings)
51 (list (module-obarray module))))
57 (lambda (obarray get-ref)
62 (cond ((regexp-exec match (car x))
66 (cond ((procedure? (get-ref (cdr x)))
68 (display (get-ref (cdr x))))
71 (display (get-ref (cdr x)))))
73 (not (eq? (module-ref module
75 (module-ref (current-module)
77 (display " shadowed"))
85 (define-public (apropos-internal rgx)
86 "Return a list of accessible variable names."
87 (let ((match (make-regexp rgx))
88 (modules (cons (current-module)
89 (module-uses (current-module))))
90 (recorded (make-vector 61 '()))
91 (vars (cons '() '())))
101 (if (and (regexp-exec match (car x))
102 (not (hashq-get-handle recorded (car x))))
104 (set-cdr! last (cons (car x) '()))
105 (set! last (cdr last))
106 (hashq-set! recorded (car x) #t))))
109 (if (or (eq? module the-scm-module)
110 (eq? module the-root-module))
111 (list (builtin-weak-bindings)
113 (list (module-obarray module)))))
117 (define-public (name obj)
118 (cond ((procedure? obj) (procedure-name obj))
119 ((macro? obj) (macro-name obj))
122 (define-public (source obj)
123 (cond ((procedure? obj) (procedure-source obj))
124 ((macro? obj) (procedure-source (macro-transformer obj)))
127 (define-public (arity obj)
128 (let ((arity (procedure-property obj 'arity)))
129 (display (car arity))
131 (display " or more"))
132 ((not (zero? (cadr arity)))
133 (display " required and ")
134 (display (cadr arity))
135 (display " optional")))
136 (if (and (not (caddr arity))
139 (display " argument")
140 (display " arguments"))
142 (let ((formals (cadr (procedure-source obj))))
146 (display (car formals))
147 (let loop ((ls (cdr formals)))
151 (display "', the rest in `")