On Sat, 2010-01-16 at 16:52 -0600, Eduardo Cavazos wrote:
> A whole other can of worms is having a way to query the Scheme system
> for information about the available libraries. For example,
>
> * Get a list of available libraries (not just those loaded)
SRFI 104 is designed to assist that. See the below program.
> * For a given library, ask what file it came from
SRFI 104 is designed to do that, using the SRFI 103 algorithm.
'find-library-file-names' tells you all matching files (there might be
more than one, causing shadowing). Or to be told only the first file,
which is the one a Scheme system will load, you can do:
(define (find-first-matching-library-file lib-name)
(let ((lfns (find-library-file-names lib-name)))
(and (not (null? lfns))
(car (join-and-flatten lfns)))))
> * For a given library, get the symbols it exports
> * For a given library, get the import spec
>
> These are pretty easy to cook up as shell scripts (some written in
> Scheme).
> The scripts would be trivial wrappers if this information were
> available via the Scheme implementation.
I don't think Scheme systems should be burdened with providing that,
because it's easily doable yourself, especially when assisted by utility
libraries like SRFI 104.
--
: Derick
----------------------------------------------------------------
(import
(rnrs)
(only (srfi :104 library-files-utilities)
directories-from-env-var
recognized-extensions
library-file-name-info)
(only (srfi :39 parameters)
parameterize)
(only (xitomatl file-system base)
file-directory?
directory-list
directory-walk-enumerator
current-directory)
(only (xitomatl enumerators)
fold/enumerator)
(only (xitomatl file-system paths)
path-join)
(only (xitomatl match)
matches?)
(only (xitomatl library-utils)
library-name<?)
(only (xitomatl lists)
map/filter)
(only (xitomatl common)
printf))
(define (list-probable-collections)
(apply append
(map (lambda (searched-dir)
(list-sort
(lambda (x y) (string<? (car x) (car y)))
(map/filter
(lambda (x)
(and (file-directory? (path-join searched-dir x))
(cons x searched-dir)))
(directory-list searched-dir))))
(directories-from-env-var))))
(define list-libraries
(let ((r6rs-lib?
(matches? (:regex '(: (+ any) #\. (? "ikarus-") "r6rs-lib")))))
(lambda (dir-name)
(list-sort
(lambda (a b) (library-name<? (car a) (car b)))
(fold/enumerator
(directory-walk-enumerator 'top-down)
dir-name
(lambda (path dirs files syms accum)
(values
dirs
(append
accum
(map/filter
(lambda (f)
(and (r6rs-lib? f)
(let* ((lfn (path-join path f))
(li (parameterize ((recognized-extensions
'("ikarus-r6rs-lib" "r6rs-lib")))
(library-file-name-info lfn))))
(and li
(cons (cdr (assq 'library li))
lfn)))))
files))))
'())))))
(for-each
(lambda (x)
(let ((collection (car x))
(searched-dir (cdr x)))
(for-each
(lambda (y)
(let ((lib-name (car y))
(lib-file (cdr y)))
(printf "~s ~s\n" lib-name (path-join searched-dir lib-file))))
(parameterize ((current-directory searched-dir))
(list-libraries collection)))))
(list-probable-collections))
$ ikarus --r6rs-script list-available-libraries.r6rs-prog
[...]
(srfi :0 cond-expand) "/somewhere/srfi/%3A0/cond-expand.r6rs-lib"
[...]
(srfi private registry) "/somewhere/srfi/private/registry.r6rs-lib"
[...]
(xitomatl datum-find) "/somewhere/xitomatl/datum-find.r6rs-lib"
[...]
(xitomatl stack-lang core) "/somewhere/xitomatl/stack-lang/core.r6rs-lib"
[...]