ForList
expects a function that maps elements to a result. But Browse
is a procedure that does not return anything. ForList
should probably look more like this:
proc {ForList F L}
case L of H|T then
{F H}
{ForList F T}
else
skip
end
end
This is exactly the difference between the built-in function List.forAll
and List.map
.
BTW, in the definition of MyFor
you are using global variables X
and L
. This will cause problems when MyFor
is called more than once. You should use local variables instead. Like so:
proc {MyFor F Init End}
L X
in
L = {Listing Init End}
X = {ForList F L}
end