(let ((entries (apropos-fold (lambda (module name object data)
(cons (list module
name
- (object-documentation object))
+ (object-documentation object)
+ (cond ((closure? object)
+ "a procedure")
+ ((procedure? object)
+ "a primitive procedure")
+ (else
+ "an object")))
data))
'()
regexp
apropos-fold-exported))
(module car)
(name cadr)
- (doc caddr))
+ (doc caddr)
+ (type cadddr))
(if (null? entries)
;; no matches
(begin
"named `~A'\n"
"matching regexp \"~A\"\n")
term))
- (let ((first? #t))
- (if (or-map doc entries)
- ;; entries with documentation
- (for-each (lambda (entry)
- ;; *fixme*: Use `describe' when we have GOOPS?
- (if (doc entry)
- (begin
- (if first?
- (set! first? #f)
- (newline))
- (simple-format #t "~S: ~S\n~A\n"
- (module-name (module entry))
- (name entry)
- (doc entry)))))
- entries))
- (if (or-map (lambda (x) (not (doc x))) entries)
- ;; entries without documentation
+ (let ((first? #t)
+ (undocumented-entries '())
+ (documented-entries '())
+ (documentations '()))
+
+ (for-each (lambda (entry)
+ (let ((entry-summary (simple-format #f
+ "~S: ~S\n"
+ (module-name (module entry))
+ (name entry))))
+ (if (doc entry)
+ (begin
+ (set! documented-entries
+ (cons entry-summary documented-entries))
+ ;; *fixme*: Use `describe' when we have GOOPS?
+ (set! documentations
+ (cons (simple-format #f
+ "`~S' is ~A in the ~S module.\n\n~A\n"
+ (name entry)
+ (type entry)
+ (module-name (module entry))
+ (doc entry))
+ documentations)))
+ (set! undocumented-entries
+ (cons entry-summary undocumented-entries)))))
+ entries)
+
+ (if (and (not (null? documented-entries))
+ (or (> (length documented-entries) 1)
+ (not (null? undocumented-entries))))
(begin
- (if (not first?)
- (display "\nNo documentation found for:\n"))
- (for-each (lambda (entry)
- (if (not (doc entry))
- (simple-format #t "~S: ~S\n"
- (module-name (module entry))
- (name entry))))
- entries)))))))
+ (display "Documentation found for:\n")
+ (for-each (lambda (entry) (display entry)) documented-entries)
+ (set! first? #f)))
+
+ (for-each (lambda (entry)
+ (if first?
+ (set! first? #f)
+ (newline))
+ (display entry))
+ documentations)
+
+ (if (not (null? undocumented-entries))
+ (begin
+ (if first?
+ (set! first? #f)
+ (newline))
+ (display "No documentation found for:\n")
+ (for-each (lambda (entry) (display entry)) undocumented-entries)))))))
(define (help-usage)
(display "Usage: (help NAME) gives documentation about objects named NAME (a symbol)
(let* ((builtin (or (eq? module the-scm-module)
(eq? module the-root-module)))
(name (module-name module))
- (obarrays (if builtin
- (list (builtin-weak-bindings)
- (builtin-bindings))
- (list (module-obarray module))))
- (get-refs (if builtin
- (list id id)
- (list variable-ref)))
- )
- (for-each
- (lambda (obarray get-ref)
- (array-for-each
- (lambda (oblist)
- (for-each
- (lambda (x)
- (cond ((regexp-exec match (car x))
- (display name)
- (display ": ")
- (display (car x))
- (cond ((procedure? (get-ref (cdr x)))
- (display separator)
- (display (get-ref (cdr x))))
- (value
- (display separator)
- (display (get-ref (cdr x)))))
- (if (and shadow
- (not (eq? (module-ref module
- (car x))
- (module-ref (current-module)
- (car x)))))
- (display " shadowed"))
- (newline)
- )))
- oblist))
- obarray))
- obarrays get-refs)))
+ (obarray (if builtin
+ (builtin-bindings)
+ (module-obarray module)))
+ (get-ref (if builtin
+ id
+ variable-ref)))
+ (array-for-each
+ (lambda (oblist)
+ (for-each
+ (lambda (x)
+ (cond ((regexp-exec match (symbol->string (car x)))
+ (display name)
+ (display ": ")
+ (display (car x))
+ (cond ((procedure? (get-ref (cdr x)))
+ (display separator)
+ (display (get-ref (cdr x))))
+ (value
+ (display separator)
+ (display (get-ref (cdr x)))))
+ (if (and shadow
+ (not (eq? (module-ref module
+ (car x))
+ (module-ref (current-module)
+ (car x)))))
+ (display " shadowed"))
+ (newline)
+ )))
+ oblist))
+ obarray)))
modules))))
(define-public (apropos-internal rgx)
(lambda (module data)
(let* ((obarray-filter
(lambda (name val data)
- (if (and (regexp-exec match name)
+ (if (and (regexp-exec match (symbol->string name))
(not (hashq-get-handle recorded name)))
(begin
(hashq-set! recorded name #t)
(cond ((or (eq? module the-scm-module)
(eq? module the-root-module))
(hash-fold obarray-filter
- (hash-fold obarray-filter
- data
- (builtin-bindings))
- (builtin-weak-bindings)))
+ data
+ (builtin-bindings)))
(module (hash-fold module-filter
data
(module-obarray module)))
(lambda (fold-module init)
(let* ((table (make-hash-table 31))
(first? (lambda (obj)
- (and (not (hash-ref table obj))
- (hash-create-handle! table obj #t)))))
+ (let* ((handle (hash-create-handle! table obj #t))
+ (first? (cdr handle)))
+ (set-cdr! handle #f)
+ first?))))
(let rec ((data init)
(modules (init-thunk)))
(do ((modules modules (cdr modules))