Live data from Hacker News

Why Does “=” Mean Assignment?

hillelwayne.com

31–40 of 367 posts

Re: Why Does “=” Mean Assignment?

#31
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.

That I believe is only Algol the more widely used 1st gen languages FORTRAN and COBOL used = As did PL1/G

Re: Why Does “=” Mean Assignment?

#32
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…

Prolog's unification:

  X = Y,
  X = 5,
  %% Y = 5 now as well
--

  ?- append([1,2], Y, [1,2,3]).
  Y = [3].

Re: Why Does “=” Mean Assignment?

#34
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.

That I believe is only Algol the more widely used 1st gen languages FORTRAN and COBOL used = As did PL1/G

Pascal as well, and its descendents like Modula-2

Re: Why Does “=” Mean Assignment?

#35
post #26

Earlier quoted context omitted.

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

From the article: > Looking at this as a whole, = was never “the natural choice” the assignment operator. Pretty much everybody used := for assignment instead, possibly because = was so associated with equality. Nowadays most languages use = entirely because C uses it, and we can trace C using it to CPL being such a clusterfuck.

And I dispute the "pretty much everybody used" part. In fact, I think the article contradicts that opinion. Algol used it, and so did Pascal. But Pascal was only a year old [Edit: at the time the choice was made for C] - it [Pascal] hadn't set the world on fire yet (to the degree that ever did). That leaves Algol using ":=", and FORTRAN, COBOL, and Lisp not using it. That's not "pretty much everybody used".

Re: Why Does “=” Mean Assignment?

#36
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.

Re: Why Does “=” Mean Assignment?

#37
I like = for assignment, but I don't like it for configuration. HCL and TOML chose it, to their detriment, I think.

When it reads as "let x equal y" it makes sense. I think it makes good sense for imperative programming. It makes slightly less sense for functional programming. For declarative configuration, I think a colon makes much more sense.

Re: Why Does “=” Mean Assignment?

#38
post #8

About once every year I have a brain fart on a sleepy morning and confuse myself by using = for comparitors and or == for assignment... shortly followed by "Nnarhh". [edit] :P LOL at downvotes, HN is no place for silly annecdotes "this is serious things we dooo".

There are better places if you just want to talk about yourself.

Re: Why Does “=” Mean Assignment?

#40
post #10
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.

There’s also <-, most commonly seen in R but draws it’s heritage from the APL keyboard

Fun fact, R also has -> (assign to the RHS instead of LHS), and "super-assignment" >, and also can use = sometimes too (and I think has different semantics). Yay R.
Post reply on HN