guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Creating a list of procedures in a file.


From: Daniel Ridge
Subject: Fwd: Creating a list of procedures in a file.
Date: Thu, 19 Nov 2009 22:00:04 -0500

On Nov 19, 2009, at 5:41 PM, Neil Jerram wrote:

Alternatively, assuming that it is safe to do so - i.e. that there are
no possible side-effects from reading - you could just read and process
the script.  Something like:

(with-input-from-file FILENAME
(lambda ()
  (let loop ((x (read)) (defs '()))
    (if (eof-object? x)
        defs
        (loop (read) (if (and (list? x)
                              (>= (length x) 3)
                              (eq? (car x) 'define)
                              (pair? (cadr x)))
                         (cons (caadr x) defs)
                         defs))))))

I go back and forth between this totally static analysis and runtime introspection and I usually come out favoring runtime introspection. Guile's fantastic introspection facilities are one of
the key reasons that I use Guile.

In the static case, above, you win on:

(define (x y) (+ y 5))

but lose on:

(define x (lambda (y) (+ y 5)))

and on:
(begin
 (define (x y) (+ y 5))
)

and on a dozen other top-level forms.

As for (current-module) vs. (resolve-interface '(bogo)), I think the answer is not necessarily so simple.

(module-public-interface (current-module)) might be more appropriate if the goal was to enumerate public interfaces.

On a distantly related note, I encourage interested Guilers to try out a snapshot of my interactive Scheme system 'Proverb'. Its the web-based AJAX Guile shell I use every day (almost all day).

A rough snapshot is available at http://www.cqctworld.org/snap/proverb.tgz . I use it currently with guile-1.8.x and firefox 1.0 - 3.0.x. To run, unpack the tarball and run ./proverb and point your firefox browser at the URL printed on the console.

An online demo of just the Javascript shell portion is available online at: http://www.cqctworld.org/jsshell/jsshell.html This online version is a REPL for Javascript only and not backed by a Scheme system.

To connect Proverb with the present topic, you could type:

(xhtml-find-undefined-in-module (resolve-interface '(guile)))

at the Proverb prompt and see some of the benefits of Guile introspection.

Cheers,
        Dan









reply via email to

[Prev in Thread] Current Thread [Next in Thread]