Hidden treasure in the D standard library
nomad.so
nomad.so
2. The store is a hashtable.
3. Multiple arguments are grouped in a tuple - no major complication.
4. Where memoization doesn't make sense you'll get a compile-time error because e.g. comparison for equality is't defined. At least most of the time :o).
5. The memory is thread-local.
6. memoize takes the name of the memoized argument and creates a distinct type for each memoized function.
TL;DR: business as usual
Wow, so if you compare aHash == anotherHash, it doesn't just compare the references, it actually examines both hashes for content equivalence? That's fairly unconventional, but probably convenient sometimes.
memoize is a template (http://dlang.org/template.html). In this case, a template is used to create a "version" of "memoize" with the right parameters and return value (i.e., `fn` and `memoize!fn` are the same type).
Each of these "versions" has a hash table from argument tuples to results. I believe the hash is computed by calling a toHash function for each item in the tuple.
Tuples and type tuples (http://dlang.org/tuple.html) in D are really quite powerful.
I assume D has enough magic to pattern match on the traits of the types in the argument list?
If that's not the case, then I don't understand either.
1: https://github.com/D-Programming-Language/phobos/blob/master...
It allows the program to have recursive algorithms with the performance of optimized for loops.
When I looked at the output of the hash function in Python for integers a few weeks ago it looked like the identity function was being used. You'll still have greater complexity than an array, but I'm not sure how much greater.
It does allow some recursive algorithms to reduce their algorithmic complexity significantly, however.