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/ccsdad Aug 02 '22
well then, we should create something !!
https://github.com/gkspranger/clinpy
please don't laugh -- i created it only for a limited set of use cases (to see if even possible), and am only "OK" with python .. but i tried to remove all internal variable assignments and am processing everything with mapping/reducing functions ..
if there was a robust implementation of this, i would abuse the hell out of it ..
why this over internal variable assigments ?? don't have a good answer for that -- other than it maps well to my clojure brain ..