Hacker News new | past | comments | ask | show | jobs | submit login

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.



Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: