assistance-engine/docs/developer.avapframework.com/chapter9_16.md

18 lines
963 B
Markdown

## 6.2.4. Comprehensions for Lists, Sets and Dictionaries
To construct a list, set, or dictionary, AVAP provides special syntax called "comprehension," each in two flavors:
* The contents of the container are listed explicitly.
* They are computed using a set of loop and filtering instructions, called a "comprehension."
Common syntax elements for comprehensions are:
```javascript
comprehension ::= assignment_expression comp_for
comp_for ::= "for" target_list "in" or_test [comp_iter]
comp_iter ::= comp_for | comp_if
comp_if ::= "if" or_test [comp_iter]
```
A comprehension consists of a single expression followed by at least one `for` clause and zero or more `for` or `if` clauses. In this case, the elements of the new container are those produced by considering each `for` or `if` clause as a block, nested from left to right, and evaluating the expression to produce an element each time the innermost block is reached.