Golf my iteration function Here is my ungolfed Ruby code for a function I want to try and golf:

Iter =-&gt; k {
    str = ""
    (0..k).map{|m| str += "-&gt; f#{m} {"}
    str += "f#{k}.times{f1 = f0[f1]};f1"
    (2..k).map{|m| str += "[f#{m}]"}
    eval(str + "}" * (k+1))
}


The best I can do to golf this is essentially shortening variable names, removing spaces, and rearranging the code to reduce the amount of loops:

I=-&gt;k{s="f#{k}.times{f1=f0[f1]};f1"
(2..k).map{|m|s+="[f#{m}]"}
(0..k).map{|m|s="-&gt;f#{k-m}{"+s+?}}
eval s}


Try it online!

This function can be compacted so that it avoids a lot of defining new functions. You can think of it like this:

$$\operatorname{Iter}(k;f_0,f_1,\dots,f_k)=f_0^{f_k}(f_1)(f_2)(f_3)\dots(f_k)$$

where

$$f^n(x)=\underbrace{f(f(\dots f(}_nx)\dots))$$

denotes function iteration. The types of arguments are given as:

$$\operatorname{Iter}(\text{int};\dots,(\text{int}\mapsto\text{int})\mapsto(\text{int}\mapsto\text{int}),\text{int}\mapsto\text{int},\text{int})$$

That is, the last argument is an integer, and each previous argument maps from T to T, where T is the type of the next argument on the right.

It is true that accepting all arguments at once would allow me to golf the above code further:

I=-&gt;k,*a{a[-1].times{a[1]=a[0][a[1]]};(2..k).map{|m|a[1]=a[1][a[m]]};a[1]}


However, the issue is that I need to curry this function. This way, I may treat objects such as

$$\operatorname{Iter}(k)(f_0)$$

as their own object, and thus be able to pass this into Iter(k) to get things such as

$$\operatorname{Iter}(k)(\operatorname{Iter}(k)(f_0))$$

As a specific example of what this function does, we have

\begin{align}\operatorname{Iter}(2)(\operatorname{Iter}(1))(x\mapsto x+1)(2)&amp;=\operatorname{Iter}(1)(\operatorname{Iter}(1)(x\mapsto x+1))(2)\\&amp;=\operatorname{Iter}(1)(x\mapsto x+1)(\operatorname{Iter}(1)(x\mapsto x+1)(2))\\&amp;=\operatorname{Iter}(1)(x\mapsto x+1)(2+1+1)\\&amp;=\operatorname{Iter}(1)(x\mapsto x+1)(4)\\&amp;=4+1+1+1+1\\&amp;=8\end{align}


  I'm interested in seeing if this can be golfed down further, with the restriction that the arguments must be curried in the order provided.
Ruby, 94 96 bytes

Using loops to do concatenations that followed such a simple pattern felt cumbersome, so I utilized the creative use of join instead, further golfed by the fact that array*str is equivalent to array.join(str)

+2 bytes to fix a typo I made that just so happened to return the same result on the test example by chance.



I=-&gt;k{eval"-&gt;f#{[*0..k]*'{-&gt;f'}{f#{k}.times{f1=f0[f1]};f1#{"[f#{[*2..k]*'][f'}]"if k&gt;1}"+?}*-~k}


Try it online!