I'm not sure I understand this. The main problem
seems to be how to call a function with variable arguments, but the part
to generate all the parameters/values is not a problem. Is that
correct?
If so, here are some answers/hints.
First,
there's no "unpack" function in Picat which corresponds to Javascript's
"...". I'm not sure how you define fnc/1,,m, but I assume that it's
defined for all possible values.
One way might be to use Picat's "=.." (univ) function and then apply/1.
Here's a simple example where fnc/1..n is to simply sum all the arguments.
"""
main ?=>
foreach(I in 1..8)
L = 1..I,
println(L),
F =.. [fnc] ++ L,
println(F),
println(apply(F)),
end,
nl.
main => true.
fnc(A) = A.
fnc(A,B) = A+B.
fnc(A,B,C) = A+B+C.
fnc(A,B,C,D) = A+B+C+D.
fnc(A,B,C,D,E) = A+B+C+D+E.
fnc(A,B,C,D,E,F) = A+B+C+D+E+F.
fnc(A,B,C,D,E,F,G) = A+B+C+D+E+F+G.
fnc(A,B,C,D,E,F,G,H) = A+B+C+D+E+F+G+H.
"""
The output:
"""
[1]
fnc(1)
1
[1,2]
fnc(1,2)
3
[1,2,3]
fnc(1,2,3)
6
[1,2,3,4]
fnc(1,2,3,4)
10
[1,2,3,4,5]
fnc(1,2,3,4,5)
15
[1,2,3,4,5,6]
fnc(1,2,3,4,5,6)
21
[1,2,3,4,5,6,7]
fnc(1,2,3,4,5,6,7)
28
[1,2,3,4,5,6,7,8]
fnc(1,2,3,4,5,6,7,8)
36
"""
Explanations:
- F =.. [fnc] ++ L: This converts the list L into a function fnc(L[1],L[2],..)
- apply(F): This calls the created function F and returns the value.
That
being said, a better approach might be to have a single function
fcn(L) where L is the list of the values, and then to generate the
result from that list. Since you don't give any details about what
fnc/1..n does, it's hard to give some more details on this.
Hope this helps. If not, please give some more details, and perhaps also some small examples.
/Hakan