3 ms·
It's not categorically how closures work, it's just that in python (and most other languages, including julia), you bind to effectively "a pointer to the value"
by dnautics 7y ago
It's not categorically how closures work, it's just that in python (and most other languages, including julia), you bind to effectively "a pointer to the value". In FP paradigm, you typically bind to "the value at function creation time".
In many cases, the "FP paradigm" is very sensible and makes closures safe to work with and easy to reason about, especially in contexts where concurrently running processes could alter the memory underneath you.
iex(1)> a = 1
1
iex(2)> f = fn x -> x + a end
#Function<7.91303403/1 in :erl_eval.expr/5>
iex(3)> f.(1)
2
iex(4)> a = 2
2
iex(5)> f.(1)
2
- pdexter 7y agoElixir doesn't have mutable variables though. Is there any language that has mutable variables and closes over the value of a variable and not a "pointer to the value"?