LANG¶
DESCRIPTION¶
These are the operators availailable in LPC. They are listed in the order of precedence (low priority first):
,expr1 , expr2=var = expr=var = expr+=var += exprvar = var + expr.-=var -= exprvar = var - expr.&=var &= exprvar = var & expr.|=var |= exprvar = var | expr.^=var ^= exprvar = var ^ expr.<<=var <<= exprvar = var << expr.>>=var >>= exprvar = var >> expr.>>>=var >>>= exprvar = var >>> expr.*=var *= exprvar = var * expr.%=var %= exprvar = var % expr./=var /= exprvar = var / expr.&&=var &&= exprvar = var && expr.||=var ||= exprvar = var || expr.?expr1 ? expr2 : expr3||expr1 || expr2&&expr1 && expr2|expr1 | expr2The result is the bitwise or of ‘expr1’ and ‘expr2’.
For arrays, the union set is computed: all elements from expr1 plus all those from expr2 which are not in expr1.
^expr1 ^ expr2The result is the bitwise xor of ‘expr1’ and ‘expr2’.
For arrays, the symmetric difference is computed: all elements from expr1 which are not in expr2, plus all those from expr2 which are not in expr1.
&expr1 & expr2The result is the bitwise and of ‘expr1’ and ‘expr2’.
For arrays and strings, the intersection set (all elements resp. characters from expr1 which which are also in the expr2) is computed.
Warning
"aab" & "a" -> "aa" but ({ 'a','a','b' }) & ({ 'a' }) -> ({ 'a' })
Eventually the array behaviour will be changed to match the string behaviour, so you shouldn’t rely on the array behavior in the interim.
Intersecting an array with a mapping is equivalent to intersecting the array with the indices of the mapping: array & mapping == array & m_indices(mapping).
Mappings can be intersected with another mapping or an array. The resulting mapping holds all those entries from the first mapping, which are also mentioned in the second mapping (as index) resp. in the array.
==expr1 == expr2!=expr1 != expr1>expr1 > expr2>=expr1 >= expr2<expr1 < expr2<=expr1 <= expr2<<expr1 << expr2>>expr1 >> expr2>>>expr1 >>> expr2+expr1 + expr2expr1 if non-empty, and expr2 otherwise.-expr1 - expr2\*expr1 \* expr2%expr1 % expr2/expr1 / expr2++++ var---- var-- var!! var~~ var( type ) varReturn the value of var converted to type. type can be ‘string’, ‘int’, ‘object’, ‘float’ or ‘int*’. var must be of a specific type for a conversion to take place; if var is ‘mixed’ or unknown, the cast is purely declarative. Also, if the declared type of var is that of type, the value is not changed.
NB. The literal number 0 is of unknown type, as it doubles as ‘not initialized’ for strings, objects, and arrays.
The operator acts like
to_string(E),to_int(E),to_object(E),to_float(E) andto_array(E). It is advisable to use the efuns directly instead of the cast.
({ type }) varvar is now assumed to have the type type. This is purely declarative, the actual value of var is not changed.++var ++--var --expr1[expr2]expr1[expr2..expr3]count from before the beginning, i.e. foo[-2..-1] is an empty array or string. foo[<2..<1] gives the 2nd and last element of the array resp. chars of the string.expr1->name(...)call_other(E). ‘expr1’ gives either an object or a string which is used as the file_name of an object, and calls the function ‘name’ in this object.ident::name(...)({ })([ ])Note
The closure operators are not described here.
operators ::=arrow_operator|arithmetic_operators
HISTORY¶
- changed (3.2.9) – added >>>,>>>=,&&=and||=.
- changed (3.2.10) – extended &to mappings.
- changed (3.3) – extended |and^to arrays.