Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 := and =?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Luffy123




PostPosted: 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
Sponsor
sponsor
Amarylis




PostPosted: 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




PostPosted: 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




PostPosted: Tue May 08, 2012 11:03 am   Post subject: RE::= and =?

Could you give us an example, mirhagk?
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
mirhagk




PostPosted: 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




PostPosted: Tue May 08, 2012 3:50 pm   Post subject: RE::= and =?

no, turing gives you a syntax error
mirhagk




PostPosted: 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
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: