{at-both-times
{define fact
[|n| (if (= n 0)
[1]
[(* n (fact (- n 1)))])]}}
(pp {at-compile-time-expand (fact 3)})
(pp (fact 3))
https://github.com/billsix/bugShow HN: C++ runtime/compile-time detection in constexpr functions
11–20 of 22 posts
In my libbug library, computation at Compile-Time uses the exact same language as the run-time
Re: Show HN: C++ runtime/compile-time detection in constexpr functions
#12Typo detected :)
"An approach for runtime dection inside a constexpr function"
Re: Show HN: C++ runtime/compile-time detection in constexpr functions
#13Typo detected :) "An approach for runtime dection inside a constexpr function" https://github.com/SaadAhmad/in_constexpr
Thanks!
Re: Show HN: C++ runtime/compile-time detection in constexpr functions
#14As with most things in C++ that looks horribly convoluted for some very simple functionality.
In D all we have to do is:
* `if ( __ctfe) { ... }` for compile time
* `if (!__ctfe) { ... }` for runtime
Re: Show HN: C++ runtime/compile-time detection in constexpr functions
#15As with most things in C++ that looks horribly convoluted for some very simple functionality. In D all we have to do is: * `if ( __ctfe) { ... }` for compile time * `if (!__ctfe) { ... }` for runtime
I don't think it's any secret D does CTFE better than any other language.
Re: Show HN: C++ runtime/compile-time detection in constexpr functions
#16As with most things in C++ that looks horribly convoluted for some very simple functionality. In D all we have to do is: * `if ( __ctfe) { ... }` for compile time * `if (!__ctfe) { ... }` for runtime
I don't think it's any secret D does CTFE better than any other language.
Better than Common Lisp?
Re: Show HN: C++ runtime/compile-time detection in constexpr functions
#17Another reason why we should not be using c++...
Re: Show HN: C++ runtime/compile-time detection in constexpr functions
#18Re: Show HN: C++ runtime/compile-time detection in constexpr functions
#19Why to mlock() the page? And since the code is already specific to linux/gcc/clang, why not to assign the flag to a read-write section (__attribute__((section(name))) -- should allow to get rid of mprotect()?