3 ms·
Have been using easy decorator memoization in python for at least a decade. This is not new and far from impossible to do using probably even older versions of
by zo1 4y ago
Have been using easy decorator memoization in python for at least a decade. This is not new and far from impossible to do using probably even older versions of python. I implemented it in 2.5 IIRC.
- zasdffaa 4y agoI was responding to "was more first class in popular languages". I know about python's functools lib and its memoisation decorator. Point was, if you didn't have it and wanted it, it's easy; no need for the language to provide it.
- robertlagrant 4y agoDon't let this guy see math.tau.
- zasdffaa 4y agoThis guy sees your point and this guy does indeed wonder why it's there when 2*Pi will do. But if it's about python the answer is simple - unlike many other languages python does fold constants, but does't fold expressions using variables even if the variable is never changed so there's an unavoidable cost unless you write out the value literally, or have it as a constant. Or - in PEP 628 - it's just a bit of a larf https://peps.python.org/pep-0628/ https://peps.python.org/pep-0628/ Perhaps this guy should grow a sense of humour.
- robertlagrant 4y ago> Perhaps this guy should grow a sense of humour. Agreed!
- merlincorey 4y agoIt's a built-in decorator now called `functools.cache`[0]. [0] https://docs.python.org/3/library/functools.html#functools.cache https://docs.python.org/3/library/functools.html#functools.c...