469,323 Members | 1,567 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

Extending Python Syntax with @

Seems like we need a simple way to extend Python syntax that doesn't
break existing syntax or clash with any other syntax in Python, is
easy to type, easy to read, and is clearly distinct from the "base"
syntax. Seems like we could put the @ symbol to good use in these
situations. Examples:

print @(separator = None) x, y, z

@x,y:x*x+y*y -- anonymous function

@f(x,y) -- generator function that can accept new arguments
with each call

@x @y @z -- short for instance variables in a method definition

Each of these examples is debatable, but my point is that there are
many enhancement requests like this, and some may be worthy of
inclusion in the core language. It would be nice if there was a
consistent way to add stuff like this. It certainly beats adding ugly
statements like 'lambda'.

It might even be possible to allow limited extension of the language
by users, provided the extensions are introduced by the special
symbol. This would allow the flexibility of Ruby or Lisp without the
cost of forking the language into many dialects.

Maybe we should collect a bunch of little enhancements like the above,
and put them all into one PEP. Any suggestions? Pet peeves? Stuff
you would like to see, but not worthy of a PEP by itself?

-- Dave

Jul 18 '05
75 3467
py****@rcn.com (Raymond Hettinger) writes:
Guido at one time wished that print was a function instead of a
statement. Here's your chance to push that idea forward.


What about the assert statement? Should that be a function too?
Jul 18 '05 #51
On Thu, 11 Mar 2004 21:42:54 +0100, Peter Maas
<fp********@netscape.net> wrote:

Peter Maas:
- The advantage is also a disadvantage: a lowered barrier for
new semantics could bloat the language definition. Python's
strength is that it has *few* concepts that are usable in *many*
places. This could be compromised by your proposal.

David MacQuigg: This is actually a separate issue. Adding a few @ mods to selected
statements does not mean that users can add their own.

Peter Maas: I assumed that in my response but also GvR and the Python community
can do too much with @.


I have enormous faith in GvR and the people working with him. I can't
imagine them falling into the Perl trap (overuse of symbols in a
syntax).

-------

Peter Maas:
- Python is a readable language. lambda says "function literal",
yield says "generator", @ just says "different". Python would
be less readable if this notation would be adopted.

David MacQuigg:
Readability, in this case, is in the eye of the beholder. 'lambda' to
me says 'wavelength', which I know has nothing to do with programming.
I suspect many users are like me, not enough computer science
background to know that lambda means 'function literal'.

Peter Maas:
:-)) OK, of course I was talking about the semantics within the
language framework. Otherwise you could claim that def says deaf and
for says four ;-)

I really wasn't trying to be clever with words in telling you what
comes to my mind with 'lambda'. Thinking back on my experience
learning Python, I can also say that this word, and the mystique
around "lambda calculus" also conveyed a subtle meaning of "complex",
or "advanced topic", which caused me to avoid lambdas for a few
months. I took five years of calculus in college, and I still don't
see the connection between lambda functions and calculus.

Let's focus on users of Python, many of whom are technical
professionals, but not computer scientists. All I'm saying is that
new keywords like lambda can have the opposite of the intended
simplifying effect. They can make things *seem* more complex. It all
depends on users perceptions and their background.

I was astonished to learn today that GvR himself called for the
deprecation of lambda, citing "confusing" as one of the reasons.
http://python.org/doc/essays/ppt/regrets/4
This guy is a language genious, yet he still understands the ordinary
users perspective. A *rare* combination.

-- Dave
Jul 18 '05 #52
co**********@physics.mcmaster.ca (David M. Cooke) writes:
The lambda depends on a global variable too (or at least, a variable
up one scope).
That's quite a significant difference. The *result* of the lambda
does not depend on a global variable.
def make_translation_function(GCPs, type, invert=False):
if type == 'LSF' and len(GCPs) < 12:
# Do lots of time-consuming magic to calculate A, B, ...
def LSF_function(x, y):
xy = x*y
lon = x*A + y*B + xy*C + ...
lat = x*G + y*H + xy*I + ...
return (lon, lat)
return LSF_function


Ah...*that's* what I needed. I hadn't considered that a defined
function could be passed out of the scope like that.

Thank you.

--kyler
Jul 18 '05 #53
Kyler Laird <Ky***@news.Lairds.org> writes:
Richie Hindle <ri****@entrian.com> writes:

[Kyler]
How do you cleanly do that?
foo = range(-10, 10)
my_op = lambda x: float(x) / max(map(abs, foo))
bar = map(my_op, foo)
foo = range(-10, 10)
def my_op(x):
return float(x) / max(map(abs, foo))
bar = map(my_op, foo)


Well, your solution depends on a global variable.


foo ? my_op ?
Doesn't the same apply to the lambda example ?
def make_translation_function(GCPs, type, invert=False):
if type == 'LSF' and len(GCPs) < 12:
# Do lots of time-consuming magic to calculate A, B, ...
return(
lambda x, y: (
x * A + y * B +
x * y * C +
...,
x * G + y * H +
x * y * I +
...
)
)
elif ... # Repeat lots of times for variations.


Isn't this just a more detailed example of the same thing ?
With a similar solution :

def make_translation_function(GCPs, type, invert=False):
if type == 'LSF' and len(GCPs) < 12:
# Do lots of time-consuming magic to calculate A, B, ...
def translation_fn(x, y):
return (
x * A + y * B +
x * y * C +
...,
x * G + y * H +
x * y * I +
...
)
return translation_fn
elif ... # Repeat lots of times for variations.

Quick variation using working code:

def makefn(a, b):
A = a*3
B = b * 2
def my_op(x, y):
return (x*A + y*B, (x+A)*(y+B))
return my_op

x = makefn(1, 1)
print x(2, 2)

Regards, Myles.
Jul 18 '05 #54
In article <i5********************************@4ax.com>,
David MacQuigg <dm*@gain.com> wrote:
Jul 18 '05 #55
Cameron Laird wrote:
There are other calculi--"quaternion calculus" and "vector
calculus" are two not-too-uncommonly-heard ones.


Indeed, in mathematics the word "calculus" really just
means a method of calculating something. It's actually
the Latin word for "stone", presumably dating back to
the time when people used stones as counters when
doing arithmetic.

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg

Jul 18 '05 #56
Paul Rubin wrote:
What about the assert statement? Should that be a function too?


No, because then the compiler wouldn't be able to optimise
it away when asserts are turned off.

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg

Jul 18 '05 #57
Ben Finney <bi****************@and-benfinney-does-too.id.au> wrote in message news:<sl*******************************@iris.polar .local>...
On Wed, 10 Mar 2004 16:50:58 -0500, John Roth wrote:
Someday people will get over their attachment with being able to write
programs with any old text editor that happens to be lying around, and
being able to print their programs without needing a special
formatting program, but that day isn't today, and I doubt if it's
tomorrow.


I doubt it's ever, because such a day would have to be preceded by the
day when programs no longer need to be inspected, maintained or
transferred between systems not specifically set up as developer
workstations.


funny thing is VB has survived this long just because you HAVE to have
the IDE to edit the code. That is one of the biggest selling points of
VB.

It should not be an issue, just make all the IDE's cross platform.

All the worth while Java IDE's are cross platform. Intellij IDEA and
Together.
Maybe Eclipse but it is pretty buggy compared to the commerical
offerings.

That is what Python is missing is an quality IDE that is cross
platform. All the ones out now suck when compared to something like
IDEA or Together.

anyone that thinks about following up this post with anything about vi
or emacs can just stop right now and go back to their hole.
Jul 18 '05 #58
Cameron Laird wrote:
Forth. Lisp. Tcl.


I was thinking of even less than that. Just define a few flow control
things and get everything out of the objects. I expect it would look
either like lisp or smalltalk.

There would only be one built in datatype, the message, and all the
objects would chuck messages around. Thus the language as such would
have a very limited syntax.

load Object.class;
load Stream.class;

x = new Object;
s = new Stream;

s.print x.to_string;

So we have declare variables, load classes and pass messages.
Jul 18 '05 #59
Y2KYZFR1 wrote:
That is what Python is missing is an quality IDE that is cross
platform. All the ones out now suck when compared to something like
IDEA or Together.

anyone that thinks about following up this post with anything about vi
or emacs can just stop right now and go back to their hole.


An IDE isn't worth much in many use cases. I see the reason in it when
developing gui apps. But for my work I honestly don't see any use for it.

Basically a good tabbed editor suits my needs.

The only two things I really miss is:

1) A good refactoring tool. Search and replace can be a bit hit'n miss
sometime.

2) A context aware class browser, that would show the classes with the
methods & defined attributes they have in the current context. So that I
could do a little less grep'ing and manual backtracking of ancestor objects.

So maybe I *do* ned a good IDE anyway :-)
regards Max M
Jul 18 '05 #60

"Peter Hickman" <pe***@semantico.com> wrote in message
news:40**********************@news.easynet.co.uk.. .
Cameron Laird wrote:
Forth. Lisp. Tcl.


I was thinking of even less than that. Just define a few flow control
things and get everything out of the objects. I expect it would look
either like lisp or smalltalk.

There would only be one built in datatype, the message, and all the
objects would chuck messages around. Thus the language as such would
have a very limited syntax.

load Object.class;
load Stream.class;

x = new Object;
s = new Stream;

s.print x.to_string;

So we have declare variables, load classes and pass messages.'


Have you looked at Io?

John Roth
Jul 18 '05 #61
"Y2KYZFR1" <ja*************@yahoo.com> wrote in message
news:c7**************************@posting.google.c om...
Ben Finney <bi****************@and-benfinney-does-too.id.au> wrote in message news:<sl*******************************@iris.polar .local>...
On Wed, 10 Mar 2004 16:50:58 -0500, John Roth wrote:
Someday people will get over their attachment with being able to write
programs with any old text editor that happens to be lying around, and
being able to print their programs without needing a special
formatting program, but that day isn't today, and I doubt if it's
tomorrow.


I doubt it's ever, because such a day would have to be preceded by the
day when programs no longer need to be inspected, maintained or
transferred between systems not specifically set up as developer
workstations.


funny thing is VB has survived this long just because you HAVE to have
the IDE to edit the code. That is one of the biggest selling points of
VB.

It should not be an issue, just make all the IDE's cross platform.

All the worth while Java IDE's are cross platform. Intellij IDEA and
Together.
Maybe Eclipse but it is pretty buggy compared to the commerical
offerings.
Java IDEs are cross platform because they're in Java, which is
cross-platform. IDLE is cross-platform because it's written in
Python, which is cross-platform.
That is what Python is missing is an quality IDE that is cross
platform. All the ones out now suck when compared to something like
IDEA or Together.
Well, yes. I tried using IDLE, and the little things that didn't work
the way I expected (or work at all) made me go back to PythonWin.
PythonWin is hardly ideal either: it's just based on a very good
editor. You can't use the Bicycle Repair Man refactoring plugin,
and the run facility sucks. It's just better than IDLE.

There are supposed to be Python plugins for Eclipse, but every time
I look for them I find stuff that is so far from ready for prime time that
they're embarassing.
anyone that thinks about following up this post with anything about vi
or emacs can just stop right now and go back to their hole.

Jul 18 '05 #62
John Roth wrote:
Have you looked at Io?


It's on my list after I've had a go at lua
Jul 18 '05 #63
> How much real development (I don't mean archiving) do we do
today on systems without appropriate tools? Very little. The issue
isn't trying to develop on systems without appropriate tools, it's
developers that won't use tools that help them work.


One class of people: end users.

Usually, end users don't need to have an IDE, they just use (not write)
software without a care in the world. Occasionally, they need to edit
something (it happens to everyone at some time), and they need to break
out a text editor. Usually this is an INI file, but there are scenarios
with applications that ship with an interpreter (Freedom Force) that
allow people to change them.

Really the ultimate question is whether we (computer scientists,
engineers, or anyone who programs) want to limit programming to those
with an IDE? I think doing so is wasteful, and requires people who want
to do minor editing to deal with learning a new application, just to
edit some minor sources.

Personally, I find most standard IDEs to be bloated pieces of shit.
When did it become reasonable to need 100+ megs to edit source code?

- Josiah
Jul 18 '05 #64
Bas
David MacQuigg <dm*@gain.com> wrote in message news:<s2********************************@4ax.com>. ..
Seems like we need a simple way to extend Python syntax that doesn't
break existing syntax or clash with any other syntax in Python, is
easy to type, easy to read, and is clearly distinct from the "base"
syntax. Seems like we could put the @ symbol to good use in these
situations. Examples:
[...]
@x,y:x*x+y*y -- anonymous function
[...]
It certainly beats adding ugly statements like 'lambda'.


Couldn't we use -> instead??

This wouldn't introduce the the @ symbol (currently forbidden??), but
only uses symbols that are already used. It is thus just another
operator. The -> symbol is already used a lot in the help strings, so
why not use it in the language also?? Maple (symbolic math program)
also uses -> for anonymous functions.
Jul 18 '05 #65
Bas wrote:
Couldn't we use -> instead??


We could use %--*(): and it still wouldn't be any better. Just because
the characters are all used elsewhere is no advantage. It's still ugly,
meaningless punctuation that makes the code less readable.

-Peter
Jul 18 '05 #66
In article <0Iq4c.2774$G3.22476@localhost>,
Peter Hansen <pe***@engcorp.com> wrote:
Bas wrote:
Couldn't we use -> instead??


We could use %--*(): and it still wouldn't be any better. Just because
the characters are all used elsewhere is no advantage. It's still ugly,
meaningless punctuation that makes the code less readable.


I'm hoping he was joking, but I guess you never know. Surely
there's some humor to be gotten out of the notion that we could
make lambda work better for Python programming by changing its
name from "lambda" to "@".

Donn Cave, do**@u.washington.edu
Jul 18 '05 #67
> >This is all semantics, probably, but I don't believe you can make a
strong case that yield is an ill-chosen name.


It's not ill chosen, just arbitrary. I would be just as happy with
'rtn' or 'tsr' or any fanciful word that doesn't convey a _wrong_
meaning.


To me, it conveys the perfect meaning. All it takes is having the
right mindset. You yield in traffic; you let someone go along before
you and then continue on.. that's what generators are, perfectly.

Yes, only one definition of 'yield' fits Python's usage-- but that's
infinately better then "Like return, but different".

What happens if you have a second type of 'return-like' statement?

@@return? @return@?

If someone is learning a language, they'll always run into keywords
and such that they do not understand. So they have to look them
up. No big deal. Afterwards, when they get the mindset of how to
think in them, it sticks-- they can then glance down and remember,
and /know/, what's going on.

It becomes again pseudocode-that-works: 'yield X' means, 'give
off X and let the control continue on its way, i'll be continued later'.

However, something like '@return X' wouldn't accomplish the same
result, in my opinion. For some people it'll be too easy to just ignore
the punctuation and think 'return', when its very important that they
not think 'return' in this case. For others, it'll always catch their eyes
and make them pause and think-- which variant of return is this?

A new keyword in this instance is perfect: its totally different, and
totally
seperate from the behavior of 'return', so someone can't just pass it
by with assumptions of 'return', and once they learn what it is, it sticks.

--Stephen
Jul 18 '05 #68
On Wed, 10 Mar 2004 18:15:57 -0500, "John Roth"
<ne********@jhrothjr.com> wrote:
How much real development (I don't mean archiving) do we do
today on systems without appropriate tools? Very little. The issue
isn't trying to develop on systems without appropriate tools, it's
developers that won't use tools that help them work.


I'll happily use a fancy tool when I find one that doesn't suck. If
and when that ever happens, I'll be willing to start considering using
a language that requires such.

--
"Sore wa himitsu desu."
To reply by email, remove
the small snack from address.
http://www.esatclear.ie/~rwallace
Jul 18 '05 #69
"Russell Wallace" <wa**************@eircom.net> wrote in message
news:40***************@news.eircom.net...
On Wed, 10 Mar 2004 18:15:57 -0500, "John Roth"
<ne********@jhrothjr.com> wrote:
How much real development (I don't mean archiving) do we do
today on systems without appropriate tools? Very little. The issue
isn't trying to develop on systems without appropriate tools, it's
developers that won't use tools that help them work.
I'll happily use a fancy tool when I find one that doesn't suck. If
and when that ever happens, I'll be willing to start considering using
a language that requires such.


Well, two points. First, why does it have to be a "fancy"
tool? The only editors I use basically have syntax highlighting
and code folding (at least, I think that's what it's called.)
There are a lot of other features I'd like to have, but I'm not
about to spend time with a learning curve that needs a full
mountaineering outfit to scale.

Second, what is it about which tools that you don't like?
Be specific, I'm sure that at least some of the tool vendors
would like feedback on their pride and joy.

John Roth

--
"Sore wa himitsu desu."
To reply by email, remove
the small snack from address.
http://www.esatclear.ie/~rwallace

Jul 18 '05 #70
On Thu, 18 Mar 2004 12:58:03 -0500,
"John Roth" <ne********@jhrothjr.com> wrote:
Second, what is it about which tools that you don't like? Be
specific, I'm sure that at least some of the tool vendors would
like feedback on their pride and joy.


Every IDE is built around a text editor. Software development is
executing processes and procedures, i.e., workflow. No IDE is
quite like $EDITOR and $SHELL, which I have been using for
<mumble> years. Operating $EDITOR is hard-wired into my fingers.
Customizing and extending $EDITOR in my own arguably convoluted
ways, and writing $SHELL scripts/programs/tools for my own
workflow habits, increases my comfort and my productivity.
If/when IDE developers realize how personal $EDITOR and my
personal collection of $SHELL tools have become, and if/when
$EDITOR becomes a drop-in replacement widget for the IDE(s) in
question, there's a chance that that IDE may approach the
productivity and comfort levels I acheive using $EDITOR and
$SHELL.

Remember USCD Pascal?

Excel : Visual Basic :: IDE : Programming Language.

The typical SmallTalk or Lisp environment might come close, but
their footprints are larger than Sasquatch's. Also, those
environments, when done right, are SmallTalk or Lisp "all the way
down" into the OS, which makes for a more homogenous experience
than what I usually feel like I get with today's "modern" IDEs
glued atop an OS and a GUI.

End of rant. Sorry.

Regards,
Heather

--
Heather Coppersmith
That's not right; that's not even wrong. -- Wolfgang Pauli
Jul 18 '05 #71
On Fri, 12 Mar 2004 9:08:10 -0800, Josiah Carlson wrote
(in message <c2**********@news.service.uci.edu>):
Personally, I find most standard IDEs to be bloated pieces of shit.
When did it become reasonable to need 100+ megs to edit source code?


Not all IDEs are this large. For instance, Apple's Project Builder
(version 2.1) is 2.6 MB, while the Mac version of CodeWarrior Pro 8 is
9.9 MB. These sizes are just the executables, and don't include
compilers, linkers, libraries, headers, documentation and examples. But
you would need all these things for a command line based development
environment.

--
Derek Ledbetter
de****@serve.com

Heavy boots of lead
fills his victims full of dread
Running as fast as they can
Iron Man lives again!
Jul 18 '05 #72
>>Personally, I find most standard IDEs to be bloated pieces of shit.
When did it become reasonable to need 100+ megs to edit source code?


Not all IDEs are this large. For instance, Apple's Project Builder
(version 2.1) is 2.6 MB, while the Mac version of CodeWarrior Pro 8 is
9.9 MB. These sizes are just the executables, and don't include
compilers, linkers, libraries, headers, documentation and examples. But
you would need all these things for a command line based development
environment.


I never said /all/, I said /most/.

In the same vein as your reply, a standard Python install is somewhere
around 30 megs and includes Idle (not quite an IDE, but it gets the job
done). DJGPP (a c/c++ compiler for dos) is also around 30 megs
installed, and includes an IDE, compiler, linker, libaries, headers, etc.

However, if we were to take a look at some standard tools that current
university students and even a measurable portion of industry
professionals use; Eclipse, MS Visual Studio, and others, you'll note
the tendency of bloat.

- Josiah
Jul 18 '05 #73
On Thu, 18 Mar 2004 12:58:03 -0500, "John Roth"
<ne********@jhrothjr.com> wrote:
Well, two points. First, why does it have to be a "fancy"
tool? The only editors I use basically have syntax highlighting
and code folding (at least, I think that's what it's called.)
There are a lot of other features I'd like to have, but I'm not
about to spend time with a learning curve that needs a full
mountaineering outfit to scale.
Well then we're agreed, neither of us uses fancy tools :) (Don't know
what code folding is, but I also like syntax highlighting.)
Second, what is it about which tools that you don't like?
Be specific, I'm sure that at least some of the tool vendors
would like feedback on their pride and joy.


I wouldn't imagine any of them read comp.lang.python, but the main
point is that basic functionality needs to be smooth, fast, 100%
reliable, not needing you to take your hands off the keyboard or
provide more than 2 keystrokes per operation or install third party
libraries or entrust your source code to a binary database, etc etc.
Get hold of Brief (the 1980s-vintage DOS programming editor) and get
to the point where you can do everything it does, not necessarily in
the same way, but just as smoothly and easily. _Then_ worry about
whiz-bang features.

--
"Sore wa himitsu desu."
To reply by email, remove
the small snack from address.
http://www.esatclear.ie/~rwallace
Jul 18 '05 #74
Well, two points. First, why does it have to be a "fancy"
tool? The only editors I use basically have syntax highlighting
and code folding (at least, I think that's what it's called.)
There are a lot of other features I'd like to have, but I'm not
about to spend time with a learning curve that needs a full
mountaineering outfit to scale.


Well then we're agreed, neither of us uses fancy tools :) (Don't know
what code folding is, but I also like syntax highlighting.)


http://scintilla.sourceforge.net/SciTEImage.html
The above link will show you what code folding looks like. Look at the
function definitions.

- Josiah
Jul 18 '05 #75
In article <m2************@unique.phony.fqdn>,
Heather Coppersmith <me@privacy.net> wrote:
Jul 18 '05 #76

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Alicia Haumann | last post: by
3 posts views Thread by Eli Daniel | last post: by
11 posts views Thread by Soeren Sonnenburg | last post: by
1 post views Thread by Richard Townsend | last post: by
3 posts views Thread by Marco Meoni | last post: by
5 posts views Thread by vbgunz | last post: by
1 post views Thread by jeremito | last post: by
7 posts views Thread by Maximus Decimus | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.