Welcome, Guest. Please Login
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
Pages: 1
Send Topic Print
On = and == (Read 3288 times)
Mark Bernstein
YaBB Administrator

designer of

Posts: 2871
Eastgate Systems, Inc.
On = and ==
Jan 12th, 2011, 12:15pm
iGregor asks,

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


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


to compare the score to 100, and


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.
Back to top
WWW   IP Logged
Pages: 1
Send Topic Print