andreaferretti / memo

Memoization for Nim
78 stars 10 forks source link

CompileTime Use? #3

Open JorySchossau opened 5 years ago

JorySchossau commented 5 years ago

I can't quite figure out why the memoized macro causes problems for {.compileTime.} usage. Macros, in general, seem to work okay during compiletime in nim, and making a manual memoizing compiletime cache also seems to work, so I'm not sure what the issue is. Thoughts?

andreaferretti commented 5 years ago

I am not sure about this, but is there any chance you could use the memoize function at compile time? It only works for non-recursive functions, but it could help anyway, depending on the use case

JorySchossau commented 5 years ago

Good idea, but unfortunately I need recursion. I will be presenting nim to a group of people who love the auto compile time memoization c++ offers on the Fibonacci example using constexpr, and I was hoping to show an easy equivalent in nim. I am learning more about nim AST & macros so will take a crack at making a PR to add compiletime functionality for memo.

JorySchossau commented 5 years ago

Here's where I'm at on this, with a couple possible ways to implement it: https://forum.nim-lang.org/t/4721