Is it possible to construct a pure function using multiple slots, with the following concept :
Binding specific slot to specific apply or map
For example :
In this example,
To reproduce the output for In(1), namely Out(1),
In[1] Table[Take[#, n], {n, 1, Length[#]}] & /@ test
Out[1] {{{4}, {4, 2}, {4, 2, 2}}, {{9}, {9, 1}, {9, 1, 5}},
{{5}, {5, 2}, {5, 2, 9}, {5, 2, 9, 3}},
{{5}, {5, 2}, {5, 2, 7}, {5, 2, 7, 1}, {5, 2, 7, 1, 1}}}
without using 'Table' symbol, I could do
In[2] Function[x, (Function[y, Take[x, y]] /@ Range[Length[x]])] /@ test
But I want to reproduce Out(1), only with slot symbols and Map.
The codes
((Take[#1, #2] &) /@ Range[Length[#1]]) & /@ test
or
((Take[#, #] &) /@ Range[Length[#]]) & /@ test
are tryable but they fails.
My imaginary working colored code is like :
Violet # binds to violet & and violet /@,
Green # binds to green & and green /@
Function[x, Take[x, #] & /@ Range[Length[x]]] /@ test
$\endgroup$FoldList[Append, {First@#}, Rest@#] & /@ test
or i f you are a fan of cryptic code:(t = #; Take[t, #] & /@ Range[Length[#]]) & /@ test
$\endgroup$&
with#
is simply shorthand forFunction
with a parameter, so theFunction
solution is actually how you would bind a slot (in this case, namedx
) in an anonymous function properly. $\endgroup$Slot
to aFunction
constructor&
outside another constructor&
("outside" being defined by syntactic precedence). As far as I know, at least. This came up before, but as I recall, it was not the central question, just the explanation of the problem with the OP's code. $\endgroup$Slot[]
binds to the firstFunction
going up the expression tree to the head. To visualize your last example:(Take[#1, #1] &) /@ Range[Length[#1]] & // TreeForm
The firstSlot[1]
inTake[..]
won't bind to the topmostFunction
as desired. You would need a way to label the slots and the function, but such a way is already provided by symbolic arguments. $\endgroup$