Extending Python Syntax with @

David MacQuigg dmq at gain.com
Thu Mar 11 03:44:04 CET 2004


On Thu, 11 Mar 2004 01:28:47 -0000, claird at lairds.com (Cameron Laird)
wrote:

>In article <fkbv40dh57pk9527seaf3etjd0k7kncugc at 4ax.com>,
>David MacQuigg  <dmq at gain.com> wrote:
>			.
>			.
>			.
>>Wouldn't it be nice, for example, if instead of special keywords like
>>'lambda' and 'yield', we had used '@(args)' and '@return'.  ( No, I'm
>>not advocating we go back and change what has been done.)  In both
>>these cases, we had a well-established syntax that needed a slight
>>variation.  
>>
>>The 'lambda function' for example, was needed to cram a small block of
>>code into a tight space.  By saying '@x,y:' instead of 'lambda x,y:',
>>we not only avoid the need for a new keyword, but we better serve the
>>purpose of tightly packing some code.  We would also avoid mystifying
>>beginners.  "It has no magic meaning.  It's just a way to write a
>>function without a name."
>			.
>			.
>			.
>No, for me it would be so far from nice I first suspected you
>of jesting, because, from my background, "lambda" *does* have
>a magic meaning, one that long precedes its (entirely apt) use
>in Python.  For you, '@(args)' might indeed be more evocative;
>for me, not calling a lambda "lambda" would be a big loss.
>
>I think APL and J (and Perl) are plenty meritorious.  I prefer
>Python--much.

I guess this reflects our different backgrounds.  I've been an
electronic design engineer for many years.  I never heard of lambda's
or lambda calculus until learning Python, and the name still doesn't
evoke much meaning for me.  I've never used APL, J, or Perl.  I wonder
how many technical professionals who are *not* programmers would know
what a lambda is?  I wonder if Python is becoming more a language for
programmers, and less for "everyone".

My initial impression in learning Python was that 'lambda' was
something tricky.  Then it became clear it was just a way to cram a
function into a small space like an argument list, except that there
were some strange restrictions on what could be put in the function.
Even now, it seems like 'lambda x,y:' is awkward if you are trying to
save space.  It seems like we have paid a price for the dubious
assumption that most users will benefit from the magic meaning of
'lambda'.

Ruby uses a notation like |x,y|, which is compact, but I don't like
adding special punctuation for every little task. (The Perl problem.)
If the goal is to cram a function into a tight space, we could do it
compactly, and have the extra burden of the new syntax be shared by
many other features.  They key characteristic is that they are small
departures from existing features and syntax, so the symantic burden
is not carried by the @ symbol.  It's just a flag to modify something
already well understood.  All @X says is "I'm like X, but different."
You still need to learn about X.

Again, my intention is not to change lambda functions, but to propose
a better way of introducing new syntax to a language that already has
all the basics worked out.  I would rather have one special symbol
than a bunch of new keywords that mean nothing to me.

-- Dave




More information about the Python-list mailing list