[plt-scheme] my solution to printing out module provides

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Jul 2 20:49:25 EDT 2007

On Jul  2, Corey Sweeney wrote:
> Here's my solution to displaying the index of module "provides" in a
> printable format, if anyone wants to use it for themselfs:
> 
> ;list your files here
> (define files
>   (list "file1.ss"
>         "file2.ss"))
> 
> (display "NOTE: IF THERES A MULTIMEDIA FILE IN YOUR FILE LIST, YOUR
> SCREWED!  don't attempt multimedia files :)")
> 
>  (map (lambda (x)
>         (let ([file-contents (read (open-input-file x))])
>           (append (list (second file-contents))
>                   (filter (lambda (a) (and (list? a)
>                                            (< 1 (length a))
>                                            (equal? 'provide (first a))))
>                           file-contents))))
>       files)

(define (module-provides file)
  (syntax-property (expand (with-input-from-file file read))
                   'module-variable-provides))

Or a more general version:

(define (module-info file)
  (let* ([stx   (expand (with-input-from-file file read))]
         [keys  (syntax-property-symbol-keys stx)])
    (map (lambda (key) (list key (syntax-property stx key)))
         keys)))

Even better:

(define (module-info file)
  (let* ([stx   (expand (with-input-from-file file read))]
         [keys  (syntax-property-symbol-keys stx)]
         [props (map (lambda (key) (list key (syntax-property stx key)))
                     keys)])
    (let loop ([x props])
      (cond [(pair? x) (cons (loop (car x)) (loop (cdr x)))]
            [(module-path-index? x)
             (let-values ([(m base) (module-path-index-split x)])
               (cons m (if base (loop base) '())))]
            [else x]))))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.