Recently I found out about CTFE and started reading all about it.
I am very pleased to discover that Nim is currently the #1 language on this topic!
Dlang is catching up; they are developing a new bytecode VM for CTFE just like Nim has for years now (vmdef.nim).
Recently attempts to provide the missing FFI support begun!
What are all the features that Nim could eventually that you can think of?
I know this is not top priority stuff, but it would be nice to concentrate all the CT pending features in one place (maybe github RFC issue).
To be honest, besides compile-time FFI so that you can const Foo {.importc.} which is coming, I find Nim CTFE pretty much feature complete.
My only grip with it is the difficulty to work with generic types in macros.
Closures (iterators and proc) are dynamically allocated at run-time with an address on the heap. At compile-time this is unknown and would differ depending on Linux, Windows, Mac. If you have enough info to construct your closure at compile-time, use a macro or template to generate an inline iterator or normal proc instead.
Methods are used for dispatching on run-time types, if your run-time type is already known at compile-time, you can use a normal proc instead of a method.
Of course other constructs can be used instead, but with this logic you could also use a different program just to calculate what is known before (main program's) runtime, and then somehow pipe the results into your program.
The whole point of metaprogramming is flexibility. Using closure iterators and dynamic dispatching idioms and still getting CTE would be awesome, and it's certainly doable! The VM is a runtime so there is no restriction; it can emulate the runtime phase and resolve dynamic behavior.
The whole point of metaprogramming is flexibility. Using closure iterators and dynamic dispatching idioms and still getting CTE would be awesome, and it's certainly doable!
All true.