Is there a simple function that will take expressions of the form
f[a1][a2][a3]
and will output f
, for an arbitrary number of arguments a1
, a2
, a3, etc (also possibly zero).
Also, is there a simple function to rearrange the input to f[a1, a2, a3]
(which of course would immediately solve the first question too).
My own attempt for the first problem:
takeHead[expr_] := FixedPointList[Head, expr][[-3]]
which seems to work but I don't know whether it is robust for all cases. (We can optionally add a HoldAll
depending of whether we want to take the head before or after evaluation.)