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 > Primaries > Arrays

Arrays

Array has features of hashtable and list. While it is capable of effective random lookups with a key, it also retains a double-linked list of elements, in the order of insertion. An array is created with angle brackets, yielding a value of type anvil.lang.array. An empty array is generated with empty brackets. There may also be an extra comma after elements.

If the expression inside array is a mapping ``key=>value, then the corresponding key/value pair is added to the array; otherwise, the next available integer is used as the key.

Arrays may also be created using comprehension which will create an array containig all the elements (or mappings) evaluted in the right-most expression.

  array-expr := "[" array-mapping ("," array-mapping )* [","] "]" 
  array-expr := "[" comprehension-foreach "]" 
  array-mapping := exprkey ["=>" exprvalue ] 
  comprehension-foreach :=  "foreach" "(" ... ")" comprehension 
  comprehension-if ::= "if" "(" expr ")" comprehension 
  comprehension := comprehension-foreach | comprehension-if | expr 
See also  | Primaries  | Mappings  | Grammar
Contributes notes:
Add a note
What's new | Anvil