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
set!. To me it looks a lot like a class method to change the class member
As I said, I am not familiar with functional programming languages, so if I said something wrong about them, feel free to point out.
EDIT:I guess to fully understand the question, I have to dig into a pure functional programming language.Thanks for all the answers. I sure learned a lot.