[plt-scheme] procedure instrospection

From: Eli Barzilay (eli at barzilay.org)
Date: Sat Apr 18 02:54:28 EDT 2009

On Apr 18, Jose A. Ortega Ruiz wrote:
> 
> i see. that's useful, thanks. i was wondering whether it'd be
> possible to somehow hook into the module evaluation process to
> collect metadata while the module is read (or evaluated/expanded),

Some of the information that you originally mentioned is only
collectible while (or after) the code is running, for example, the
callers and callees.  See the code in Matthew's recent post or in the
new `profile' collection on how to get such data.  (But this is will
not be accurate at all...)


> specially for the case of formals names. i'm thinking of something
> simple, and not necessarily 100% accurate--a hash table maintained
> separately, say, recording metadata computed during evaluation.

The real way to do that is if there was a way at the core to make
procedures somehow remember their arguments.  It's not difficult to
add a `lambda' form that does that, but it won't help with existing
code.


> or, as you suggest, i could also read the module source as data, and
> parse it to obtain/cache the information i want (although that
> sounds a bit brittle and more inaccurate, since it relies on the
> program's text instead of syntax data)... i'm guessing that plt
> already provides procedures to help in the task (for instance, ports
> remembering line and columns): any advice on what would be the best
> way to accomplish that?

You can get pretty accurate with that -- for example, reading the
module as syntax (using `read-syntax') and expanding it will catch any
macros that expanded into function definitions.  But it will still be
a problem to get the argument names of a definition like

  (define foo (let (...) (lambda (x y z) ...)))

and it won't help at all with:

  (define blah (compose foo bar))

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


Posted on the users mailing list.