define-module for elisp special modules
[bpt/guile.git] / module / ice-9 / ls.scm
CommitLineData
6a4d3cfd
JB
1;;;; ls.scm --- functions for browsing modules
2;;;;
28b8c785 3;;;; Copyright (C) 1995, 1996, 1997, 1999, 2001, 2006, 2010 Free Software Foundation, Inc.
6a4d3cfd 4;;;;
73be1d9e
MV
5;;;; This library is free software; you can redistribute it and/or
6;;;; modify it under the terms of the GNU Lesser General Public
7;;;; License as published by the Free Software Foundation; either
53befeb7 8;;;; version 3 of the License, or (at your option) any later version.
6a4d3cfd 9;;;;
73be1d9e 10;;;; This library is distributed in the hope that it will be useful,
6a4d3cfd 11;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
12;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13;;;; Lesser General Public License for more details.
6a4d3cfd 14;;;;
73be1d9e
MV
15;;;; You should have received a copy of the GNU Lesser General Public
16;;;; License along with this library; if not, write to the Free Software
92205699 17;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6a4d3cfd
JB
18;;;;
19\f
a6401ee0 20(define-module (ice-9 ls)
1a179b03
MD
21 :use-module (ice-9 common-list)
22 :export (local-definitions-in definitions-in ls lls
23 recursive-local-define))
a6401ee0
JB
24
25;;;;
26;;; local-definitions-in root name
27;;; Returns a list of names defined locally in the named
28;;; subdirectory of root.
29;;; definitions-in root name
30;;; Returns a list of all names defined in the named
31;;; subdirectory of root. The list includes alll locally
32;;; defined names as well as all names inherited from a
33;;; member of a use-list.
34;;;
35;;; A convenient interface for examining the nature of things:
36;;;
37;;; ls . various-names
38;;;
67e6fa38
JB
39;;; With no arguments, return a list of definitions in
40;;; `(current-module)'.
41;;;
a6401ee0
JB
42;;; With just one argument, interpret that argument as the
43;;; name of a subdirectory of the current module and
44;;; return a list of names defined there.
45;;;
46;;; With more than one argument, still compute
47;;; subdirectory lists, but return a list:
48;;; ((<subdir-name> . <names-defined-there>)
49;;; (<subdir-name> . <names-defined-there>)
50;;; ...)
51;;;
67e6fa38
JB
52;;; lls . various-names
53;;;
54;;; Analogous to `ls', but with local definitions only.
a6401ee0 55
1a179b03 56(define (local-definitions-in root names)
28b8c785
AW
57 (let ((m (nested-ref-module root names)))
58 (if m
59 (module-map (lambda (k v) k) m)
60 (nested-ref root names))))
a6401ee0 61
1a179b03 62(define (definitions-in root names)
28b8c785
AW
63 (let ((m (nested-ref-module root names)))
64 (if m
a6401ee0 65 (reduce union
28b8c785 66 (cons (local-definitions-in m '())
a6401ee0 67 (map (lambda (m2) (definitions-in m2 '()))
28b8c785
AW
68 (module-uses m))))
69 (nested-ref root names))))
a6401ee0 70
1a179b03 71(define (ls . various-refs)
67e6fa38 72 (if (pair? various-refs)
a6401ee0
JB
73 (if (cdr various-refs)
74 (map (lambda (ref)
75 (cons ref (definitions-in (current-module) ref)))
76 various-refs)
67e6fa38
JB
77 (definitions-in (current-module) (car various-refs)))
78 (definitions-in (current-module) '())))
a6401ee0 79
1a179b03 80(define (lls . various-refs)
67e6fa38 81 (if (pair? various-refs)
a6401ee0
JB
82 (if (cdr various-refs)
83 (map (lambda (ref)
84 (cons ref (local-definitions-in (current-module) ref)))
85 various-refs)
67e6fa38
JB
86 (local-definitions-in (current-module) (car various-refs)))
87 (local-definitions-in (current-module) '())))
a6401ee0 88
1a179b03 89(define (recursive-local-define name value)
a6401ee0 90 (let ((parent (reverse! (cdr (reverse name)))))
28b8c785
AW
91 (module-define! (make-modules-in (current-module) parent)
92 name value)))
67e6fa38
JB
93
94;;; ls.scm ends here