Author |
Message |
Luffy123
|
Posted: Mon May 07, 2012 8:31 pm Post subject: := 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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Amarylis
|
Posted: Mon May 07, 2012 8:33 pm Post subject: 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
|
Posted: Mon May 07, 2012 10:03 pm Post subject: 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
|
Posted: Tue May 08, 2012 11:03 am Post subject: RE::= and =? |
|
|
Could you give us an example, mirhagk? |
|
|
|
|
|
Tony
|
Posted: Tue May 08, 2012 12:22 pm Post subject: RE::= and =? |
|
|
in C and such one might accidentally write code such as*
code: |
if (counter := 3) {
% expecting counter to be 3
|
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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
mirhagk
|
Posted: Tue May 08, 2012 3:24 pm Post subject: 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
|
Posted: Tue May 08, 2012 3:50 pm Post subject: RE::= and =? |
|
|
no, turing gives you a syntax error |
|
|
|
|
|
mirhagk
|
Posted: Tue May 08, 2012 7:41 pm Post subject: RE::= and =? |
|
|
so then I can't think of a context where it'd be an issue |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|