0

I'm trying to create a List of functions is oz, this list will be pasted to another function as an input. Someone can help me with this?

Anita
  • 43
  • 5

1 Answers1

0
declare
fun{Op State FunctionList}
   case FunctionList of H|T then {Op {H State} T}
   [] nil then State
   end
end

X={Op 1 [fun{$ S} S+4 end
         fun{$ S} S*2 end
         fun{$ S} S-3 end
         fun{$ S} S*S end]}

{Browse X}

In this exemple, the function Op execute a list of function with a state in argument. (((1+4)*2)-3)^2=49

declare
fun{Power L U} %return a list of power function from ^L to ^U
   if L>U then nil
   else fun{$ X} {Pow X L} end | {Power L+1 U}
   end
end

FList={Power 0 10}

{Browse {Map FList fun{$ Fun} {Fun 2} end}}

In this other example, the function Power generate a list of power function [X¹ X² X³...]. Then, for every function in the list, another function is applied. That last function take each function as argument and give it 2 as argument...

yakoudbz
  • 903
  • 1
  • 6
  • 14