[plt-scheme] getting a parse tree with bindings info

From: Neil W. Van Dyke (neil at neilvandyke.org)
Date: Tue May 20 18:24:17 EDT 2003

John Clements <clements at brinckerhoff.org> writes at 13:23 20-May-2003 -0400:
> To put it another way, I think you will find that the 'interesting' 
> part of the computation performed by syncheck (that is, the association 
> of bindings with variables and the expansion of macros) is performed by 
> a call to 'expand'.

Thanks!  I've just played with "expand" and "expand-once", and also plan
to look closely at "expand-program" in "drscheme/private/eval.ss".

"expand" doesn't put the information into quite the annotated-source
form I imagined would be most convenient, but I think it probably
contains enough information for my needs.

Background rambling on why I asked, for the curious...

The reason I started thinking from an "annotated source" perspective is
that several of the tools mostly only need to ask (recursively) for a
source sexp, "Is this an application of a procedure that we're hardwired
to treat specially, a procedure application we don't do anything special
about, syntax we've been hardwired to know about, or syntax we don't
recognize and therefore have to skip over?"

One example of such a tool is an interactive explanation system for
Scheme code.  (Though this seems less useful for Scheme than for
syntax-heavy languages.)

Another example is a rule-based "style consultant" (or, to LL1 people,
"Master Programmer Inna Box") that could, without bumping into hard AI
problems, advise students on at least simple improvements they might
want to make to their code.  Some simple examples include `(if (not E) C
A)' replaced with `(if E A C)', `(if E1 C1 (if E2 C2 (if E3 ...)))'
replaced with a `cond' form, a `cond' form that can be replaced with
`case', a `let*' form that can be a `let', reducing some Boolean
expressions, merging immediately nested `let's, etc.  I've found it's
easy to start enumerating these rules by manually cleaning up student
code.  Then there's things like finding largely redundant blocks of
source code that can be abstracted.  There's also fancier expression
rewriting, perhaps mainly by adapting some compiler optimizations to
optimize source readability.

Some of those simple rules might also make fancy interactive editor
commands for DrScheme (things Emacs Scheme-Mode can't really do).

I won't try to defend the utility of these particular examples -- they're
just examples of tools that I'd say deal heavily with the source syntax.


Posted on the users mailing list.