I stumbled over a problem when trying to define unary operators as macros.
The following example defines a macro which converts an identifier to a string:
import macros
macro M(s: untyped): string =
result = toStrLit(s)
echo M(foo)
Run
which gives "foo" as output.
But I can't define the macro as a unary operator. If I try the following
import macros
macro `@`(s: untyped): string =
result = toStrLit(s)
echo @foo
I get: undeclared identifier: 'foo'
Run
I wonder what's the reason for this? Is it because there is a system-defined
operator that gets priority? Is there a way around that?
I noticed that binary macros as operators do work, at least when the first
argument is not **untyped**.