4 ms·
Python doesn't even have closures. The usual reason people give for believing this is the inability to mutate closed-over variables. If that's the case, then
by ubernostrum 11y ago
Python doesn't even have closures.
The usual reason people give for believing this is the inability to mutate closed-over variables.
If that's the case, then a strictly-immutable FP language similarly "wouldn't have closures" and thus could not be FP. Problem solved!
- pcote 11y agoYou can mutate closed-over variables in Python. Here's an example.... def some_function(val): def say_stuff(): print("message is: {}".format(val)) def mutate_me(new_mutation): nonlocal val val = new_mutation say_stuff.mutate_me = mutate_me return say_stuff if __name__ == '__main__': f = some_function("hello") f.mutate_me("goodbye") f()