4 ms·
>A common FP critique of imperative programming goes like this: “How can a = a + 1? That’s like saying 1 = 2. Mutable assignment makes no sense.” This is a nota
by PrimHelios 8y ago
>A common FP critique of imperative programming goes like this: “How can a = a + 1? That’s like saying 1 = 2. Mutable assignment makes no sense.” This is a notation mismatch: “equals” should mean “equality”, when it really means “assign”.
I sort of disagree with this. Many functional languages pull heavily from lambda calculus and other forms of mathematics. In math, "a = a + 1" isn't the same as "1 = 2". The issue isn't equality, it's that you're trying to rebind a bound variable, which isn't possible.
In other words, rebinding a bound variable is not the same as "1 = 2".
- kbp 8y ago> In math, "a = a + 1" isn't the same as "1 = 2". The issue isn't equality, it's that you're trying to rebind a bound variable, which isn't possible. "=" means equality in math; a = a + 1 is the same as 1 = 2 because if you subtract a from both sides and add 1 to both sides you get 1 = 2. Lambda calculus has the concept of binding variables, but it doesn't use "=" for that, it uses application of lambda forms. It's the same idea that's applied in some variants of Lisp, where LET is a macro such that (let ((x 1) (y 2)) ...) expands to ((lambda (x y) ...) 1 2). The way it plays out is that rebinding is perfectly fine, because it's not really any different from binding in the first place. The same way that (let ((x 10)) (f x) (setf x (1+ x)) (g x)) can be re-written as ((lambda (x) (f x) (setf x (1+ x)) (g x)) 10) That can itself be re-written as: ((lambda (x) (f x) ((lambda (x) (g x)) (1+ x))) 10) If you'd like to read more about this sort of thing, Sussman and Steele's "Lambda: The Ultimate Imperative" is a good starter: http://repository.readscheme.org/ftp/papers/ai-lab-pubs/AIM-353.pdf http://repository.readscheme.org/ftp/papers/ai-lab-pubs/AIM-...
- kazinator 8y agoRebinding is essential for recursion, which is a concept in mathematics. Given a fib(x) function defined in terms of itself, the when we express fib(10), the parameter x is simultaneously bound to a number of different arguments through the recursion. We just understand those to be different x's in different instances of the f scope. Rebinding is also needed for simple composition of operations. Given some f(x), the formula f(3) + f(4) involves x being simultaneously bound to 3 and 4 in different instances of the scope inside f.
- kazinator 8y agoOf course you can rebind a bound variable; by extending into a new scope. Functions cannot "work" in math if arguments cannot simultaneously be bound to different values. Recursion is not possible, and so defining computation in terms of recursion goes out the window.
- lmm 8y ago> rebinding a bound variable is not the same as "1 = 2". Therefore using "=" to mean "bind variable" is a notation mismatch, which is the whole point of what you quoted, no?