There are several E built-in functions which use lists and quoted expressions in powerful ways. These functions are similar to functional programming constructs and, basically, they allow for very readable code, which otherwise would require iterative algorithms (i.e., loops).

`MapList(`

`address`,`list`,`e-list`,`quoted-exp`)-
The
`address`is the address of a variable (e.g.,`{x}`

),`list`is a list or E-list (the source),`e-list`is an E-list variable (the destination), and`quoted-exp`is the address of an expression which involves the addressed variable (e.g.,``x+2`

). The effect of the function is to take, in turn, a value from`list`, store it at`address`, evaluate the quoted expression and store the result in the destination list. The resulting list is also returned (for convenience).For example:

MapList({y}, [1,2,3,a,99,1+c], lt, `y*y)

`lt`

taking the value:[1,4,9,a*a,9801,(1+c)*(1+c)]

`MapList`

**mapped**the function (the quoted expression) across the (source) list. `ForAll(`

`address`,`list`,`quoted-exp`)-
Works just like
`MapList`

except that the resulting list is not stored. Instead,`ForAll`

returns`TRUE`

if every element of the resulting list is true (i.e., non-zero), and`FALSE`

otherwise. In this way it decides whether the quoted expression is true**for all**elements of the source list. For example, the following are`TRUE`

:ForAll({x}, [1,2,-13,8,0], `x<10) ForAll({x}, [1,2,-13,8,0], `x<=8) ForAll({x}, [1,2,-13,8,0], `x>-20)

`FALSE`

:ForAll({x}, [1,2,-13,8,0], `x OR x) ForAll({x}, [1,2,-13,8,0], `x=2) ForAll({x}, [1,2,-13,8,0], `x<>2)

`Exists(`

`address`,`list`,`quoted-exp`)-
Works just like
`ForAll`

except it returns`TRUE`

if the quoted expression is true (i.e., non-zero) for at least one of the source list elements, and`FALSE`

otherwise. For example, the following are`TRUE`

:Exists({x}, [1,2,-13,8,0], `x<10) Exists({x}, [1,2,-13,8,0], `x=2) Exists({x}, [1,2,-13,8,0], `x>0)

`FALSE`

:Exists({x}, [1,2,-13,8,0], `x<-20) Exists({x}, [1,2,-13,8,0], `x=4) Exists({x}, [1,2,-13,8,0], `x>8)

`SelectList(`

`address`,`list`,`e-list`,`quoted-exp`)-
Works just like
`MapList`

except the`quoted-exp`is used to decide which elements from`list`are copied to`e-list`. The only elements which are copied are those for which`quoted-exp`is true (i.e., non-zero). The resulting list is also returned (for convenience).For example:

SelectList({y}, [99,6,1,2,7,1,1,6,6], lt, `y>5)

`lt`

taking the value:[99,6,7,6,6]

Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.