4 ms·
The Nim macro system also has quasi-quotes (whose heritage ultimately goes back to Lisp, I believe, though Quine 1940 probably deserves the ultimate "credit" [1
by cb321 2y ago
The Nim macro system also has quasi-quotes (whose heritage ultimately goes back to Lisp, I believe, though Quine 1940 probably deserves the ultimate "credit" [1]). E.g.:
import std/macros
macro check(ex: untyped) =
let info = ex.lineInfo
let exStr = ex.toStrLit
result = quote do:
if not `ex`:
echo `info` & ": Check failed: " & `exStr`
check 1 == 2
and then saved in `/tmp/j.nim` and run via `nim r /tmp/j` gives
Hint: mm: arc; opt: none (DEBUG BUILD, `-d:release` generates faster code)
17090 lines; 0.191s; 24.699MiB peakmem; proj: /tmp/j; out: /u/cb/.cache/nim/j_d/j_56B19E2DE1BC31D8D53BA27494BE816EB824A493 [SuccessX]
Hint: /u/cb/.cache/nim/j_d/j_56B19E2DE1BC31D8D53BA27494BE816EB824A493 [Exec]
/tmp/j.nim(8, 8): Check failed: 1 == 2
[1] https://en.wikipedia.org/wiki/Quasi-quotation https://en.wikipedia.org/wiki/Quasi-quotation