Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Documentation and Tutorials >> On = and ==
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1294852558

Message started by Mark Bernstein on Jan 12th, 2011, 12:15pm

Title: On = and ==
Post by Mark Bernstein on Jan 12th, 2011, 12:15pm

iGregor asks,


Quote:
Where can I get an explanation of the difference between "=" and "==" ?


Tinderbox historically uses "=" in two different ways -- to test whether two things are equal:

    if($Score=100) { ...

and to assign a value to an attribute

    $Score=42

In principle, we can tell from the context what we mean. In practice, figuring out intention can be tricky. This ambiguity crops up in all sorts of programming languages.

Example: what do we mean by this:  $GameOver=$Score=100 ?

A common solution is to use one operator for comparison and a different operator for assignment.  So, we can write

     $Score==100

to compare the score to 100, and

    $Score=100

to set the score to 100.

For the time being, a single "=" continues to mean "compare" in contexts where a comparison is called for, such as in an agent query or and if() statement.  In these contexts, ''==" is synonymous with "=". In the future, though, we might disallow the old meaning. In any case, "==" makes your intention more clear, which may be important when you revisit your notes at the end of your PhD project, or when your biographer is trying to discover just how you arrived at your crucial discovery.

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.