encap

Author: Tom Breton

Updated:

Summary

Code to convert sexps to independent functions etc

Commentary

This code lets you excerpt list-forms in a few keystrokes, without
(much) chance of changing their logic.  

NB, some of the weirder stuff, like unquoted lambda forms in
macros, can still be altered in small ways.

Also NB, it is important to properly tell function-types (defuns,
etc) what should be a parm and what shouldn't.

We automatically remove any redundant surrounding (progn ... ) when
building a function.  This lets the user build a progn surrounding
more than one expression and then encap it.


The use of insert-parentheses or tehom-insert-parentheses is
recommended with this, to cut your keystrokes down to a bare
minimum with numeric prefix args

Non-features

A variant could grab the next/previous N sexps into a progn or
list.  That requires much more understanding of the code, and
co-ordination as to which types we may produce.  It makes more
sense to just do it by hand.  

Instead of assuming only leaves may be parms, we could assume that
any form may be a literal.  But building the interaction for that
is much harder, and much harder for the user to navigate.
   
A variant, or just another def-type, could write the definition
into an enclosing let statement (let*, flet, etc as appropriate).
This requires searching, using backward-up-list a lot.
   
Another variant could read it from a let statement, understanding
the form as different than forms inside progn's etc.

Could walk the code better, not collecting "arguments" that are
defined intermediately, eg in a let form.  In its pure form. this
would involve expanding macros.  

It could also not quote lambdas-transformed-to-calls when they
shouldn't be quoted, eg in some macros.  Again, would require
code-walking and macro expansion.

It would be quite difficult to support macroizing list-forms, since
it's not clear what could and couldn't be args.

One approach is that the user could transform the whole thing into
an (eval `()) form (or instead of backquote, build lists, etc) and
then we could strip off the eval and transform it into a macro.
That only requires that the user write "eval" and "`", and commas
as needed, and surround forms that should spread out with ,@'(...)
It can pretty much be done in place with a few numeric arguments.

Dependencies