Python Rocks!

William B. Clodius wclodius at lanl.gov
Fri Jan 21 22:22:08 EST 2000


Jim Richardson wrote:
> 
> On 20 Jan 2000 04:58:00 GMT,
>  William Tanksley, in the persona of <wtanksle at hawking.armored.net>,
>  brought forth the following words...:
> 
> >On Tue, 18 Jan 2000 16:41:06 -0800, tye4 wrote:
> >
> >>I have offered you many reasons why we need 'end' block support..
> >
> >No, you haven't.  All you've done is claim that other languages don't use
> >indentation.  So what?  Python uses assignment.  ML doesn't.  Does that
> >mean ML is bad and Python is good, or is it the other way around?
> 
> what does ML do then? this has me puzzled...
> <snip>

As a pure functional language every entity in ML has a single definition
of its value that cannot be changed. A language with assignment allows
entities whose value can change, e.g., A in
...
A=1
X=A
A=2*X
...
A pure functional language would not allow the redefinition of A. Intead
you would have to do something similar to
...
A=1
X=A
B=2
...
and any subsequent point in the first text where you would refer to A
would have to be rewritten to refer to B, unless assignment is again
applied to A, in which case new entities  would have to be defined. In
most cases the fact that there is a single definition of an entity makes
the code easier to follow, but it potentially increase the number of
"definitions" within a scope, (such languages reduce this problem by
having additional flexibilities that encourage short functions), it
makes the compiler work harder to generate reasonable code (e.g., it
should recognize that A is not needed after the definition of X so its
"storage" can be reused for B, it cannot rely on you to do this
optimization for it), and there are some things that we think of as
changing, e.g., life, for which an imperative model with assignment is
perhaps more natural than a functional model. 

The need for an optimizing compiler for reasonable efficiency often
brings up the loudest arguments against functional languages, but,
except perhaps for arrays, the optimizations are the obvious ones you
would find in a not highly advanced compiler for an imperative staticaly
typed language. Indeed some optimizing compilers translate imperative
language into a form with single assignment (i.e., a form with
functional semantics) and then perform their optimizations on that as
the reasoning is usually simpler in that form.



More information about the Python-list mailing list