1 ;;;; ls.scm --- functions for browsing modules
3 ;;;; Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
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.
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.
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
20 ;;;; As a special exception, the Free Software Foundation gives permission
21 ;;;; for additional uses of the text contained in its release of GUILE.
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.
29 ;;;; This exception does not however invalidate any other reasons why
30 ;;;; the executable file might be covered by the GNU General Public License.
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.
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.
45 (define-module (ice-9 ls)
46 :use-module (ice-9 common-list))
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.
58 ;;; A convenient interface for examining the nature of things:
60 ;;; ls . various-names
62 ;;; With no arguments, return a list of definitions in
63 ;;; `(current-module)'.
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.
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>)
75 ;;; lls . various-names
77 ;;; Analogous to `ls', but with local definitions only.
79 (define-public (local-definitions-in root names)
80 (let ((m (nested-ref root names))
84 (module-for-each (lambda (k v) (set! answer (cons k answer))) m))
87 (define-public (definitions-in root names)
88 (let ((m (nested-ref root names)))
92 (cons (local-definitions-in m '())
93 (map (lambda (m2) (definitions-in m2 '()))
96 (define-public (ls . various-refs)
97 (if (pair? various-refs)
98 (if (cdr various-refs)
100 (cons ref (definitions-in (current-module) ref)))
102 (definitions-in (current-module) (car various-refs)))
103 (definitions-in (current-module) '())))
105 (define-public (lls . various-refs)
106 (if (pair? various-refs)
107 (if (cdr various-refs)
109 (cons ref (local-definitions-in (current-module) ref)))
111 (local-definitions-in (current-module) (car various-refs)))
112 (local-definitions-in (current-module) '())))
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)))