60c765eb90e13a90306438e945c1e7655270404e
[bpt/guile.git] / ice-9 / ls.scm
1 ;;;; ls.scm --- functions for browsing modules
2 ;;;;
3 ;;;; Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
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 ;;;; As a special exception, the Free Software Foundation gives permission
21 ;;;; for additional uses of the text contained in its release of GUILE.
22 ;;;;
23 ;;;; The exception is that, if you link the GUILE library with other files
24 ;;;; to produce an executable, this does not by itself cause the
25 ;;;; resulting executable to be covered by the GNU General Public License.
26 ;;;; Your use of that executable is in no way restricted on account of
27 ;;;; linking the GUILE library code into it.
28 ;;;;
29 ;;;; This exception does not however invalidate any other reasons why
30 ;;;; the executable file might be covered by the GNU General Public License.
31 ;;;;
32 ;;;; This exception applies only to the code released by the
33 ;;;; Free Software Foundation under the name GUILE. If you copy
34 ;;;; code from other Free Software Foundation releases into a copy of
35 ;;;; GUILE, as the General Public License permits, the exception does
36 ;;;; not apply to the code that you add in this way. To avoid misleading
37 ;;;; anyone as to the status of such modified files, you must delete
38 ;;;; this exception notice from them.
39 ;;;;
40 ;;;; If you write modifications of your own for GUILE, it is your choice
41 ;;;; whether to permit this exception to apply to your modifications.
42 ;;;; If you do not wish that, delete this exception notice.
43 ;;;;
44 \f
45 (define-module (ice-9 ls)
46 :use-module (ice-9 common-list))
47
48 ;;;;
49 ;;; local-definitions-in root name
50 ;;; Returns a list of names defined locally in the named
51 ;;; subdirectory of root.
52 ;;; definitions-in root name
53 ;;; Returns a list of all names defined in the named
54 ;;; subdirectory of root. The list includes alll locally
55 ;;; defined names as well as all names inherited from a
56 ;;; member of a use-list.
57 ;;;
58 ;;; A convenient interface for examining the nature of things:
59 ;;;
60 ;;; ls . various-names
61 ;;;
62 ;;; With no arguments, return a list of definitions in
63 ;;; `(current-module)'.
64 ;;;
65 ;;; With just one argument, interpret that argument as the
66 ;;; name of a subdirectory of the current module and
67 ;;; return a list of names defined there.
68 ;;;
69 ;;; With more than one argument, still compute
70 ;;; subdirectory lists, but return a list:
71 ;;; ((<subdir-name> . <names-defined-there>)
72 ;;; (<subdir-name> . <names-defined-there>)
73 ;;; ...)
74 ;;;
75 ;;; lls . various-names
76 ;;;
77 ;;; Analogous to `ls', but with local definitions only.
78
79 (define-public (local-definitions-in root names)
80 (let ((m (nested-ref root names))
81 (answer '()))
82 (if (not (module? m))
83 (set! answer m)
84 (module-for-each (lambda (k v) (set! answer (cons k answer))) m))
85 answer))
86
87 (define-public (definitions-in root names)
88 (let ((m (nested-ref root names)))
89 (if (not (module? m))
90 m
91 (reduce union
92 (cons (local-definitions-in m '())
93 (map (lambda (m2) (definitions-in m2 '()))
94 (module-uses m)))))))
95
96 (define-public (ls . various-refs)
97 (if (pair? various-refs)
98 (if (cdr various-refs)
99 (map (lambda (ref)
100 (cons ref (definitions-in (current-module) ref)))
101 various-refs)
102 (definitions-in (current-module) (car various-refs)))
103 (definitions-in (current-module) '())))
104
105 (define-public (lls . various-refs)
106 (if (pair? various-refs)
107 (if (cdr various-refs)
108 (map (lambda (ref)
109 (cons ref (local-definitions-in (current-module) ref)))
110 various-refs)
111 (local-definitions-in (current-module) (car various-refs)))
112 (local-definitions-in (current-module) '())))
113
114 (define-public (recursive-local-define name value)
115 (let ((parent (reverse! (cdr (reverse name)))))
116 (and parent (make-modules-in (current-module) parent))
117 (local-define name value)))
118
119 ;;; ls.scm ends here