This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: modules


   From: David Pirotte <david@altosw.be>
   Date: Tue, 23 May 2000 02:24:25 +0200

   - how do I query guile to know what modules have been loaded ?
   - how do I know in which name space I am
   - how do I know what symbols are 'available' in the name space I am in

check out ice-9/ls.scm:

	;;;; ls.scm --- functions for browsing modules

i think the code is a bit dated, though.  the last time i played w/
ice-9/ls.scm, i wound up writing my own module-browsing ls.scm, appended
below.  warning: the last time i used ttn/ls.scm was in february, so it
may not work these days w/ cvs guile...

thi


---------------------
;;; ttn/ls.scm --- Commands for interactive module browsing

;; $State: Exp $:$Name:  $
;;
;; Copyright (C) 2000 Thien-Thi Nguyen
;; This file is part of ttn's personal scheme library, released under GNU
;; GPL with ABSOLUTELY NO WARRANTY.  See the file COPYING for details.

;;; Commentary:

;; Yes, (ice-9 ls) and (ice-9 session) exist.  But the `ls' provided is
;; weird.  So this interface is provided.  All visited modules are registered
;; and given nicknames.

;;; Code:

(define-module (ttn ls)
  :use-module (ice-9 session))

(export

 cm ;;; [new-module]
 ;; Change module to NEW-MODULE, which can be a nickname (symbol), or
 ;; a list in the traditional module sense.  If NEW-MODULE is omitted,
 ;; the registered modules are displayed.

 ls ;;; [regexp]
 ;; Display symbols matching regular expression REGEXP, including where
 ;; they came from.  If REGEXP is omitted, all symbols are displayed.

 )

(define %known-modules '((guile-user . (guile-user))))

(defmacro cm new-module
  (cond ((eq? '() new-module)
         (write-line "known modules:")
         (for-each (lambda (pair)
                     (display (car pair))
                     (display " . ")
                     (write-line (cdr pair)))
                   %known-modules)
         (newline))
        ((list? (car new-module))
         (set! %known-modules (cons (cons (car (reverse (car new-module)))
                                          (car new-module))
                                    %known-modules))
         `(define-module ,(car new-module)))
        (else
         (let ((try (assq (car new-module) %known-modules)))
           (if try
               `(define-module ,(cdr try))
               (error "Nickname not found"))))))

(define (ls . regexp)
  (apropos (if (eq? '() regexp) '. (car regexp))))

;;;---------------------------------------------------------------------------
;;; now make available to everyone

(module-define! the-scm-module 'cm cm)
(module-define! the-scm-module 'ls ls)

;;; ttn/ls.scm ends here

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]