From: William James Date: 2006-12-28T11:40:09+09:00 Subject: Re: Higher-Order Procedures Tutorial (long) Nate Murray wrote: > Hey Guys, > I've been going through the video lectures "Structure and > Interpretation of Computer Programs by Hal Abelson and Gerald Jay > Sussman. " ( > http://swiss.csail.mit.edu/classes/6.001/abelson-sussman-lectures/ ). > The section on Higher-Order Procedures was a huge eye-opener for me and > I wanted to condense down what I learned in Lisp to guys who program in > Ruby. Now I know that for most of the experienced on this list this > will be old-news, but I hope to provide a valuable tutorial of Abelson > and Sussman's material to some guys who are just learning about this > stuff in Ruby. > > Posted below is the straight text and code examples of what I have so > far. ( I've also posted the pdf of slides here: > http://tech.natemurray.com/2006/12/higher-order-procedures-in-ruby.html > if you're interested. ) Now, I am not just trying to drive up traffic > to my site. My purpose in posting this here is two-fold: > > 1) To submit it for peer review. I'd like to know if you guys have any > suggestions or improvements on the code examples and/or copy. For > example a part that seems particularly ugly to me is the > > cube = self.method(:cube).to_proc > cube.call(3) > > part. Any suggestions on how to make this a little more transparent or > simplified? def cube n n * n * n end def inc(n) n + 1 end def sum(term, a, the_next, b) return 0 if a > b send(term,a) + sum(term, send(the_next,a), the_next, b) end p sum( :cube, 1, :inc, 3 )