Re:Matlab–Python–Julia Cheatsheet
by dnautics on Monday June 10, 2019 @01:54AM
(#20144219)
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
Re:Matlab–Python–Julia Cheatsheet
by pdexter on Monday June 10, 2019 @02:50AM
(#20144447)
Elixir 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"?
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.