Is Python a functional programming language?

Nobody nobody at nowhere.com
Tue May 11 16:03:35 EDT 2010


On Tue, 11 May 2010 07:36:30 -0700, Paul Rubin wrote:

> Offhand I can't tell that imperative and procedural mean something
> different.  Both basically mean that the programmer specifies a series of
> steps for the computer to carry out.  Functional languages are mostly
> declarative; for example, an expression like
>    x = 3
> is called an "equation" rather than an "assignment".  It declares "x is
> equal to 3", rather than directing x to be set to 3.  If someplace else in
> the program you say "x = 4", that is an error, normally caught by the
> compiler, since x cannot be equal to both 3 and 4.

In both ML and Haskell, bindings are explicitly scoped, i.e.

	let x = 3 in ... end	(ML)
	let x = 3 in ...	(Haskell)

If you bind a variable which is already bound, it introduces a new binding
which "overrides" the existing binding. It won't generate an error.

The key point is that a variable has a fixed (constant) value at any
specific point in the program. The value depends upon which bindings are
in scope at that point, and not on the "state" of the variable at a
particular point in time.

E.g. (Haskell):

	test y = let x = 3
	         in let f y = x + y
	            in let x = 5
	               in f y
	test 5
	8

x has the value 3 at the point that f is defined, so that's the value
which is used when f is used.




More information about the Python-list mailing list