Here’s Mathematica’s Nest function Definition. What’s the eqv. in Ruby?
The idea is this:
nest(f, x, 3) #=> f(f(f(x)))
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could define your own using
inject:Then you could call it like this:
If you want a function back (i.e. leave
xunspecified) then you could return a lambda:and use it like this:
Or you could rearrange the
nestarguments and useProc#curry:You can also use
[]in place ofcallif want something that looks more like a function call: