I've reported the issue
[https://github.com/nim-lang/Nim/issues/5630](https://github.com/nim-lang/Nim/issues/5630)
that is correct. yet
template foo(p: untyped): auto = (block:
1
)
let x = foo:
discard
won't compile, while this will
let x = (block:
1
)
in fact, this compiles as well:
template foo(p: untyped): auto
>From example, if you think that's returning something it's indeed returning
>exactly `not (a == b)` but not returning a `bool` value. It's only be `bool`
>after evaluated in runtime.
> Is it possible to return value from template which the last of argument is
> untyped?
pretty sure you can:
[https://nim-lang.org/docs/manual.html#templates](https://nim-lang.org/docs/manual.html#templates)
Is it possible to return value from template which the last of argument is
`untyped`?
If possible, maybe some example would be nice
I used template with last argument `untyped` for executing that argument (which
consists of statements) but never use so that it would return something.
Maybe you should use a proc instead.
By passing nil (ok, by setting the default to nil), you can get foo3() behaving
as follows
template foo(_: untyped): auto =
echo "foo"
1
template foo2(_: varargs[untyped]): auto =
echo "foo2"
block:
discard
2
template foo3(_:
Hmm, that's true. I don't know the reason but judging from error, it's said
wrong number of argument so need to change to `varargs` to accommodate zero
arity.
If it's like below, is it ok?
template foo(_: untyped): auto =
echo "foo"
1
template foo2(_:
if I understand correcly what you mean I'd expect it to compile with:
template foo(p: untyped): auto = (block:
1
)
but it won't
I think if you substitutes the template directly into the assignment, it would
be assigning a variable from multiple statements.
Hi, i'm trying to assign the result of a template, but apparently the compiler
gets confused unless I surround the template with (block: ...)
template foo(p: untyped): auto =
1
let x = (block:
foo:
discard)
let y =
11 matches
Mail list logo