How can do it?
t = {};
f =
Compile[{{l, _Integer}},
Module[
{list = {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}}},
Map[AppendTo[t, list[[#]] &], l]];
t
];
CompiledFunction::cfta
there is two related question: this and this.
Update:
with help of Sumit (here) I write another function but still there is problem with Sequence@@
.
Compile[{{l, _Integer}},
Module[{positions = {1, 2, 4}},
Table[KroneckerDelta[#1,
Sequence @@ Flatten@Position[list, #2]]*#2 &[x, y],
{x,positions}, {y, l}]
]
]
Or this:
f = Compile[{{r, _Integer, 2}},
Table[
Map[KroneckerDelta[p, Position[r, #][[1]]]*# &, r], {p, {2, 4}}]]
Compile
? If not, why not simply uset = list[[l]]
? $\endgroup$AppendTo
,Map
etc.? If the former, then how aboutf = Compile[{{l, _Integer, 1}}, Module[{list = {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}}}, list[[l]]]]; t = f[{1, 2, 1}]
? $\endgroup$