Re: Crazy macro
- From: Ron Garret <rNOSPAMon@xxxxxxxxxxx>
- Date: Sat, 29 Apr 2006 13:19:55 -0700
In article <1146327686.463468.103010@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"Drew McDermott" <airfoyle@xxxxxxxxxxxxxx> wrote:
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.
In that case the tags are redundant. All you need is a privileged
symbol (\... would seem like a natural choice) to indicate that it is to
be replaced by the subsequent form, e.g.:
(control-nest
(multiple-value-let (x y) (frob) \...)
(multiple-value-let (q z) (blurp) (foo \...))
etc...
)
It would be nice to be able to do something like this:
(control-nest
(multiple-value-let (x y) (foo) (if (condition) :then-tag :else-tag))
:then-tag (then-code)
:else-tag (else-code))
but the problem with that is it breaks up your symbol space into those
symbols you can return from a control-nest and those which serve as
tags, which rubs me the wrong way. It makes it hard to find bugs like:
(control-nest
(multiple-value-let (x y) (foo) (if (condition) :than-tag :else-tag))
:then-tag (then-code)
:else-tag (else-code))
My preferred design would use a second form to indicate when something
is a tag, e.g.:
(control-nest
(multiple-value-let (x y) (foo)
(if (condition) (cont then) (cont else)))
then (then-code ... (cont c1))
else (else-code ... (cont c2))
c1 ...
c2 ...)
or something like that.
rg
.
- Follow-Ups:
- Re: Crazy macro
- From: Drew McDermott
- Re: Crazy macro
- References:
- Crazy macro
- From: Drew McDermott
- Crazy macro
- Prev by Date: Re: Decreasing the "standard deviation" of lisp
- Next by Date: Re: Decreasing the "standard deviation" of lisp
- Previous by thread: Re: Crazy macro
- Next by thread: Re: Crazy macro
- Index(es):
Relevant Pages
|
|