Pseudo-currying in one line
EDIT: Modified to cover situation when an argument is a List
Use Fold
expr = c[a1, a2, a3, a4, a5];
Fold[#1[#2] &, {c, List @@ expr} // Flatten[#, 1]&]
(* c[a1][a2][a3][a4][a5] *)
expr2 = c[a1, a2, {a31, a32, a33}, a4, a5];
Fold[#1[#2] &, {c, List @@ expr2} // Flatten[#, 1] &]
(* c[a1][a2][{a31, a32, a33}][a4][a5] *)
The deprecated (but valid) function HeadCompose
basically does just that:
c[a1, a2, a3, a4, a5] /. h_[a___] :> HeadCompose[h, a]
c[a1][a2][a3][a4][a5]
If you don't wish to use that then perhaps one of these:
f1 = FixedPoint[Replace[h_[x_, y__] :> h[x][y]], #] &;
f2 = # //. {x : _[_] :> x, h_[x_, y__] :> h[x][y]} &;
f3 @ h_[x___, y_] := f3[h[x]][y]
f3 @ h_[] := h
e.g.
c[a1, a2, a3, a4, a5] // f1
c[a1][a2][a3][a4][a5]
Also possible (any maybe more readable) using patterns and ReplaceRepeated
c[a1, a2, a3, a4, a5] //. f_[most__, last_] :> f[most][last]
c[a1][a2][a3][a4][a5]
As indicated by @MB1965 in a comment ReplaceRepeated
is greedily searching for any part of the expression that matches f_[most__, last_]
so that
c[a1 + a2, a3 + a4, a5] //. f_[most__, last_] :> f[most][last]
yields
c[a1[a2]][a3[a4]][a5]
Restricting the pattern to c[most__, last_]
instead of f_[most__, last_]
remedies that
pseudocurry[expr_] := expr //. Head[expr][most__, last_] :> Head[expr][most][last]
c[a1 + a2, a3 + a4, a5] // pseudocurry
c[a1 + a2][a3 + a4][a5]