Subject: Re: define-syntax: considered harmful.
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1998/06/04
Newsgroups: comp.lang.scheme
Message-ID: <6l5rar$4pkbs@fido.engr.sgi.com>

Kellom{ki Pertti  <pk@kuovi.cs.tut.fi> wrote:
+---------------
| Ray Dillinger <bear@sonic.net> writes:
| > We have a wonderful, powerful language here; we can express 
| > anything we want simply and in a reasonably straightforward 
| > way with procedure calls.  Very rarely do we actually need 
| > additional syntax.
| 
| This is exactly my impression. Give me a concise way of writing
| (lambda () expr), and I will forget I ever heard about macros.
+---------------

	> (defmacro @ body
	    `(lambda () ,@body))

	> (@ (+ 1 2))
	#<procedure>

	> ((@ (+ 1 2)))
	3

	> (dynamic-wind (@ #f) (@ (+ 1 2)) (@ (print "Yippee!")))
	Yippee!
	3

[Given the lambasting after my last attempt at humor, I should hasten
to say this is *NOT* a serious suggestion!]


-Rob

p.s. Newbie nostalgia:  Actually, when I first started coding Scheme,
back before the typing sequence "lambda" got wired into my fingers,  ;-}
there was a time when I *did* have a similar sentiment to Pertti's.
I wanted to use ".\", which looks sort of like a lambda, but dot is,
well, dot, and backslash is a lexical escape character, so you can't.
But then I thought of this really *horrible* hack, which was to make
the name of the lambda macro be (string->symbol (string #\space)),
a.k.a. "| |" a.k.a. "\ ", for the general lambda, and "\\" for the
argumentless thunk. And whaddya know, it *worked*!

	> (defmacro \ (args . body)
	    `(lambda ,args ,@body))

	> (defmacro \\ body
	    `(lambda () ,@body))

	> (\ (x y) (+ x y))
	#<procedure>

	> (map (\ (x y) (+ x y)) '(1 2 3) '(4 5 6))
	(5 7 9)

	> (\\ (+ 1 2))
	#<procedure>

	> ((\\ (+ 1 2)))
	3

	> (dynamic-wind (\\ #f) (\\ (+ 1 2)) (\\ (print "Yippee!")))
	Yippee!
	3

But one quickly tires of that. It's just not worth making one's code look
so, well, "weird" -- especially since you have to be careful to leave an
"extra" space when defining a closure with indefinite args or the &rest arg
will get "eaten" by the escaped space:

	> (\ (x y) (+ x y))	; not a problem, the "(" stops the ID formation
	#<procedure>
	> (\  rest (apply print rest))  ; not a problem, "extra" space
	#<procedure>
	> (\ rest (apply print rest))	; Oops!
	reference to undefined identifier: | rest|
	> 

So I eventually gave it up and just used a "vi" abbreviation macro
for a while, and then finally the sequence L A M B D A got wired into
my fingers and one fine day I found I'd even stopped using the editor
accelerator...

p.p.s. I also find Olin's use of the "?" macro as a synonym for "cond" to
be a bit much, too. Easier to type maybe, but *harder* to read. But YMMV...

-----
Rob Warnock, 7L-551		rpw3@sgi.com   http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
2011 N. Shoreline Blvd.		FAX: 650-933-4392
Mountain View, CA  94043	PP-ASEL-IA