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