Editing
Squirrel Expressions
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
<div style="width:33.333%; z-index: 1; top: 0px; position: sticky; height: 30px; display: inline-block; text-align: center; line-height: 30px; background-color:#BBBBBB;">[https://sigwiki.potato.tf/index.php/Squirrel_Operators BACK]</div><div style="width:33.333%; z-index: 1; top: 0px; position: sticky; height: 30px; display: inline-block; text-align:center; line-height: 30px; background-color:#BBBBBB;">[https://sigwiki.potato.tf/index.php/An_Introduction_to_Squirrel HOME]</div><div style="width:33.333%; z-index: 1; top: 0px; position: sticky; height: 30px; display: inline-block; text-align:center; line-height: 30px; background-color:#BBBBBB;">[https://sigwiki.potato.tf/index.php/Squirrel_Intro_to_Functions NEXT]</div> Expressions are combinations of literals, variables, and operators which are evaluated to return a single value, which can then be used in variable assignment or other tasks. <syntaxhighlight lang="c#" line="1" start="1" style="font-weight:bold;> printl(1 + 2 + 3); // 1 + 2 + 3 is an expression which evaluates to the integer 6, 6 is then printed to the console local x = 500.0 / 2; // 500 / 2 is an expression which evaluates to 250.0, 250.0 is then assigned to x </syntaxhighlight> With all the working parts, especially the operators, you might wonder how the compiler knows what order to parse your code in, or what order of operations to adhere to. This is called operator precedence, which determines what operators are called first over others in the same expression. You can view the [http://squirrel-lang.org/squirreldoc/reference/language/expressions.html?highlight=bitwise#operators-precedence Squirrel Precedence List] in the Squirrel Reference Manual. Keep in mind you should use this as a ''reference'', don't try to memorize the whole list, it's not necessary. Concerning precedence, there a few things that are worth remembering however, The most important is that parentheses have the highest operator precedence. If you're not sure of a particular operator precedence issue you can enforce your own order of operations with parentheses and get along just fine. Another important one is the precedence of logical NOT AND & OR between themselves, these are frequently used in programs together, so it's useful to remember the precedence order. NOT has the highest, then AND, and the lowest is OR. NOT AND OR. The same applies to the bitwise NOT AND OR/XOR. One last precedence issue that might pop up semi-frequently is that bitwise AND has a lower precedence than the relational operators (namely the inequality operator). This is relevant for the example in the previous chapter of testing for the existence of bit flags. (Note the parentheses present in that example) <syntaxhighlight lang="c#" line="1" start="1" style="font-weight:bold;> printl("beevus" || !true && "butthead"); // "beevus" // !true is evaluated first, NOT has the highest precedence, it becomes false // next is false && "butthead", which becomes false // next is "beevus" || false, which finally evaluates to "beevus", which is then printed to console </syntaxhighlight>
Summary:
Please note that all contributions to SigMod are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
SigMod:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
British English
Views
Read
Edit
Edit source
View history
More
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information