3 ms·
Here's the equivalent (of some) in Python: def make_adder (how_much_to_add): return lambda initial_value: initial_value + how_much_to_add print map ( m
by 13ren 18y ago
Here's the equivalent (of some) in Python:
def make_adder (how_much_to_add):
return lambda initial_value: initial_value + how_much_to_add
print map ( make_adder(10), [1, 7, 3, 9] )
# [11, 17, 13, 19]
my_favorite_adder = make_adder(42)
print map ( my_favorite_adder, [1, 7, 3, 9] )
# [43, 49, 45, 51]
def make_modifier (operator, operand): # a bit more general than make_adder
return lambda (initial_value): operator(initial_value, operand)
print map ( make_modifier(pow, 3), [1, 7, 3, 9] )
# [1, 343, 27, 729]
note: The lisp syntax looks weird to me, but in converting this, I really noticed the convenience of lisp's (1). symbols (not needing quotes); and (2). lists (not needing commas). Interesting.