
-----------------------------------
Luffy123
Mon May 07, 2012 8:31 pm

:= and =?
-----------------------------------
What is the difference between the two?

I tried and it works still.

var num : int

num = 3
num := 3

both work.

the first one gets a warning though but still works.

-----------------------------------
Amarylis
Mon May 07, 2012 8:33 pm

RE::= and =?
-----------------------------------
The first one, while it does work, is supposed to be only for boolean expressions (comparison). The second one is the actual syntax for value assignment.

-----------------------------------
mirhagk
Mon May 07, 2012 10:03 pm

RE::= and =?
-----------------------------------
You should never use the first way, as within certain contexts it could be problematic (although those contexts  might not be common in Turing)

-----------------------------------
Raknarg
Tue May 08, 2012 11:03 am

RE::= and =?
-----------------------------------
Could you give us an example, mirhagk?

-----------------------------------
Tony
Tue May 08, 2012 12:22 pm

RE::= and =?
-----------------------------------
in C and such one might accidentally write code such as*
[code]
if (counter := 3) {
   % expecting counter to be 3
[/code]
instead the code _assigns_ 3 to the counter, and the result is evaluated to be true.

* actual C code uses == for comparison and = for assignment.

-----------------------------------
mirhagk
Tue May 08, 2012 3:24 pm

RE::= and =?
-----------------------------------
That is precisely what I was thinking of Tony. Although I'm trying to think of a way this could happen in Turing. Does turing set equal operator return the value? Is the following possible?

[syntax="turing']
var num1:=42
var num2:int
var num3:=num2:=num1
[/syntax]

-----------------------------------
evildaddy911
Tue May 08, 2012 3:50 pm

RE::= and =?
-----------------------------------
no, turing gives you a syntax error

-----------------------------------
mirhagk
Tue May 08, 2012 7:41 pm

RE::= and =?
-----------------------------------
so then I can't think of a context where it'd be an issue
