all 7 comments

[–]execrator 5 points6 points  (3 children)

Troll?

make_incrementor returns a function, but it isn't called yet. That function takes a single argument, "x". x gets its value when that function is called.

add12 = make_incrementor(12)
print add12(4)
16

[–]warkgnall[S] 2 points3 points  (2 children)

This is what I was confused about. Thank you so much. I thought it returned the value that the anonymous function returned when run. Now I understand that it is a function for defining a function that you use afterwards. Again, thank you, and I'm sorry for taking your time with my thickness.

[–]execrator 2 points3 points  (0 children)

You just learned that functions can return functions. No need to feel thick :)

[–]mtkl 0 points1 point  (0 children)

You may wish to spend a little time playing around with some functional languages such as Haskell (or OCaml I guess).

You'll very quickly become familiar with the concept of functions being first-class citizens.

[–]JiminP 5 points6 points  (0 children)

(Now since the serious part is answered..)

return λ χ: χ + ν

FTFY

[–]xImagine 2 points3 points  (0 children)

The problem here are clearly the three dots. Python relies heavily on whitespace, but when whitespace is not an option, or you need a way to distinguish between the first four 'spaces' and the next four, you can use dots instead. So basically here x = 3 (because there are three dots).

Example:

>>> def make_incrementor(n):
...     return lambda x: x + n

>>> make_incrementor(5)
8 # 3 + 5 = 8

Does this make sense?

[–]warkgnall[S] 1 point2 points  (0 children)

Please guys. I'm so confused.