What does ":=" do?
Solution 1
http://en.wikipedia.org/wiki/Equals_sign#In_computer_programming
In computer programming languages, the equals sign typically denotes either a boolean operator to test equality of values (e.g. as in Pascal or Eiffel), which is consistent with the symbol's usage in mathematics, or an assignment operator (e.g. as in C-like languages). Languages making the former choice often use a colon-equals (:=) or ≔ to denote their assignment operator. Languages making the latter choice often use a double equals sign (==) to denote their boolean equality operator.
Note: I found this by searching for colon equals operator
Solution 2
It's the assignment operator in Pascal and is often used in proofs and pseudo-code. It's the same thing as =
in C-dialect languages.
Historically, computer science papers used =
for equality comparisons and ←
for assignments. Pascal used :=
to stand in for the hard-to-type left arrow. C went a different direction and instead decided on the =
and ==
operators.
Solution 3
In the statically typed language Go :=
is initialization and assignment in one step. It is done to allow for interpreted-like creation of variables in a compiled language.
// Creates and assigns
answer := 42
// Creates and assigns
var answer = 42
Solution 4
Another interpretation from outside the world of programming languages comes from Wolfram Mathworld, et al:
If A and B are equal by definition (i.e., A is defined as B), then this is written symbolically as A=B, A:=B, or sometimes A≜B.
■ http://mathworld.wolfram.com/Defined.html
■ https://math.stackexchange.com/questions/182101/appropriate-notation-equiv-versus
Solution 5
Some language uses :=
to act as the assignment operator.
Cyclone
I'm a php web developer. I'm mostly done with my secret project. Hold out just a bit longer! I keep getting distracted by various things, like Project Euler, but at least it's entertaining. When in doubt, Fnord!
Updated on December 09, 2021Comments
-
Cyclone over 2 years
I've seen
:=
used in several code samples, but never with an accompanying explanation. It's not exactly possible to google its use without knowing the proper name for it.What does it do?
-
Beta about 13 yearsIn what language?
-
svens about 13 yearsYou normally use
:=
when you define something, to separate it from regular variable changes.. What programming language are we talking about? -
Andrew about 13 yearsPL/SQL it is for assignment. But given a different language, that answer isn't guarenteed to hold true - so which languages was the example in?
-
PRINCE KUMAR about 13 yearsTo google something like this, spell it out and enclose it in quotes, like so: "colon equals"
-
Admin over 10 yearsI think Pascal's got this operator !
-
Shamaoke over 9 yearsYou can search for special symbols using this service.
-
sevko over 9 yearsThe OP might have been referring to pseudocode, in which I've often seen
:=
.
-
-
nighthawk454 about 9 yearsIronically, this answer is now above Wikipedia when searching for
colon equals operator
. -
TigOldBitties about 9 years@Pacerier see this post stackoverflow.com/questions/7462322/… as to why the answer to your question can be both "Yes" and "No".
-
Pacerier about 9 years@TigOldBitties, Good gotcha from Erwin down there.
-
ATLUS about 8 yearsIf we keep typing
colon equals operator
, we work magic on Google's SEO to make this the top result -
Variadicism about 8 yearsIf they wanted it close to the left arrow, they could have used
<-
like Haskell did. They weren't trying to get close to the left arrow with:=
, they were using the mathematical 'is defined as' operator: mathworld.wolfram.com/Defined.html -
Michael restore Monica Cellio about 8 yearsPedant alert: <- in Haskell is not assignment. Haskell does not have destructive assignment in the way of Pascal, Ada etc. <- is part of the do-notation syntax for parameter substitution. It is more analogous to the process of substituting values into parameters in a subroutine call.
-
Variadicism over 7 years@Michael Fair enough. You're right. My bad. Anyway, the point remains that if they were trying to imitate the left arrow, they would not have used
:=
, they would have used<-
. -
Gabriel Staples about 3 yearsThat link looks old. Here's the updated link (I think), but the quote seems to be massively changed since then and I can't track down the new quote exactly: en.wikipedia.org/wiki/Assignment_(computer_science).