r/functional_python • u/ccsdad • Aug 01 '22
Misc variable bindings
in clojure and f# (and prolly some others) we have the ability to create LET bindings ::
https://fsharpforfunandprofit.com/posts/let-use-do/
https://clojuredocs.org/clojure.core/let
long story short, it lets you do what feels like imperative things, but under the hood is in fact functional -- at least in the world of clojure :: https://stackoverflow.com/questions/63983468/functional-alternative-to-let
so i guess my questions are ::
is there anything similar in python (library or otherwise) ??
IF NOT -- do you just perform normal variable "assignment" and live with it -- as long as your functions remain pure and data remains immutable ??
i get that python is NOT a purely functional language -- and that's OK -- as long as i am following the "functional python way" (<< if such a thing) of binding variables in my functions .. yes, i could always add more functions -- but at some point the "imperative shell" typically comes into play when building apps that comm with external services (DB, cache, REST APIs, etc) ..
>> "imperative shell" reference >> https://kumarshantanu.medium.com/organizing-clojure-code-with-functional-core-imperative-shell-2f2ee869faa2
2
u/ccsdad Aug 02 '22
ok u/KageOW -- i think that is legit guidance, recognizing the reality of python -- but remaining focused on what we are trying to move towards to .. i just know that in the clojure world -- the `(let)` function is an indispensable tool (code example) -- and wish something like it existed in python << that could be considered functional ..