ls.scm 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ;;;; ls.scm --- functions for browsing modules
  2. ;;;;
  3. ;;;; Copyright (C) 1995, 1996, 1997, 1999, 2001, 2006 Free Software Foundation, Inc.
  4. ;;;;
  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.
  9. ;;;;
  10. ;;;; This library 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 GNU
  13. ;;;; Lesser General Public License for more details.
  14. ;;;;
  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
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. ;;;;
  19. (define-module (ice-9 ls)
  20. :use-module (ice-9 common-list)
  21. :export (local-definitions-in definitions-in ls lls
  22. recursive-local-define))
  23. ;;;;
  24. ;;; local-definitions-in root name
  25. ;;; Returns a list of names defined locally in the named
  26. ;;; subdirectory of root.
  27. ;;; definitions-in root name
  28. ;;; Returns a list of all names defined in the named
  29. ;;; subdirectory of root. The list includes alll locally
  30. ;;; defined names as well as all names inherited from a
  31. ;;; member of a use-list.
  32. ;;;
  33. ;;; A convenient interface for examining the nature of things:
  34. ;;;
  35. ;;; ls . various-names
  36. ;;;
  37. ;;; With no arguments, return a list of definitions in
  38. ;;; `(current-module)'.
  39. ;;;
  40. ;;; With just one argument, interpret that argument as the
  41. ;;; name of a subdirectory of the current module and
  42. ;;; return a list of names defined there.
  43. ;;;
  44. ;;; With more than one argument, still compute
  45. ;;; subdirectory lists, but return a list:
  46. ;;; ((<subdir-name> . <names-defined-there>)
  47. ;;; (<subdir-name> . <names-defined-there>)
  48. ;;; ...)
  49. ;;;
  50. ;;; lls . various-names
  51. ;;;
  52. ;;; Analogous to `ls', but with local definitions only.
  53. (define (local-definitions-in root names)
  54. (let ((m (nested-ref root names))
  55. (answer '()))
  56. (if (not (module? m))
  57. (set! answer m)
  58. (module-for-each (lambda (k v) (set! answer (cons k answer))) m))
  59. answer))
  60. (define (definitions-in root names)
  61. (let ((m (nested-ref root names)))
  62. (if (not (module? m))
  63. m
  64. (reduce union
  65. (cons (local-definitions-in m '())
  66. (map (lambda (m2) (definitions-in m2 '()))
  67. (module-uses m)))))))
  68. (define (ls . various-refs)
  69. (if (pair? various-refs)
  70. (if (cdr various-refs)
  71. (map (lambda (ref)
  72. (cons ref (definitions-in (current-module) ref)))
  73. various-refs)
  74. (definitions-in (current-module) (car various-refs)))
  75. (definitions-in (current-module) '())))
  76. (define (lls . various-refs)
  77. (if (pair? various-refs)
  78. (if (cdr various-refs)
  79. (map (lambda (ref)
  80. (cons ref (local-definitions-in (current-module) ref)))
  81. various-refs)
  82. (local-definitions-in (current-module) (car various-refs)))
  83. (local-definitions-in (current-module) '())))
  84. (define (recursive-local-define name value)
  85. (let ((parent (reverse! (cdr (reverse name)))))
  86. (and parent (make-modules-in (current-module) parent))
  87. (local-define name value)))
  88. ;;; ls.scm ends here