PEP 3107 and stronger typing (note: probably a newbie question)

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Jul 13 04:57:02 EDT 2007


On Fri, 13 Jul 2007 08:37:00 +0200, Hendrik van Rooyen wrote:

> "Donn Cave" <donn at u...ton.edu> wrote:
> 
>>In its day, goto was of course very well loved.
> 
> Does anybody know for sure if it is in fact possible to
> design a language completely free from conditional jumps?

GOTO is unconditional.  I guess it depends on what you call a jump.

> At the lower level, I don't think you can get away with
> conditional calls - hence the "jumps with dark glasses",
> continue and break.
> 
> I don't think you can get that functionality in another way.

Don't think in terms of calls and jumps but conditionally evaluating
functions with no side effects.

> Think of solving the problem of reading a text file to find
> the first occurrence of some given string - can it be done 
> without either break or continue?  (given that you have to 
> stop when you have found it)

Finding an element in a list in Haskell:

findFirst needle haystack = f 0 haystack where
    f _ []     = -1
    f i (x:xs) | x == needle = i
               | otherwise   = f (i+1) xs

No ``break`` or ``continue`` but a recursive function.

>  I can't think of a way, even in assembler, to do this without
> using a conditional jump - but maybe my experience has
> poisoned my mind, as I see the humble if statement as a plethora
> of local jumps...

Technically yes, and with exceptions we have non local jumps all over the
place.

You are seeing the machine language behind it, and of course there are lots
of GOTOs, but not "uncontrolled" ones.  The language above hides them and
allows only a limited set of jumps.  Easing the proofs that the program is
correct.  If you have a conditional call you can proof both alternative
calls and build the proof the the function that builds on those
alternatives on them.

Trying to guess how some source would look like in machine language isn't
that easy anymore the higher the abstraction level of the used
programming language is.  In Haskell for example you have to keep in mind
that it uses lazy evaluation and that the compiler knows very much about
the program structure and data types and flow to do optimizations.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list