Anvil | Smiths Smiths | Register Register | Login Login |
Search:
Show links Show tools Show tree | Previous document Next document | njet.org > Anvil > Documentation > Language reference > Expressions > Unary operators

Unary operators

Unary operators take one expression as the operand.

Unary plus (!) evaluates an operand, converts it to boolean, and returns its negation.

Unary plus (+) takes an integer, float, or string representing an integer or float operand, and returns the same number unchanged.

Unary plus (-) takes an integer, float, or string representing an integer or float operand, and returns the negative of the same number.

Unary star (*) is an enumeration operator:

  • If an operand yields to enumeration, next element is returned.
  • If an operand yields to something other than enumeration, enumeration of its elements is returned. What enumeration returns is type-specific; there is callback ``_enumeration()´´ for classes.

Copyof creates a deep copy from an operand. This is the same as the call to ``copyOf()´´ method.

Cloneof creates a shallow copy from an operand. The is the same as the call to ``cloneOf()´´ method.

Sizeof returns the number of elements in the operand. This is the same as the call to ``sizeOf()´´ method.

Classof returns the type of operand as anvil.runtime.Type. This is the same as the meta attribute ``expr.class´´.

  unary-expr := "!" expr 
  unary-expr := "+" expr 
  unary-expr := "-" expr 
  unary-expr := "*" expriterable 
  unary-expr := "copyof" exprcopyable 
  unary-expr := "cloneof" exprcloneable 
  unary-expr := "sizeof" expr 
  unary-expr := "classof" expr 
See also  | Expressions  | Grammar
Contributes notes:
Add a note
What's new | Anvil