Live data from Hacker News

Why Does “=” Mean Assignment?

hillelwayne.com

351–360 of 367 posts

Re: Why Does “=” Mean Assignment?

#351

Earlier quoted context omitted.

FWIW, that's what Ross Ihaka does as well (or at least did in a presentation that I watched - and pointed out that you can use = for assignment). Personally, I think = for assignment is a disaster, and wish I could use in every language.

I've used R since it was in beta form, and one of the most interesting things to me (aside from the evolution of type hierarchy) has been changes in use of the assignment operator. When I started, = was the norm for assignment, with == for evaluating equality. Later I started noticing that people were recommending I agree = versus == can lead to tricky errors in code, but I still prefer = for various reasons in gener…

I teach R, and most of the students have never programmed before, at least not anything other than having been exposed to a configuration file or writing a little html.

x = x+1 is really confusing because of the way kids learn math. The notation x <- x+1 at least conveys the idea of taking a value and storing it somewhere.

Re: Why Does “=” Mean Assignment?

#352

Earlier quoted context omitted.

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…

Likewise - but of course in Sinclair BASIC it was mandatory because every command had to begin with a keyword - a fact enforced by the fact that the cursor started out as a flashing [K], and every key on the keyboard was mapped to directly enter a keyword in that mode. LET was on the 'L' key. You literally couldn't type "a = 1" into a Spectrum/ZX81 - you couldn't type an 'a' unless you were at an [L] cursor prompt, w…

Not too thrown - I went from BASIC to Z80 assembler, and that just had labels...!

Re: Why Does “=” Mean Assignment?

#354
post #2

The '=' sign is used because after that statement the variable will indeed have equality with the r-value. Coincidentally in async languages like Verilog there is a another assignment operator '<=' which means that the variable won't take the new value until the next clock cycle (or more explicitly the next evaluation of the process block). '=' exists also and has the same meaning as with traditional languages.

What about `a = a + 1`?

The r-value is ephemeral it doesn't exist once the statement ends.

Re: Why Does “=” Mean Assignment?

#355
post #252

Earlier quoted context omitted.

I think the simple reason is that two characters are harder to type then one character, if they both are a key combo. And to keep syntax more clean.

Yeah but this introduced an easy path for errors. You could mean to write `==` and instead write `=` and it'll work fine in C in practically all locations (even as conditions of if-statements). Using `:=` could have likely alleviated this error to a noticeable degree, if not entirely.

Chefs rather use a sharp knife then a blunt one, even if they cut themselves from time to time. If safety is a priority, there are special designed languages like Ada that use :=

Re: Why Does “=” Mean Assignment?

#356
post #340
post #323

As the article points out, the big first programming languages, FORTRAN, COBOL, LISP, and Algol each had their own way of doing variable assignment. FORTRAN used "=" and Algol used ":=" the other two languages used commands or functions to set or bind the values of variables. In the mid 60's, when I started programming, most programs had to be keypunched. (There was paper tape entry and Dartmouth's new timesharing sy…

I feel like this is the best answer. People have to work with what they have. Much in the same way that SNES games look the way that do, even though the designers back then were just as smart and talented as the ones today. That’s simply what they could do with the medium at the time. The limitations define the style. And then dogma perpetuates it, as the new generation continues to live with the results of once-grea…

*The limitations define the style. And then dogma perpetuates it, as the new generation continues to live with the once-great but now outdated results of someone else's thinking.

Re: Why Does “=” Mean Assignment?

#357
post #320

Earlier quoted context omitted.

The translation would be structure indexes.

Yeah, I think that would be clear even if I didn't speak German, which I do. I'm curious what their semantics are / what they're for.

Bauer and Woessner [1] weren't very clear on their semantics, but according to Bruines [2], they're type annotations.

[1] https://web.archive.org/web/20090220012346/http://delivery.a...

[2] http://www.cs.ru.nl/bachelorscripties/2010/Bram_Bruines___02...

Re: Why Does “=” Mean Assignment?

#358
post #224
post #143

Earlier quoted context omitted.

> From the article: Articles, like desserts, aren't always right. I am sorely tempted to pull out Sammet's book tonight and start counting.

Too late to edit, but I've gone and done it: scanned through Sammet's Programming Languages: History and Fundamentals for languages with identifiable assignment statements. I skip assembly-style, English-like (COBOL etc.), and functional-style (LISP etc.) syntax, and for summary purposes ignore accompanying keywords like BASIC's LET . Results: ν = ε 18 (AMTRAN, BASIC, COLASL, CPS, FORTRAN, FORTRANSIT, JOSS, JOVIAL, K…

[deleted]

Re: Why Does “=” Mean Assignment?

#359
post #279

Earlier quoted context omitted.

I think GP might have meant that to go the other way around, i.e. don't allow statements to also be expressions, and more specifically, make assignment a statement.

Well first I was super intriguied by the example. But I agree with your conclusion, that statements should not also be expressions, so a = b = c shouldn't work (at least not the way we're used to, that the b = c is an assignment "statement" that also produces an expression value). But in the end all this does is allow "a = b = c" to be a nonambiguous statement meaning, in more familiar notation, "a = b == c". Not exa…

What I've not seen is examples of needing to distinguish between assign and compare, that outweigh the added complexity.

if x=y # obviously compare x=y # obviously assignment x=y=z # is that really needed? If so, brackets

Re: Why Does “=” Mean Assignment?

#360
post #279

Earlier quoted context omitted.

I think GP might have meant that to go the other way around, i.e. don't allow statements to also be expressions, and more specifically, make assignment a statement.

Well first I was super intriguied by the example. But I agree with your conclusion, that statements should not also be expressions, so a = b = c shouldn't work (at least not the way we're used to, that the b = c is an assignment "statement" that also produces an expression value). But in the end all this does is allow "a = b = c" to be a nonambiguous statement meaning, in more familiar notation, "a = b == c". Not exa…

Just noting that I didn't mean to express any particular preference for syntax, just addressing whether it's technically possible. Personally I'm fine with = vs == being prevalent, but might prefer something like := and = respectively.
Post reply on HN