Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ANNOUNCE: 'goto' for Python

67 views
Skip to first unread message

Richie Hindle

unread,
Apr 1, 2004, 2:10:29 AM4/1/04
to pytho...@python.org

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.

--
Richie Hindle
ric...@entrian.com


Peter Maas

unread,
Apr 1, 2004, 3:34:14 AM4/1/04
to
Richie Hindle wrote:
> 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

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail peter...@mplusr.de
-------------------------------------------------------------------

Bruno Desthuilliers

unread,
Apr 1, 2004, 4:12:51 AM4/1/04
to
Richie Hindle wrote:
> 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... !-)

Yermat

unread,
Apr 1, 2004, 4:57:58 AM4/1/04
to

What is the day today ? Oh yes the first of April !

Michele Simionato

unread,
Apr 1, 2004, 6:52:34 AM4/1/04
to
Richie Hindle <ric...@entrian.com> wrote in message news:<mailman.210.10808034...@python.org>...

Today is April the first ... ;)

Gonçalo Rodrigues

unread,
Apr 1, 2004, 8:17:29 AM4/1/04
to
On Thu, 01 Apr 2004 08:10:29 +0100, Richie Hindle <ric...@entrian.com>
wrote:


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

Ville Vainio

unread,
Apr 1, 2004, 9:33:20 AM4/1/04
to
>>>>> "Richie" == Richie Hindle <ric...@entrian.com> writes:

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.

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

Ville Vainio

unread,
Apr 1, 2004, 9:42:14 AM4/1/04
to

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" == Peter Maas <fpete...@netscape.net> writes:

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!)

Joe Mason

unread,
Apr 1, 2004, 10:22:51 AM4/1/04
to
In article <c4gk3c$hfb$1...@swifty.westend.com>, Peter Maas wrote:
> Richie Hindle wrote:
>> 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!

Next up: "from grovel import please"

Joe

Paul Prescod

unread,
Apr 1, 2004, 11:18:48 AM4/1/04
to Michele Simionato, pytho...@python.org
...ruining April Fools! The point is to get long-running debates between
newbies sucked into believing the joke is real.

Michele Simionato wrote:
>
> Today is April the first ... ;)

Camilo Olarte wrote:
>
> OOUCH ! I Almost believe it!

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


Richie Hindle

unread,
Apr 1, 2004, 10:25:54 AM4/1/04
to pytho...@python.org

[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."

--
Richie Hindle
ric...@entrian.com


Camilo Olarte

unread,
Apr 1, 2004, 10:33:04 AM4/1/04
to pytho...@python.org
>> 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.

>>>>>> What is the day today ? Oh yes the first of April ! <<<<<<

OOUCH ! I Almost believe it!

:)

Camilo Olarte
Telesat, más fácil...más Internet.
http://www.telesat.com.co/

Michael Hudson

unread,
Apr 1, 2004, 12:25:26 PM4/1/04
to
Camilo Olarte <col...@telesat.com.co> writes:

> >> 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.
>
> >>>>>> What is the day today ? Oh yes the first of April ! <<<<<<
>
> OOUCH ! I Almost believe it!

There's nothing to believe: it works!

Cheers,
mwh

--
"Sturgeon's Law (90% of everything is crap) applies to Usenet."
"Nothing guarantees that the 10% isn't crap, too."
-- Gene Spafford's Axiom #2 of Usenet, and a corollary

Richie Hindle

unread,
Apr 1, 2004, 12:09:34 PM4/1/04
to pytho...@python.org

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

>
> Camilo Olarte wrote:
> >
> > OOUCH ! I Almost believe it!

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...

--
Richie Hindle
ric...@entrian.com


Josiah Carlson

unread,
Apr 1, 2004, 2:25:22 PM4/1/04
to
> 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

Richie Hindle

unread,
Apr 1, 2004, 3:46:06 PM4/1/04
to pytho...@python.org

[Gerrit]
> Why don't we call goto '$@' and comefrom '@$'?

A bit verbose don't you think? How about ">label" and "<label"? "<" and
">" aren't currently used as unary operators. Mind you, at least your
suggestion would confuse the perlistas.

--
Richie Hindle
ric...@entrian.com


Daniel Yoo

unread,
Apr 1, 2004, 4:41:34 PM4/1/04
to
Michael Hudson <m...@python.net> wrote:
: Camilo Olarte <col...@telesat.com.co> writes:

:> >> 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.
:>
:> >>>>>> What is the day today ? Oh yes the first of April ! <<<<<<
:>
:> OOUCH ! I Almost believe it!

: There's nothing to believe: it works!


Hello,


It doesn't work from the interactive interpreter, though:

###


>>> from goto import goto, label

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.3/site-packages/goto.py", line 255, in _trace
_addToCaches(filename)
File "/usr/local/lib/python2.3/site-packages/goto.py", line 229, in _addToCaches
for tokenType, tokenString, (startRow, startCol), (endRow, endCol), line \
IOError: [Errno 2] No such file or directory: '<stdin>'
###


I haven't looked at the code closely enough to understand exactly how
to fix this. But in the meantime, here's a patch to at least give an
error message when one tries to use it interactively:

--- goto.py Tue Mar 30 12:24:28 2004
+++ goto-fixed.py Thu Apr 1 13:37:10 2004
@@ -208,6 +208,15 @@
# Source filenames -> comefrom label names -> line numbers of those comefroms.
_comefromNameCache = {}

+
+def _openModuleFilename(moduleFilename):
+ """Opens up the file named by moduleFilename. In the special case where
+ the file is <stdin>, we raise an IOError."""
+ if moduleFilename == '<stdin>':
+ raise IOError, "module cannot be used on sys.stdin."
+ return open(moduleFilename, 'r')
+
+
def _addToCaches(moduleFilename):
"""Finds the labels and gotos in a module and adds them to the caches."""

@@ -227,7 +236,7 @@
# Tokenize the module; 'window' is the last two (type, string) pairs.
window = [(None, ''), (None, '')]
for tokenType, tokenString, (startRow, startCol), (endRow, endCol), line \
- in tokenize.generate_tokens(open(moduleFilename, 'r').readline):
+ in tokenize.generate_tokens(_openModuleFilename(moduleFilename).readline):
# Plain goto: "goto .x"
if window == plainGotoPattern:
_plainGotoCache[moduleFilename][startRow] = tokenString

Hope this helps!

Gerrit

unread,
Apr 1, 2004, 2:31:09 PM4/1/04
to pytho...@python.org
Richie Hindle wrote:
> 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.

Why don't we call goto '$@' and comefrom '@$'?

Cousin Stanley

unread,
Apr 1, 2004, 6:16:17 PM4/1/04
to
| ....

| How about ">label" and "<label"? "<" and ">"
| aren't currently used as unary operators
| ....

The Multics OS used the > and < characters for paths
with > indicating a move deeper into the hierarchy
and < indicating a move higher in the hierarchy
and used for relative paths ....

http://www.multicians.org

I liked it ....

--
Cousin Stanley
Human Being
Phoenix, Arizona

Richie Hindle

unread,
Apr 1, 2004, 5:22:21 PM4/1/04
to pytho...@python.org

[Daniel]

> It doesn't work from the interactive interpreter, though:

I know - I did point that out in my original announcement. 8-)

> in the meantime, here's a patch to at least give an
> error message when one tries to use it interactively:

Thanks very much - I'll incorporate that (or something similar) into the
next release).

--
Richie Hindle
ric...@entrian.com


Christos TZOTZIOY

unread,
Apr 2, 2004, 9:38:34 AM4/2/04
to
On Thu, 01 Apr 2004 11:25:22 -0800, rumours say that Josiah Carlson
<jcar...@uci.edu> might have written:

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

Aren't double bluffs great?-)
--
TZOTZIOY, I speak England very best,
Ils sont fous ces Redmontains! --Harddix

Bill

unread,
Apr 2, 2004, 12:32:08 PM4/2/04
to

"Richie Hindle" <ric...@entrian.com> wrote in message
news:mailman.210.10808034...@python.org...
--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


Josiah Carlson

unread,
Apr 2, 2004, 3:49:00 PM4/2/04
to
>>Of course, I suppose the prank is that people think it is a prank, when
>>in fact, is actually truth.
>
>
> Aren't double bluffs great?-)

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

- Josiah

Richie Hindle

unread,
Apr 2, 2004, 3:40:34 PM4/2/04
to pytho...@python.org

[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.

--
Richie Hindle
ric...@entrian.com


Skip Montanaro

unread,
Apr 2, 2004, 2:50:10 PM4/2/04
to Josiah Carlson, pytho...@python.org

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

Roger Binns

unread,
Apr 3, 2004, 1:54:55 AM4/3/04
to
Richie Hindle wrote:
> [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


Richie Hindle

unread,
Apr 3, 2004, 4:50:39 AM4/3/04
to pytho...@python.org

[Roger]
> http://www.fortran.com/come_from.html
> http://c2.com/cgi/wiki?ComeFrom
> http://aspn.activestate.com/ASPN/CodeDoc/Acme-ComeFrom/ComeFrom.html

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.)

--
Richie Hindle
ric...@entrian.com
(I know it's two days since April 1st, but I can't help myself)


Tim Peters

unread,
Apr 3, 2004, 11:50:17 AM4/3/04
to pytho...@python.org

[Richie Hindle]


> 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.

Guido has already accepted your module for inclusion in Python 2.4, and I
expect he'll use his time machine then to ensure that it's always been part
of Python.

> 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.

That would be confusingly low-level. If you haven't used Fortran, you may
not have realized that Clark's examples never used line numbers. In
Fortran, you have the option of putting a non-negative integer in columns 1
through 5 of a statement. There are no restrictions on the integers you can
put there (e.g., they needn't bear any relation to line number, and don't
even have to be increasing top-to-bottom), except that no two statements can
have the same integer attached. So Clark *was* using labels, not line
numbers -- they're simply integer labels. Your introduction of alphanumeric
labels to Python is already far advanced.

I must say, though, that the restriction to 5 digits in Fortran had the nice
Pythonic effect of discouraging a subroutine from containing more than a
hundred thousand branch targets (if you wanted more than that, you had to
play obscure tricks to worm around the no-more-than-1E5-labels restriction,
and that had a healthy moderating effect -- sad to say, most programmers
start to lose track after just a few tens of thousands of branch targets!).

BTW, because Fortran ignored whitespace, these labels were all the same:

123
123
123
01 23
1 2 3
00123

> (Computed and conditional comefroms are already on the list, as are

> computed labels, which I'm surprised to see 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.)

As above, the conflict is an illusion: Clark is also using labels, they're
just integer labels. Full speed ahead!


Alan James Salmoni

unread,
Apr 4, 2004, 6:45:35 PM4/4/04
to
Wow! Thanks very much! Just what I've been looking for.

Umm, would it be possible to discuss a few other possibilities, like
in-line assembly language, GOSUB's, PEEK's, POKE's and file operations
only possible through direct access to the hard disk? I reckon with
these in place, we could out-obfuscate any Perl code in no time! ;^)

Oh damn, it's April 4th - jokes on me... =:/

Alan James Salmoni

Richie Hindle <ric...@entrian.com> wrote in message news:<mailman.210.10808034...@python.org>...

> 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()
>

0 new messages