3 ms·
In Elm pure functions may allocate memory. How does D handle this?
by millstone 6y ago
In Elm pure functions may allocate memory. How does D handle this?
- mhh__ 6y agoD pure functions can always allocate memory via the GC. If you don't want to use the GC it is customary to use a pure wrapper around malloc (even though you theoretically shouldn't, it works fine in practice). https://dlang.org/library/core/memory/pure_malloc.html https://dlang.org/library/core/memory/pure_malloc.html https://run.dlang.io/is/xB0Qeu https://run.dlang.io/is/xB0Qeu this RPN calculator (the one I wrote for the dlang.org page but ungolfed) is pure and checked as such by the compiler. It's also referentially transparent because "in" means the input parameter is constant and can't escape (and thread local fyi).