From: Zakath
Subject: Most obfuscated piece of macro you know
Date: 
Message-ID: <4248e3a0$0$2044$636a15ce@news.free.fr>
Hi,

I am still a Lisp beginner but I played quite a lot with macros. It
is a very powerful tool but I also discovered that, as a
side-effect, it can make your code look more cryptic.

That leads us to the following question : what is the most
obscure/obfuscated piece of macro you, dear Lisp hackers, have ever
seen ?

Thanks in advance

Zakath

From: Kenny Tilton
Subject: Re: Most obfuscated piece of macro you know
Date: 
Message-ID: <cz52e.44931$rB3.8455048@twister.nyc.rr.com>
Zakath wrote:
> Hi,
> 
> I am still a Lisp beginner but I played quite a lot with macros. It
> is a very powerful tool but I also discovered that, as a
> side-effect, it can make your code look more cryptic.
> 
> That leads us to the following question : what is the most
> obscure/obfuscated piece of macro you, dear Lisp hackers, have ever
> seen ?

Why don't you start the ball rolling with your discovery? I mean, since 
you already have an example or examples in hand, share that.

i do not get confused by language constructs, I get confused by the 
mechanisms I create sometimes because I program by the seat of my pants. 
  But it won't be macros or classes or functions or specials that 
confuse me, it will be the engines I build from them. ie, something 
always at least one level higher.

which is why I am asking for your known example, because I cannot 
imagine a macro per se confusing me.

kenny

-- 
Cells? Cello? Cells-Gtk?: http://www.common-lisp.net/project/cells/
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film

"Doctor, I wrestled with reality for forty years, and I am happy to 
state that I finally won out over it." -- Elwood P. Dowd
From: Peter Lewerin
Subject: Re: Most obfuscated piece of macro you know
Date: 
Message-ID: <b72f3640.0503290212.7b45fe8c@posting.google.com>
Kenny Tilton <·······@nyc.rr.com> wrote:

> which is why I am asking for your known example, because I cannot 
> imagine a macro per se confusing me.

Something like this would confuse *me*:

  (defmacro setx (value place) `(setf ,place ,val))

i.e. a macro that partly follows (name), partly contradicts (ordering)
expectaction/convention.  It's not that it would necessarily be a bad
idea; this macro could make perfect sense within its context.  It's
just that it would be confusing unless one is prepared for it.

(Again, I *am* easily confused...)
From: Kenny Tilton
Subject: Re: Most obfuscated piece of macro you know
Date: 
Message-ID: <9Ac2e.45860$rB3.8492953@twister.nyc.rr.com>
Peter Lewerin wrote:

> Kenny Tilton <·······@nyc.rr.com> wrote:
> 
> 
>>which is why I am asking for your known example, because I cannot 
>>imagine a macro per se confusing me.
> 
> 
> Something like this would confuse *me*:
> 
>   (defmacro setx (value place) `(setf ,place ,val))
> 
> i.e. a macro that partly follows (name), partly contradicts (ordering)
> expectaction/convention.

OK, but bad names are not specific to macros. I once worked on a tricky 
little app whose four key controlling variables were aa, bb, cc, and 
(wait for it) dd. I had the pleasure of discussing this with the author, 
too. :)

kenny

-- 
Cells? Cello? Cells-Gtk?: http://www.common-lisp.net/project/cells/
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film

"Doctor, I wrestled with reality for forty years, and I am happy to 
state that I finally won out over it." -- Elwood P. Dowd
From: Peter Lewerin
Subject: Re: Most obfuscated piece of macro you know
Date: 
Message-ID: <b72f3640.0503291236.18fb7f96@posting.google.com>
Kenny Tilton <·······@nyc.rr.com> wrote

> OK, but bad names are not specific to macros.

No, but a function or variable can't combine bad (or merely
unfortunate) naming with unexpected redefinitions of the local syntax.
 What I'm trying to get at is that code doesn't have to be cryptic or
obfuscated to be confusing.  I now realize that the OP was indeed
asking for examples of "cryptic or obfuscated", so I'll shut up now.
From: Kaz Kylheku
Subject: Re: Most obfuscated piece of macro you know
Date: 
Message-ID: <1112108554.204417.290290@f14g2000cwb.googlegroups.com>
Zakath wrote:
> Hi,
>
> I am still a Lisp beginner but I played quite a lot with macros. It
> is a very powerful tool but I also discovered that, as a
> side-effect, it can make your code look more cryptic.

Macros make your code look exactly how you want it. If the code is
unnecessarily cryptic, it's because you designed the macro that way, or
abused a given macro beyond its intended use.

We encode programs by cramming their meaning into high-level
abstractions (that's why it's called ``code''). Because programs are
written in code, they are all cryptic in the sense that you can't
understand the code if you don't know the abstractions.

Abstractions create a barrier against understanding that you have to
cross once. You learn the abstraction, and if you learn it well then
you properly understand it whenever you encounter it in the program
code. If the programmer  hadn't developed and used the abstraction,
then he would have created a permanent barrier against understanding,
recurring in every part of the program where the abstraction ought to
have been used.

When I say abstractions, that isn't confined to macro operators, but
covers functions too, as well as data abstraction and everything else.
From: ···············@yahoo.com
Subject: Re: Most obfuscated piece of macro you know
Date: 
Message-ID: <1112117044.167309.105010@o13g2000cwo.googlegroups.com>
This macro is not obscure, but clear.  Helpful.  Talkative.  Manically
talkative...

(defmacro deep-trace (form)
  (let ((g (gensym)))
    `(let ((,g ,(if (atom form)
                    form
                  (cons (first form)
                        (mapcar #'(lambda (arg)
                                    `(deep-trace ,arg))
                                (rest form))))))
       (format t "~&~S => ~S" ',form ,g)
       ,g)))

CL-USER(6): (deep-trace (+ 1 2 (+ 3 4)))
1 => 1
2 => 2
3 => 3
4 => 4
(+ 3 4) => 7
(+ 1 2 (+ 3 4)) => 10
10

It works on some special forms.

CL-USER(9): (deep-trace (if (< 2 3) 1776 1789))
2 => 2
3 => 3
(< 2 3) => T
1776 => 1776
(IF (< 2 3) 1776 1789) => 1776
1776

Exercise: why doesn't
(deep-trace (if (< 2 3) 'cow 'horse))
return 'cow?  Fix this bug.
Hint: (quote ...) is a special form.

Exercise: identify and fix similar problems, e.g. with (function ...).
From: Frank Buss
Subject: Re: Most obfuscated piece of macro you know
Date: 
Message-ID: <d2b7ks$20g$1@newsreader3.netcologne.de>
Zakath <···········@laposte.net> wrote:

> I am still a Lisp beginner but I played quite a lot with macros. It
> is a very powerful tool but I also discovered that, as a
> side-effect, it can make your code look more cryptic.

then you didn't define the right macros. Macros should lead to better 
readable programs. Perhaps the macro itself can be complicated, but the 
code which uses the macro should be better to read than without the macro.

> That leads us to the following question : what is the most
> obscure/obfuscated piece of macro you, dear Lisp hackers, have ever
> seen ?

Macros can be complicated, but it's all Lisp with the same easy syntax. 
Searching at Google for "defmacro obfuscated" gives 29 results, compared to 
5120 results for "c++ template obfuscated" :-)

-- 
Frank Bu�, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de