Compile-time calculation: Difference between revisions
Content added Content deleted
(added Julia example) |
(Added zkl) |
||
Line 795: | Line 795: | ||
RET |
RET |
||
</pre> |
</pre> |
||
=={{header|zkl}}== |
|||
zkl has two ways to do compile time calculations: a variant of C's macros and "parse time" calculations (since the compiler is written in zkl, the parser just recurses). |
|||
File foo.zkl: |
|||
<lang zkl>const { [1..10].reduce('*).println(" parse time") } |
|||
#fcn fact(N) { [1..N].reduce('*).println(" tokenize time"); ""} |
|||
// paste output of fact into source |
|||
#tokenize fact(10) |
|||
println("compiled program running.");</lang> |
|||
Run the program: zkl foo: |
|||
{{out}} |
|||
<pre> |
|||
3628800 tokenize time |
|||
3628800 parse time |
|||
compiled program running. |
|||
</pre> |
|||
Tokenize time can paste text into the source, parse time can inject a limited set of objects into the parse tree (and is used for things like __DATE__, __FILE__ constants). |
|||
{{omit from|AutoHotkey|AutoHotkey is an interpreted language - the 'compiler' (separate from the interpreter) just bundles the interpreter and the code inside an EXE, so this sort of thing isn't possible}} |
{{omit from|AutoHotkey|AutoHotkey is an interpreted language - the 'compiler' (separate from the interpreter) just bundles the interpreter and the code inside an EXE, so this sort of thing isn't possible}} |