Re: Crazy macro



"Drew McDermott" <airfoyle@xxxxxxxxxxxxxx> wrote in message
news:1146327686.463468.103010@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.

I was ready to reply by here that you should use local functions, this is
IMO exactly what they are there for. But I continued reading anyway...

So, we need a way to avoid Vietnamization while preserving the fact
....
(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)
...)))


I stand by my knee-jerk reaction.

(flet ((doit ()
(lots of non-overindented stuff)
(all of it using x y z p q r s)))
(multiple-value-let (x y z)
(foo ...)
(multiple-value-let (p q)
(baz x y)
(multiple-value-let (r s)
(zap x p)
(doit))))


I know flet already introduces alot of indentation, it might be acceptable
with a lot of local functions to do

(flet
((foo ()
...)
(bar ()
...))
...)

My 2cents...

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")


.



Relevant Pages

  • Crazy macro
    ... the macro is a little weird. ... call to 'control-nest' expands to ... (multiple-value-let (x y z) ...
    (comp.lang.lisp)
  • Re: Crazy macro
    ... (multiple-value-let (x y z) ... (zap x p) ...
    (comp.lang.lisp)