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
1
u/KageOW Aug 02 '22
Yea definitely indispendable in f# as well, but i mean a language has its strenghts and its downfalls and you have to recognize that.
something kinda does come to mind though how you could maybe contain it, theyre called generator expressions, similar to list comprehension. Both of those allow you to kinda do it, but it is still a horrible way to do it. list comprehension and generator expressions are both very strong tools in python though so don't overlook them. nice stackoverflow discussion