> Prolog came out the same year as C and popularized logic programming, and you can sort of fake assignment with cuts. Can anyone explain to me what this is supposed to mean? (I know Prolog, I understand cuts very well. But I don't know what the author means here.)
Why Does “=” Mean Assignment?
71–80 of 367 posts
Re: Why Does “=” Mean Assignment?
#72I've always had the notion that if I made a language I'd make the operators := and == so it'd be harder to accidentally use the wrong one.
Re: Why Does “=” Mean Assignment?
#73Re: Why Does “=” Mean Assignment?
#74more broadly, why schools are merging reduction and equality in arithmetic ?
What do you mean?
2 + 2 = 4
=
I don't recall teacher showing you equalness through stupid but important ideas: 2 + 2 = 2 + 2
2 + 2 = 2 + 1 + 1
all these are equal, and it's important later on when expression, with variables, aren't reducible to a constant but to another expression which is equal to the other one. IMO it would help a lot for people to try to simplify a problem into a known identity or interesting form (for instance the 'trick' of adding and subtracting one to get closer to binomial formula or other)Re: Why Does “=” Mean Assignment?
#75Re: Why Does “=” Mean Assignment?
#76I've been programming professionally for 25 years using mostly C inspired languages, and I will still regularly write "if(foo = bar)" on a daily basis and not notice until there's an error. It's easily the most common syntax error I write, followed closely by using commas in my for-loop as apparently it looks like a function to my fingers: "for(x=0, x<10, x++)"
Re: Why Does “=” Mean Assignment?
#77In pure algorithmic notation, people might use <- or <= instead.
Re: Why Does “=” Mean Assignment?
#78Because 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
Re: Why Does “=” Mean Assignment?
#79The length of symbols should roughly be negatively correlated with its frequency. Since in procedural language, assignment is a much more common operation than equality check, it is reasonable to favor "=" over ":=" or even "<-".
Re: Why Does “=” Mean Assignment?
#80A classic way to guard against accidental use of assignment in logic statements is to write it "backwards", i.e.:
if (2 == x) {...}
Since (2 = x) won't compile, while (x = 2) will not only compile but might appear to work for a very long time.