Difference between functool’s cache and lru_cache

functools.cache was newly added in version 3.9. The documentation states: Simple lightweight unbounded function cache. Sometimes called “memoize”. Returns the same as lru_cache(maxsize=None), creating a thin wrapper around a dictionary lookup for the function arguments. Because it never needs to evict old values, this is smaller and faster than lru_cache() with a size limit. Example … Read more

Is (pure) functional programming antagonistic with “algorithm classics”?

With respect to data structures, Chris Okasaki has done substantial research into adopting classic data structures into a purely functional setting, as many of the standard data structures no longer work when using destructive updates. His book “Purely Functional Data Structures” shows how some structures, like binomial heaps and red/black trees, can be implemented quite … Read more

Examples where compiler-optimized functional code performs better than imperative code

There are cases where the same algorithm will optimize better in a pure context. Specifically, stream fusion allows an algorithm that consists of a sequence of loops that may be of widely varying form: maps, filters, folds, unfolds, to be composed into a single loop. The equivalent optimization in a conventional imperative setting, with mutable … Read more

When choosing a functional programming language for use with LLVM, what are the trade-offs?

Either OCaml or Haskell would be a good choice. Why not check out the LLVM tutorials for each language? The LLVM tutorial for OCaml is here: http://llvm.org/docs/tutorial/OCamlLangImpl1.html Haskell has more momentum these days, but there are plenty of good parsing libraries for OCaml as well including the PEG parser generator Aurochs, Menhir, and the GLR … Read more

How is a functional programming-based JavaScript app laid out?

You should read this question: Javascript as a functional language There are lots of useful links, including: Use functional programming techniques to write elegant JavaScript The Little JavaScripter Higher-Order JavaScript Eloquent JavaScript, Chapter 6: Functional Programming Now, for my opinion. A lot of people misunderstand JavaScript, possibly because its syntax looks like most other programming … Read more

whats the difference between function foo(){} and foo = function(){}? [duplicate]

No, they’re not the same, although they do both result in a function you can call via the symbol foo. One is a function declaration, the other is a function expression. They are evaluated at different times, have different effects on the scope in which they’re defined, and are legal in different places. Quoting my … Read more

recursive descent parser and functional programming

Answer derived from this blog article: So my question is what would a more traditional functional approach to parsing (i.e. few side effects) look like? Sounds like you need to separate functional (as in Lisp, Scheme, Standard ML, CAML, OCaml, F#) from purity (absence of side effects, as in Haskell) and incidental language features (algebraic … Read more