ls.scm 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. (define-module (ice-9 ls)
  21. :use-module (ice-9 common-list))
  22. ;;;;
  23. ;;; local-definitions-in root name
  24. ;;; Returns a list of names defined locally in the named
  25. ;;; subdirectory of root.
  26. ;;; definitions-in root name
  27. ;;; Returns a list of all names defined in the named
  28. ;;; subdirectory of root. The list includes alll locally
  29. ;;; defined names as well as all names inherited from a
  30. ;;; member of a use-list.
  31. ;;;
  32. ;;; A convenient interface for examining the nature of things:
  33. ;;;
  34. ;;; ls . various-names
  35. ;;;
  36. ;;; With no arguments, return a list of definitions in
  37. ;;; `(current-module)'.
  38. ;;;
  39. ;;; With just one argument, interpret that argument as the
  40. ;;; name of a subdirectory of the current module and
  41. ;;; return a list of names defined there.
  42. ;;;
  43. ;;; With more than one argument, still compute
  44. ;;; subdirectory lists, but return a list:
  45. ;;; ((<subdir-name> . <names-defined-there>)
  46. ;;; (<subdir-name> . <names-defined-there>)
  47. ;;; ...)
  48. ;;;
  49. ;;; lls . various-names
  50. ;;;
  51. ;;; Analogous to `ls', but with local definitions only.
  52. (define-public (local-definitions-in root names)
  53. (let ((m (nested-ref root names))
  54. (answer '()))
  55. (if (not (module? m))
  56. (set! answer m)
  57. (module-for-each (lambda (k v) (set! answer (cons k answer))) m))
  58. answer))
  59. (define-public (definitions-in root names)
  60. (let ((m (nested-ref root names)))
  61. (if (not (module? m))
  62. m
  63. (reduce union
  64. (cons (local-definitions-in m '())
  65. (map (lambda (m2) (definitions-in m2 '()))
  66. (module-uses m)))))))
  67. (define-public (ls . various-refs)
  68. (if (pair? various-refs)
  69. (if (cdr various-refs)
  70. (map (lambda (ref)
  71. (cons ref (definitions-in (current-module) ref)))
  72. various-refs)
  73. (definitions-in (current-module) (car various-refs)))
  74. (definitions-in (current-module) '())))
  75. (define-public (lls . various-refs)
  76. (if (pair? various-refs)
  77. (if (cdr various-refs)
  78. (map (lambda (ref)
  79. (cons ref (local-definitions-in (current-module) ref)))
  80. various-refs)
  81. (local-definitions-in (current-module) (car various-refs)))
  82. (local-definitions-in (current-module) '())))
  83. (define-public (recursive-local-define name value)
  84. (let ((parent (reverse! (cdr (reverse name)))))
  85. (and parent (make-modules-in (current-module) parent))
  86. (local-define name value)))
  87. ;;; ls.scm ends here