Task

Select certain elements from an Array into a new Array in a generic way.



To demonstrate, select all even numbers from an Array.

As an option, give a second solution which filters destructively,
by modifying the original Array rather than creating a new Array.




procedure main()
 
every put(A := [],1 to 10)              # make a list of 1..10
every put(B := [],iseven(!A))           # make a second list and filter out odd numbers
every writes(!B," ") | write()          # show
end
 
procedure iseven(x)                     #: return x if x is even or fail
if x % 2 = 0 then return x
end