Is Python a functional programming language?
Chris Rebert
clp2 at rebertia.com
Fri May 14 15:15:32 EDT 2010
On Fri, May 14, 2010 at 12:08 PM, Nobody <nobody at nowhere.com> wrote:
> On Tue, 11 May 2010 18:31:03 -0700, Paul Rubin wrote:
>>>> 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 ... (Haskell)
>>
>> I'm not talking about nested bindings. I'm talking about two different
>> bindings of the same symbol in the same scope:
>>
>> $ cat meow.hs
>> x = 3
>> x = 4
>> $ ghc meow.hs
>>
>> meow.hs:2:0:
>> Multiple declarations of `Main.x'
>> Declared at: meow.hs:1:0
>> meow.hs:2:0
>
> It may be worth noting the interactive behaviour:
>
> $ ghci
> GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help
> Loading package base ... linking ... done.
> Prelude> let x = 7
> Prelude> let f y = x + y
> Prelude> f 3
> 10
> Prelude> let x = 5
> Prelude> f 3
> 10
Ahem (emphasis mine):
"""
==This syntax is *ghci-specific*==
The syntax for 'let' that ghci accepts is not the same as we would use
at the “top level” of a normal Haskell program.
"""
-- http://book.realworldhaskell.org/read/getting-started.html
Cheers,
Chris
--
http://blog.rebertia.com
More information about the Python-list
mailing list