Hacker News new | ask | show | jobs
by inportb 4420 days ago
Why would zo1 want to read SICP? zo1 is clearly quite happy with Python's named functions, and has no immediate incentive to "read SICP and gain an appreciation for higher-order functions."
1 comments

I either assume that the parent poster was serious about the question or rhetorical. Given the apparent lack of knowledge, I assume the question was serious. If the question was serious, does it not deserve a serious response?

Faced with squeezing an explanation into a limited post or recommending one of the best books on computer science (written by teachers with many years experience in teaching these self-same principles), should I not recommend the book that will allow the poster to expand his/her horizons?

The poster was sufficiently motivated to ask the question. I was willing to post what I believed at the time to be the best answer to the question. If the poster's desire to know is sufficient, then he/she will take the time to explore the suggestion. If not, then things will stay as they are. In either case, my only interaction is my choice to share a suggestion or remain silent.

Indeed, you are right. I was quite curious about them, and I wanted to know if there was something I was missing. Some reasoning that I knew not of, and that others did.

However, I'm about halfway through the chapter on "Higher order procedures" in the book you linked to, and have skimmed the rest of that chapter. And I've yet to find a valid pro for anonymous methods. Nothing I've found so far as to the benefit of using anonymous functions.

It does however, continuously reiterate the benefit of being able to pass "procedures as arguments" and to be able to return them from normal functions. So far, that's been the only "pro" and it's one that's solved by function pointers or having functions as objects, and not by anonymous methods. I'm still open for convincing, genuinely.

Here's another jewel from that chapter: "The resulting procedure is just as much a procedure as one that is created using define. The only difference is that it has not been associated with any name in the environment."

On a side note, your initial post was a tad condescending. The other post at least gave me the relevant chapter, instead of saying "here, read this for yourself". The least you could have done was give me a few short points why you think anonymous methods are superior in some way. Perhaps pointing me to a large blob of text was your way of deferring your own justifications for their use by not having to explain it to me (and as a consequence, yourself)?

My apologies. I was somewhat sleep deprived at the time and it sounded a lot better in my head.

SICP's point with higher-order functions is that code is data and that functions are no different than numbers or lists or whatever. In the function below, I've named everything.

  def add4Mul2(x):
    z = 4
    y = 2
    return (x + y) * z

  lst = [1,2,3,4]
  x = map(add4Mul2, lst)
the short version without any variable names.

  x = map(lambda x: (x+2)*4, [1,2,3,4])
I don't name the function for the same reason that I don't name the 2, the 4 or the array -- I don't need to because I use them one time. If I were using (x+2)*4 all the time, then I'd give it a name, but since I only use it once, it's less of a problem to treat the function like any other constant data -- use the data without assigning it to a variable first.