Live data from Hacker News

Why Does “=” Mean Assignment?

hillelwayne.com

51–60 of 367 posts

Re: Why Does “=” Mean Assignment?

#51

because in math it means assignment. y = mx+b That is an assignment. There is also a math symbol that specifically designates equivalence.

I sympathize with this view; I did some simple programming in C-like languages before I learned algebra, and it's sometimes hard to not see = this way.

But if = in math notation denoted "assignment", what could ≠ mean?

Re: Why Does “=” Mean Assignment?

#53
post #5

Because 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.

Traditionally? I don't think there was a "tradition". ":=" was used in Algol. "=" was used in Fortran. COBOL didn't use either "=" or ":=".

FORTRAN was far from the first high level language.

Plankalkül for example was out a decade earlier and used →. EX:

  P1 max3 (V0[:8.0],V1[:8.0],V2[:8.0]) → R0[:8.0]
https://en.wikipedia.org/wiki/Plankalk%C3%BCl

So, there really was a lot of languages out there, but := was fairly common because it was easy to parse and type.

Re: Why Does “=” Mean Assignment?

#55

because 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?

#56
post #13

Another interesting way to think about it is as "match". That is try to match the stuff on the right with the stuff on the left. Take Erlang for example: 1> X = 1. 1 2> X = 2. ** exception error: no match of right hand side value 2 Notice variables are immutable (not just values themselves). Once X becomes 1, it can only match with 1 after that. You might think this is silly or annoying, why not just allow reassignme…

I'm sure I've mentioned it here before, but in my favorite Erlang talk I design the language with the equal sign as my core construct. Since the equal sign is an assertion of truth, and since assertions cause a crash on failure, you can pretty much derive the rest of the language/BEAM characteristics from that.

I don't think I've heard of this before; I'd love to watch it if you have a link!

Re: Why Does “=” Mean Assignment?

#57
post #56

Earlier quoted context omitted.

I'm sure I've mentioned it here before, but in my favorite Erlang talk I design the language with the equal sign as my core construct. Since the equal sign is an assertion of truth, and since assertions cause a crash on failure, you can pretty much derive the rest of the language/BEAM characteristics from that.

I don't think I've heard of this before; I'd love to watch it if you have a link!

I'd also want to see the link, if available!

Re: Why Does “=” Mean Assignment?

#59
post #21

Earlier quoted context omitted.

Ditto. Fun fact: various dialects of BASIC let you optionally put LET before your assignment statements. So the following are equivalent: X = 10 LET X = 10

Wait...LET was optional? Auigh! Whole months of my childhood, wasted!

Depends on the dialect. It was mandatory on the Sinclair BASICs, for example (ZX81/ZX Spectrum), but optional on the Amstrad (Locomotive/Mallard) and BBC BASICs. A quick search suggests it was optional as early as "MicroSoft"'s Altair BASIC: http://swtpc.com/mholley/Altair/BasicLanguage.pdf

As someone who learned first on a ZX81, I'd always assumed that "LET X=5" was the canonical form, and that "X=5" for assignment was just a shortening for convenience.

Post reply on HN