From: Vagif Verdi
Subject: Optional parameters in lambdas.
Date: 
Message-ID: <2cbfd319-4dcb-45c7-8e86-54799d3a16c1@s37g2000prg.googlegroups.com>
When i work with mapcars i always create small 1,2 maximum 3 parameter
lambdas, and practically always use one letter names like x y z for
parameters. If there are more than 3 params, i usualy just define it
in flet. So i created this very simple macro:

(defmacro -> (&body body)
   `(lambda (&optional x y z) ,@body))

Is it bad that there would be 2 or 1 unused parameter in most cases ?

From: K Livingston
Subject: Re: Optional parameters in lambdas.
Date: 
Message-ID: <c2583411-e475-4bf3-a113-c4668b4646b8@n58g2000hsf.googlegroups.com>
On Mar 23, 9:25 pm, Vagif Verdi <···········@gmail.com> wrote:
> When i work with mapcars i always create small 1,2 maximum 3 parameter
> lambdas, and practically always use one letter names like x y z for
> parameters. If there are more than 3 params, i usualy just define it
> in flet. So i created this very simple macro:
>
> (defmacro -> (&body body)
>    `(lambda (&optional x y z) ,@body))
>
> Is it bad that there would be 2 or 1 unused parameter in most cases ?

Depending on your compiler/lisp that may or may not clean up
efficiently (although you might get some warnings if you don't add
declarations pragmas)...

I think the real crime here is an extreme loss in readability to
everyone else, at a savings of typing "(-> " instead of "(lambda (x) "
as you put it, in most cases, of a whole 8 characters.  Is this bad?
I would say, "absolutely".

If it's really killing you to type "(lambda (x)" I would suggest
instead an editor macro - <ctrl> + <something> .. etc. to write that
for you.  But even that strikes me as a poor solution, as I'm sure you
could (or should) come up with some slightly better variables names,
like "l" to indicate a list, etc.  Although - you could be doing
algebra or something where x, y, and z may be perfect.  Perhaps you
macro should only inject "(lambda (" for you.

Also potentially problematic/confusing is that "->" is frequently used
by logic packages for declaring rules.

In general, I would say, if you are using a macro to defining
something that is 99% equivalent to an existing Common Lisp function,
in this case lambda, you probably want to think twice, or thrice,
about doing it.

Kevin
From: D Herring
Subject: Re: Optional parameters in lambdas.
Date: 
Message-ID: <E92dnWUV9KTyrHranZ2dnUVZ_trinZ2d@comcast.com>
Vagif Verdi wrote:
> When i work with mapcars i always create small 1,2 maximum 3 parameter
> lambdas, and practically always use one letter names like x y z for
> parameters. If there are more than 3 params, i usualy just define it
> in flet. So i created this very simple macro:
> 
> (defmacro -> (&body body)
>    `(lambda (&optional x y z) ,@body))
> 
> Is it bad that there would be 2 or 1 unused parameter in most cases ?

There are various macros floating around that allow expressions such as
(FN (+ !1 (* !2 !3))) => (lambda (!1 !2 !3) (+ !1 (* !2 !3)))
to "do the right thing" by scanning for specially named symbols.

Maybe someone else can chime in with more details; I've seen these on 
this group, but forget who posted them or what they were called.

- Daniel
From: Rob Warnock
Subject: Re: Optional parameters in lambdas.
Date: 
Message-ID: <cuOdneLdPuT_z3ranZ2dnUVZ_tGonZ2d@speakeasy.net>
D Herring  <········@at.tentpost.dot.com> wrote:
+---------------
| Vagif Verdi wrote:
| > (defmacro -> (&body body)
| >    `(lambda (&optional x y z) ,@body))
| > Is it bad that there would be 2 or 1 unused parameter in most cases ?
| 
| There are various macros floating around that allow expressions such as
| (FN (+ !1 (* !2 !3))) => (lambda (!1 !2 !3) (+ !1 (* !2 !3)))
| to "do the right thing" by scanning for specially named symbols.
| 
| Maybe someone else can chime in with more details; I've seen these on 
| this group, but forget who posted them or what they were called.
+---------------

There was a long thread about LAMBDA shortcuts about a year ago.
[My own multiple-implicit-formals hack is called #$ and uses IGNORABLE
(as others have already mentioned) on formals named $1, $2, etc.]

Oh, wait! There was a reprise of the same discussion in early February
of this year, in one of the "Arc" threads talking about the Arc shortcut
syntax of [mod _ 42] expanding to (lambda (_) (mod _ 42)). Kenny started
it all (42 msgs) with <······························@cv.net>.


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Kent M Pitman
Subject: Re: Optional parameters in lambdas.
Date: 
Message-ID: <u63vc4t0i.fsf@nhplace.com>
Vagif Verdi <···········@gmail.com> writes:

> When i work with mapcars i always create small 1,2 maximum 3 parameter
> lambdas, and practically always use one letter names like x y z for
> parameters. If there are more than 3 params, i usualy just define it
> in flet. So i created this very simple macro:
> 
> (defmacro -> (&body body)
>    `(lambda (&optional x y z) ,@body))
> 
> Is it bad that there would be 2 or 1 unused parameter in most cases ?

It's not the style I'd personally use, but...

It's a very slight inefficiency to receive the value and then not use
it, but no, there's no real badness about that.

Some people would think it inelegant for these variable x,y,z to pop out
of nowhere, since that means that in 
 (defun f (x)
   (-> x))
that the visible x is not going to refer to the x that you see.

But you probably want to do
  (declare (ignorable x y z))
just before the ,@body in order to tell the compiler to stop
nagging you about the unused x, y, or z.
From: Vagif Verdi
Subject: Re: Optional parameters in lambdas.
Date: 
Message-ID: <03d5f4a4-56bf-474e-91bd-f9977e6ec519@i29g2000prf.googlegroups.com>
I already had discussion on #lisp, and was quickly convinced that
implicit lexical binding to x y z is a potential trouble, and does not
worth slight reduction in length (not complexity) of code.