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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
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. |
|
|
|
|
![](images/spacer.gif) |
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) |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Tue May 08, 2012 11:03 am Post subject: RE::= and =? |
|
|
Could you give us an example, mirhagk? |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
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. |
|
|
|
![](images/spacer.gif) |
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] |
|
|
|
|
![](images/spacer.gif) |
evildaddy911
|
Posted: Tue May 08, 2012 3:50 pm Post subject: RE::= and =? |
|
|
no, turing gives you a syntax error |
|
|
|
|
![](images/spacer.gif) |
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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|