Using an anonymous function

  The function which divides its argument by 2

 

map((x) => x/2, [1,2,3,4])

   ==>   [0,1,1,2]

 

(In rex, division is integer division  (truncating) unless one of the arguments is floating point, in which case the result is too.)

 

In general:

(X) Þ some expression E

is read:

"The function which, with argument X, returns the value of E".

E will usually  contain X, although it need not:

(X) Þ 5

is the function which yields 5 regardless of argument.

 

map((x) Þ 5, [1,2,3,4]) ==> [5,5,5,5]

map is called "higher-order" because it is a function taking a function  as its argument

 

To Next Slide To Previous Slide To Contents