[plt-scheme] my solution to printing out module provides
Also note that it is easy to make non-text files work too. You have to
run in the graphical language, but instead of doing this:
(with-input-from-file file read)
do this:
(let ([t (new text%)])
(send t load-file file)
(read (open-input-text-editor t)))
Robby
On 7/2/07, Eli Barzilay <eli at barzilay.org> wrote:
> 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!
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>