I posed this question as an aside in this thread and nobody answered; @dom96 was also wondering.
Why do macros often use the construct quote do:, when quote: alone seems to work just fine?
This works:
import macros
macro m(x: untyped) =
result = newStmtList()
result.add quote do:
echo `x`
m:
"hi"
And this doesn't:
import macros
macro m(x: untyped) =
result = newStmtList()
result.add quote:
echo `x`
m:
"hi"
Thanks for posting this question and thanks for the answer.
I must say, I am surprised that this minor syntax difference is the reason why quote is used with a do so much. I wish we'd gone with:
import macros
macro m(x: untyped) =
result = newStmtList()
result.add(
quote: echo `x`
)
m:
"hi"
And been done with it. In fact, why doesn't this work?