ls.scm 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ;;;; ls.scm --- functions for browsing modules
  2. ;;;;
  3. ;;;; Copyright (C) 1995, 1996, 1997, 1999, 2001, 2006, 2010 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 3 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-module root names)))
  55. (if m
  56. (module-map (lambda (k v) k) m)
  57. (nested-ref root names))))
  58. (define (definitions-in root names)
  59. (let ((m (nested-ref-module root names)))
  60. (if m
  61. (reduce union
  62. (cons (local-definitions-in m '())
  63. (map (lambda (m2) (definitions-in m2 '()))
  64. (module-uses m))))
  65. (nested-ref root names))))
  66. (define (ls . various-refs)
  67. (if (pair? various-refs)
  68. (if (cdr various-refs)
  69. (map (lambda (ref)
  70. (cons ref (definitions-in (current-module) ref)))
  71. various-refs)
  72. (definitions-in (current-module) (car various-refs)))
  73. (definitions-in (current-module) '())))
  74. (define (lls . various-refs)
  75. (if (pair? various-refs)
  76. (if (cdr various-refs)
  77. (map (lambda (ref)
  78. (cons ref (local-definitions-in (current-module) ref)))
  79. various-refs)
  80. (local-definitions-in (current-module) (car various-refs)))
  81. (local-definitions-in (current-module) '())))
  82. (define (recursive-local-define name value)
  83. (let ((parent (reverse! (cdr (reverse name)))))
  84. (module-define! (make-modules-in (current-module) parent)
  85. name value)))
  86. ;;; ls.scm ends here