Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct

Evan Driscoll driscoll at cs.wisc.edu
Sun Mar 18 03:59:31 CET 2012


On 3/17/2012 9:03, Antti J Ylikoski wrote:
> 
> In his legendary book series The Art of Computer Programming,
> Professor Donald E. Knuth presents many of his algorithms in the form
> that they have been divided in several individual phases, with
> instructions to GOTO to another phase interspersed in the text of the
> individual phases.
> 
> 
> A1.  (Do the work of Phase A1.)  If <zap> then go to Phase A5,
> otherwise continue.
> 
> A2.  (Do some work.) If <zorp> go to Phase A4.
> 
> A3.  (Some more work.)
> 
> A4.  (Do something.)  If <condition ZZZ> go to Phase A1.
> 
> A5.  (Something more).  If <foobar> then go to Phase A2, otherwise
> end.

Clearly you just need the goto module (http://entrian.com/goto/):

  from goto import goto, label

  label .A1
  # do work of phase A1
  if <zap>: goto .A5

  label .A2
  # do some work
  if <zorp>: goto .A4

  # do some more work

  label .A4
  # do something
  if <condition zzz>: goto .A1

  label .A5
  # something more
  if <foobar>: goto .A2

Clearly the best solution of all.

(Note: do not actually do this.)

Evan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 552 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20120317/4d4f14ed/attachment.pgp>


More information about the Python-list mailing list