/* Apply a callback to an array in Picat. From Rosetta Code: http://rosettacode.org/wiki/Apply_a_callback_to_an_array """ In this task, the goal is to take a combined set of elements and apply a function to each element. """ Note: As of writing (Picat version alpha 0.1), don't support anonymous (lambda) functions so the function must be defined in the program. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import cp. main => go. go => L = 1..10, % some different approaches writeln(L.map(fun)), writeln(map(L,fun)), writeln(map(fun,L)), writeln([fun(I) : I in L]), writeln([apply(fun,I) : I in L]), writeln([I*I : I in L]), nl. fun(X) = X*X.