Menu

Overloaded Operators

Csaba Skrabák

Comma Operator vs Comma Syntactic Element

  • The comma may appear as an expected symbol in the arguments of certain instructions (INPUT, POKE.)
  • Comma may also be a separator between labels (ON) or names (DEF). These commas don't work like operators, as they cannot evaluate the two operands. (In the runner's JavaScript array program, such comma appears as a _NAMELIST instruction ; see [Internals] and [Instructions])
  • Otherwise, the comma is considered a part of the expression and creates a list of values out of the value of the expressions on both its sides. See [Operators], [Hacks] page.

Equals Operator vs Equals Syntactic Element

In modern languages, it is often the case that expression evaluation and execution is not distinguished. You can in Java, C, C++, C#, Pascal execute an assignment in an if condition for instance. It is a source of error. You need distinct operator for checking equality and another symbol for assigning a value in these languages, which programmers tend to confuse. Even if they actually use the correct operator, the maintainability is impacted if you hide an assignment deep inside a line of code dealing with other things.
Since in imeight language the IF condition is a place where evaluation happens, and not execution, the equals sign is clearly not an assignment. That is why there is no == or := symbol used in imeight language. = denotes equality check operator in evaluation, and assignment in LET (and implicit LET) instructions.
FOR and DEF instructions also expect equals signs in their arguments. There is no evaluation of operands or checking equality, so the equals sign in these cases is not an operator.
On the other hand, imeight language lacks the possibility of chaining assignments. A=B=8 in Java assigns 8 to both B and A. In imeight language for the same code, B=8 evaluates to 1 if B equals 8, 0 otherwise, and that 1 or 0 Boolean value will be assigned to A.

Addition vs Concatenation

String and numeric types are distinguished by imeight runner. To convert, you have VAL and STR$ functions.
A plus (+) sign between two numeric expressions means addition, while plus sign between a string expression and another (string or numeric) expression is concatenation.

In the emulator, the plus operator is implemented as a JavaScript plus (+) operator, so it will behave similar ways.

Unary vs Binary Minus

Between numeric expressions, dash (-) means subtraction, while before the expression, it will be considered negation, and appears in the tokenized program structure as a function. The unary minus is on the precedence level of multiplication.


Related

Wiki: Hacks
Wiki: Home
Wiki: Instructions
Wiki: Internals
Wiki: Operators

Discussion

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.