how a pure functional programming language manage without assignment statements?

Posted by Gnijuohz on Programmers See other posts from Programmers or by Gnijuohz
Published on 2012-04-12T04:57:48Z Indexed on 2012/04/12 5:40 UTC
Read the original article Hit count: 292

When reading the famous SICP,I found the authors seem rather reluctant to introduce the assignment statement to Scheme in Chapter 3.I read the text and kind of understand why they feel so.

As Scheme is the first functional programming language I ever know something about,I am kind of surprised that there are some functional programming languages(not Scheme of course) can do without assignments.

Let use the example the book offers,the bank account example.If there is no assignment statement,how can this be done?How to change the balance variable?I ask so because I know there are some so-called pure functional languages out there and according to the Turing complete theory,this must can be done too.

I learned C,Java,Python and use assignments a lot in every program I wrote.So it's really an eye-opening experience.I really hope someone can briefly explain how assignments are avoided in those functional programming languages and what profound impact(if any) it has on these languages.

The example mentioned above is here:

(define (make-withdraw balance)
    (lambda (amount)
        (if (>= balance amount)
            (begin (set! balance (- balance amount))
                balance)
            "Insufficient funds")))

This changed the balance by set!.To me it looks a lot like a class method to change the class member balance.

As I said,I am not familiar with functional programming languages,so if I said something wrong about them,feel free to point out.

© Programmers or respective owner

Related posts about programming-languages

Related posts about functional-programming