Commit | Line | Data |
---|---|---|
6a4d3cfd JB |
1 | ;;;; ls.scm --- functions for browsing modules |
2 | ;;;; | |
cd5fea8d | 3 | ;;;; Copyright (C) 1995, 1996, 1997, 1999, 2001, 2006 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 | |
8 | ;;;; version 2.1 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) |
a6401ee0 JB |
57 | (let ((m (nested-ref root names)) |
58 | (answer '())) | |
59 | (if (not (module? m)) | |
60 | (set! answer m) | |
61 | (module-for-each (lambda (k v) (set! answer (cons k answer))) m)) | |
62 | answer)) | |
63 | ||
1a179b03 | 64 | (define (definitions-in root names) |
a6401ee0 JB |
65 | (let ((m (nested-ref root names))) |
66 | (if (not (module? m)) | |
67 | m | |
68 | (reduce union | |
69 | (cons (local-definitions-in m '()) | |
70 | (map (lambda (m2) (definitions-in m2 '())) | |
71 | (module-uses m))))))) | |
72 | ||
1a179b03 | 73 | (define (ls . various-refs) |
67e6fa38 | 74 | (if (pair? various-refs) |
a6401ee0 JB |
75 | (if (cdr various-refs) |
76 | (map (lambda (ref) | |
77 | (cons ref (definitions-in (current-module) ref))) | |
78 | various-refs) | |
67e6fa38 JB |
79 | (definitions-in (current-module) (car various-refs))) |
80 | (definitions-in (current-module) '()))) | |
a6401ee0 | 81 | |
1a179b03 | 82 | (define (lls . various-refs) |
67e6fa38 | 83 | (if (pair? various-refs) |
a6401ee0 JB |
84 | (if (cdr various-refs) |
85 | (map (lambda (ref) | |
86 | (cons ref (local-definitions-in (current-module) ref))) | |
87 | various-refs) | |
67e6fa38 JB |
88 | (local-definitions-in (current-module) (car various-refs))) |
89 | (local-definitions-in (current-module) '()))) | |
a6401ee0 | 90 | |
1a179b03 | 91 | (define (recursive-local-define name value) |
a6401ee0 JB |
92 | (let ((parent (reverse! (cdr (reverse name))))) |
93 | (and parent (make-modules-in (current-module) parent)) | |
94 | (local-define name value))) | |
67e6fa38 JB |
95 | |
96 | ;;; ls.scm ends here |