Why Does “=” Mean Assignment?
161–170 of 367 posts
Re: Why Does “=” Mean Assignment?
#162Because K&R had terrible keyboards so they abbreviated everything as much as possible. Traditionally := was used for assignment, which makes sense since it is an asymmetric symbol for an asymmetric operation.
We read it out loud as "becomes the same as", this being what was actually happening. I've carried the habit over to C despite the bare =, it helps me reason and seems to aid in preventing the =/== error.
Re: Why Does “=” Mean Assignment?
#163Re: Why Does “=” Mean Assignment?
#164= has contextual meaning in math, why not programming? It's not like we can fool ourselves into thinking that tests for equality don't also have wildly different meaning depending on context. No operator has a universal meaning, nor should they.
Re: Why Does “=” Mean Assignment?
#165Because K&R had terrible keyboards so they abbreviated everything as much as possible. Traditionally := was used for assignment, which makes sense since it is an asymmetric symbol for an asymmetric operation.
Re: Why Does “=” Mean Assignment?
#166>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 i…
"=" 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-...Re: Why Does “=” Mean Assignment?
#167Is it really worth allowing assignment in places so weird that you also need ==? Wouldn't it be easier to use = for everything and get rid of those weird edge cases?
Yeah I was pretty surprised when I found out that assignment and equality can be totally syntactically separate and nonambiguous with miminal language-design effort. Just get rid of the silly idea of allowing expressions as statements. Although even then it's nice to use different symbols because they are different meanings. I don't like it when a word has different meanings depending on context.
I don't think that's enough. Take the two following Python lines:
a = b = c == d
a = b == c == d
No expression is being used as a statement, yet you can't syntactically separate assignment from equality.Re: Why Does “=” Mean Assignment?
#168>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 i…
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.
Re: Why Does “=” Mean Assignment?
#169because in math it means assignment. y = mx+b That is an assignment. There is also a math symbol that specifically designates equivalence.
The concept of assignment only makes sense in a context with a time axis. Computation has a time axis (location of the instruction pointer) but math does not.
Re: Why Does “=” Mean Assignment?
#170I think they are forgetting that a lot of languages take que's from old math textbooks where you would see function definitions written as "f(x) = nx + b" or "y = nx + b" and constant assignment with a "c = " notation. if you want to calculate the output of a function into a data table(which is what early computers were often doing) iterating a variable x over a f(x) = xn + b(with n and b being fixed constants) is ex…