ANNOUNCE: 'goto' for Python

R

Richie Hindle

Entrian Solutions is pleased to announce version 1.0 of the 'goto' module.

This adds the 'goto' and 'comefrom' keywords to Python 2.3, adding
flexibility to Python's control flow mechanisms and allowing Python
programmers to use many common control flow idioms that were previously
denied to them.

'goto' example: breaking out from a deeply nested loop:

from goto import goto, label
for i in range(1, 10):
for j in range(1, 20):
for k in range(1, 30):
print i, j, k
if k == 3:
goto .end
label .end
print "Finished\n"


'comefrom' example: letting cleanup code take control after an error.

from goto import comefrom, label
def bigFunction():
setUp()
if not doFirstTask():
label .failed
if not doSecondTask():
label .failed
if not doThirdTask():
label .failed

comefrom .failed
cleanUp()

Computed 'goto's are also supported - see the documentation for details.
Computed 'comefrom's are planned for a future release.

Documentation and further examples:
http://entrian.com/goto/index.html

Downloads:
http://entrian.com/goto/download.html

The 'goto' module is released under the Python Software Foundation
license, and requires Python 2.3 or later.

Please note that this version does not work at the interactive Python
prompt - code importing 'goto' must be in a .py file. This restriction
will hopefully be lifted in a future release.
 
P

Peter Maas

Richie said:
Entrian Solutions is pleased to announce version 1.0 of the 'goto' module.

This adds the 'goto' and 'comefrom' keywords to Python 2.3, adding
flexibility to Python's control flow mechanisms and allowing Python
programmers to use many common control flow idioms that were previously
denied to them.

Great!!! This will enhance Python's yet poor capabilities to write
code with a behaviour hard to predict by programmers thereby adding
a human touch to the sometimes too clean and dull Python language!

Mit freundlichen Gruessen,

Peter Maas
 
B

Bruno Desthuilliers

Richie said:
Entrian Solutions is pleased to announce version 1.0 of the 'goto' module.

This adds the 'goto' and 'comefrom' keywords to Python 2.3, adding
flexibility to Python's control flow mechanisms and allowing Python
programmers to use many common control flow idioms that were previously
denied to them.
Trop gros, passera pas... !-)
 
G

Gonçalo Rodrigues

Entrian Solutions is pleased to announce version 1.0 of the 'goto' module.

This adds the 'goto' and 'comefrom' keywords to Python 2.3, adding
flexibility to Python's control flow mechanisms and allowing Python
programmers to use many common control flow idioms that were previously
denied to them.

'goto' example: breaking out from a deeply nested loop:

from goto import goto, label
for i in range(1, 10):
for j in range(1, 20):
for k in range(1, 30):
print i, j, k
if k == 3:
goto .end
label .end
print "Finished\n"


'comefrom' example: letting cleanup code take control after an error.

from goto import comefrom, label
def bigFunction():
setUp()
if not doFirstTask():
label .failed
if not doSecondTask():
label .failed
if not doThirdTask():
label .failed

comefrom .failed
cleanUp()

Computed 'goto's are also supported - see the documentation for details.
Computed 'comefrom's are planned for a future release.

Documentation and further examples:
http://entrian.com/goto/index.html

Downloads:
http://entrian.com/goto/download.html

The 'goto' module is released under the Python Software Foundation
license, and requires Python 2.3 or later.

Please note that this version does not work at the interactive Python
prompt - code importing 'goto' must be in a .py file. This restriction
will hopefully be lifted in a future release.


Thanks a lot!! Now I at least have a chance to shame my perlite
friends in obfuscation contests with a suitably spaghetified Python
code. I'm getting all warm and fuzzy with the possibilities this
module opens.

Once again, thanks a lot for your efforts to improve the Python
language, with my best regards,
G. Rodrigues
 
V

Ville Vainio

Richie> Entrian Solutions is pleased to announce version 1.0 of
Richie> the 'goto' module.

Richie> This adds the 'goto' and 'comefrom' keywords to Python
Richie> 2.3, adding flexibility to Python's control flow
Richie> mechanisms and allowing Python programmers to use many
Richie> common control flow idioms that were previously denied to
Richie> them.

I like it! I especially like the way comefrom maps to how we
speak. You know, "come here when you are done with the first
file". Programming is hard for the beginners because there really is
no direct mapping of many everyday speech idioms, and comefrom goes a
long way to redeem this for Python.

There is still a long way to go, though. I have some problems telling
nouns apart from verbs. Python could innovate here by prefixing all
the function names with !. This ought to make the parser faster also,
considering that Python startup time has gone up in recent versions.

Another gripe of mine is the if-statement. Often what is done is more
important than the condition that determines what we are to do in the
first place, esp. in situations where the condition is of the form "if
the previous command succeeded". This could be easily redeemed by a
postfix-if statement:


err = foo()
dostuff()
domorestuff()
:if not err

This seems pretty elegant, considering that exceptions are a hackish
and unnatural way to solve this problem. Python parser would cope with
this just fine.
 
V

Ville Vainio

That's mostly true. I'm the first to admit that occasionally a
predictable and dull language is useful, but there is a lot of virtue
in being to express yourself with the language, and give a personal
touch to all the code you write. The code I write should scream that
"this is by Ville down the hall!". The idiosynchracies (sp?) in our
code leave a lasting mark for the generations to come, show off the
proficiency we have been able to acquire in the language (and thus
make the monthly salary easy to calculate), and make us who we are.

--
Ville Vainio http://tinyurl.com/2prnb


Peter> Great!!! This will enhance Python's yet poor capabilities
Peter> to write code with a behaviour hard to predict by
Peter> programmers thereby adding a human touch to the sometimes
Peter> too clean and dull Python language!























(Wow, this top posting seems like lots of fun!)
 
J

Joe Mason

Great!!! This will enhance Python's yet poor capabilities to write
code with a behaviour hard to predict by programmers thereby adding
a human touch to the sometimes too clean and dull Python language!

Next up: "from grovel import please"

Joe
 
R

Richie Hindle

[Richie]
This adds the 'goto' and 'comefrom' keywords to Python
[Ville]
I like it! I especially like the way comefrom maps to how we
speak. You know, "come here when you are done with the first
file". Programming is hard for the beginners because there really is
no direct mapping of many everyday speech idioms, and comefrom goes a
long way to redeem this for Python.

Absolutely.

I should have referred to the definitive reference the 'comefrom' statement,
"A Linguistic Contribution to GOTO-less Programming" by R. Lawrence Clark in
Comm. ACM, Vol 27 Nr. 4 (pp. 349-350) (reprint from Datamation, Dec 1973).
[Thanks to Sjoerd Mullender for the full reference.]

I confess that although I've implemented the statement, I've never read this
seminal paper because I couldn't find a free-to-view copy on the web - I don't
suppose anyone knows where such a thing can be found? I'd be interested to
see whether Mr Clark discusses the English-idiomatic nature of 'comefrom'.
err = foo()
dostuff()
domorestuff()
:if not err

Nice idea, though an 'unless' keyword would make for more idiomatic English
Python - we rarely say "if not". Also, you probably want to write 'foo()'
*after* 'dostuff' even though it is executed before - consider this example:
"Go and buy some more lubricant, unless you find some in the fridge."
 
P

Paul Prescod

....ruining April Fools! The point is to get long-running debates between
newbies sucked into believing the joke is real.

Michele said:
>
> Today is April the first ... ;)

Camilo said:
>
> OOUCH ! I Almost believe it!

Paul "So I top-posted. What are you going to do about it?" Prescod
 
R

Richie Hindle

[Paul]
PLEASE STOP!!! ...ruining April Fools!

You can't count Camilo in with the spoilers - Camilo obviously believes
that my 'goto' module is some kind of prank fiction, when in fact it's a
working module ready to be downloaded and used. There's probably a word
for this but I've no idea what it is...
 
J

Josiah Carlson

You can't count Camilo in with the spoilers - Camilo obviously believes
that my 'goto' module is some kind of prank fiction, when in fact it's a
working module ready to be downloaded and used. There's probably a word
for this but I've no idea what it is...

While I (generally) dislike april fools pranks, after reading this I
gave it a shot. Low and behold, it works.

Perhaps you should have released it on April 4 or so, just to not be
accused of trying to dupe people.

Of course, I suppose the prank is that people think it is a prank, when
in fact, is actually truth.

- Josiah
 
B

Bill

--snip--
'comefrom' example: letting cleanup code take control after an error.

from goto import comefrom, label
def bigFunction():
setUp()
if not doFirstTask():
label .failed
if not doSecondTask():
label .failed
if not doThirdTask():
label .failed

comefrom .failed
cleanUp()
Hello,
Can you explain to me why you need comefrom? Couldn't you replace
"label.failed" with "goto cleanup"? Thanks.
Louis
 
S

Skip Montanaro

Josiah> While I (generally) dislike april fools pranks, after reading
Josiah> this I gave it a shot. Low and behold, it works.

Josiah> Perhaps you should have released it on April 4 or so, just to
Josiah> not be accused of trying to dupe people.

Nah, that's what makes it such a great AFJ. Over-the-top *and* it's real.

Josiah> Of course, I suppose the prank is that people think it is a
Josiah> prank, when in fact, is actually truth.

There ya go.

Skip
 
R

Richie Hindle

[Bill]
Can you explain to me why you need comefrom? Couldn't you replace
"label.failed" with "goto cleanup"? Thanks.

You don't strictly need comefrom, but then you don't strictly need goto
either. Use whatever control flow construct fits the problem you're
trying to solve.
 
J

Josiah Carlson

Of course, I suppose the prank is that people think it is a prank, when
Aren't double bluffs great?-)

I don't know about 'great', but nifty, yes.

- Josiah
 
R

Roger Binns

Richie said:
[Bill]
Can you explain to me why you need comefrom? Couldn't you replace
"label.failed" with "goto cleanup"? Thanks.

You don't strictly need comefrom, but then you don't strictly need goto
either. Use whatever control flow construct fits the problem you're
trying to solve.

http://www.fortran.com/come_from.html
http://c2.com/cgi/wiki?ComeFrom

Needless to say, Perl has already been there :)

http://aspn.activestate.com/ASPN/CodeDoc/Acme-ComeFrom/ComeFrom.html

Roger
 
R

Richie Hindle

[Roger]

Thanks for the references! It's a bit of an embarrassment for the Python
community that it's taken us so long to catch up.

And it's a bit of an embarrassment for me that I didn't implement "goto
<linenumber>" or "comefrom <linenumber>" - I'll implement those in the
next release.

(Computed and conditional comefroms are already on the list, as are
computed labels, which I'm surprised to se missing from Clark's paper.
His "assigned COME FROM" is almost the same thing, but I found it
confusing - computed labels seem like a much clearer way of achieving the
same thing.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top