Crazy macro



I have invented a macro that I believe is fairly novel, and have become
somewhat fond of. On the other hand, the macro is a little weird. I
present it to the world to see if anyone thinks it should be strangled
in the crib or allowed to flourish.

The problem the macro addresses is the 'Vietnamization" of Lisp code,
the tendency of large programs to wander off to the right as
indentation gets deeper and deeper. Many people advocate
breaking large programs into little functions to avoid such problems,
but I resist that. For one thing, it creates a lot of functions with
no real reason for existence. For another, if the program's current
state is stored in several local variables, then they must all be
passed as arguments to the little functions, and many must be returned
as values. Finally, if one's code is well commented, so that each
segment is understandable, I don't see any reason why the absence of
function boundaries at the segments should freak out someone reading
it.

So, we need a way to avoid Vietnamization while preserving the fact
that we're reading a single piece of code. Here's where the macro
comes in. It's called 'control-nest.' A call looks like this:

(control-nest
:tag1
exp1[:tag2]
:tag2
exp2[:tag3]
...
:tagN
expN)

Each expI should contain exactly one occurrence of tag{I+1}, except for
expN. Writing expI(e) to means expI with tag{I+1} replaced by e, the
call to 'control-nest' expands to
exp1(exp2(...expN))

As an example, we can use 'control-nest' to provide the functionality
of 'let*' for 'multiple-value-let':

(control-nest
(multiple-value-let (x y z)
(foo ...)
:bind-p-q)
:bind-p-q
(multiple-value-let (p q)
(baz x y)
:bind-r-s)
:bind-r-s
(multiple-value-let (r s)
(zap x p)
...)))

expands to

(multiple-value-let (x y z)
(foo ...)
(multiple-value-let (p q)
(baz x y)
(multiple-value-let (r s)
(zap x p)
...)))

(Notice that we didn't provide 'tag1' here; it's optional because it
plays no actual role in expanding the macro.)

Any comments?

By the way, this macro is included in YTools
(http://www.cs.yale.edu/homes/dvm/#software).

-- Drew McDermott
Yale University

.



Relevant Pages

  • Re: Crazy macro
    ... the macro is a little weird. ... (multiple-value-let (x y z) ... (baz x y) ... (zap x p) ...
    (comp.lang.lisp)
  • Re: initialising array of unknown size (newbie)
    ... Note what the macro Arows expands to ... Note what the macro Acols expands to ... the integer returned by mat_multis now converted to a float. ...
    (comp.lang.c)
  • Re: Crazy macro
    ... the macro is a little weird. ... In that case the tags are redundant. ... be replaced by the subsequent form, ...
    (comp.lang.lisp)
  • Re: QteAddViewMap api
    ... preprocessor that expands macros from the *INPUT file of the ... What is the MAPA0100 encoding for a macro statement in the *input/from ... For the macro line being expanded I have tried map type = 1 ... /EndMacro lines are not included in the output view the debugger does ...
    (comp.sys.ibm.as400.misc)
  • Re: More problems with complex notation
    ... The macro _Complex_I expands to a constant expression of type const ... float _Complex, with the value of the imaginary unit. ... 1.0i does seem like the obvious notation. ...
    (comp.std.c)