Re: block expression

2018-01-31 Thread bluenote
There should be no need for such a template, this must be a regression. Since [this PR](https://github.com/nim-lang/Nim/pull/6695/files) blocks should be an expression (see [corresponding issue](https://github.com/nim-lang/Nim/issues/3827)). There is also a test case. However the test case

Re: block expression

2018-01-29 Thread woggioni
@Udiknedormin Thanks, you code works! Actually I was using this: template scope(body : typed) : auto = (block: body) but I guess ther is something I miss about the semantics of typed because this code template scope(body : typed) : auto = (block: body) let

Re: block expression

2018-01-29 Thread Udiknedormin
Well... the template is the right thing to do but without closure magic --- just use a block: template scope(code): auto = block: code let a = scope: echo "hello" 1 echo a

Re: block expression

2018-01-27 Thread woggioni
@Hlaaftana Yes, I'd just like to omit parenthesis without losing the scope semantics

Re: block expression

2018-01-27 Thread Hlaaftana
Moral of the story, this works: let a = (block: echo "hello" 1)

Re: block expression

2018-01-27 Thread jcosborn
Here's a related thread: [https://forum.nim-lang.org/t/2201](https://forum.nim-lang.org/t/2201)

Re: block expression

2018-01-27 Thread woggioni
I also noticed another problem let a = (proc() : auto = let b = 4 6 )() echo b this clearly does not compiles since d is accessed from an outer scope. This one should be the equivalent written with templates: template bxpr(body : typed)

Re: block expression

2018-01-27 Thread woggioni
I'll answer my own question.. It seems that I just forgot to specify the template return type: template scope(body : typed) : auto = (proc() : auto = body) () let a = scope: echo "hello" 1 this works fine. There are some things that are not very clear

block expression

2018-01-27 Thread woggioni
It would be really nice to be able to write something like this let a = block: echo "hello" 1 but this does not compile because block is a statement a trivial workaround is let a = (proc() : auto = echo "hello" 1 )()

Re: cannot assign result of a template with block argument unless surrounded by a block expression

2017-03-30 Thread evacchi
I've reported the issue [https://github.com/nim-lang/Nim/issues/5630](https://github.com/nim-lang/Nim/issues/5630)

Re: cannot assign result of a template with block argument unless surrounded by a block expression

2017-03-28 Thread evacchi
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

Re: cannot assign result of a template with block argument unless surrounded by a block expression

2017-03-28 Thread mashingan
>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.

Re: cannot assign result of a template with block argument unless surrounded by a block expression

2017-03-27 Thread evacchi
> 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)

Re: cannot assign result of a template with block argument unless surrounded by a block expression

2017-03-25 Thread mashingan
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.

Re: cannot assign result of a template with block argument unless surrounded by a block expression

2017-03-24 Thread planhths
Maybe you should use a proc instead.

Re: cannot assign result of a template with block argument unless surrounded by a block expression

2017-03-24 Thread jlp765
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(_:

Re: cannot assign result of a template with block argument unless surrounded by a block expression

2017-03-24 Thread mashingan
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(_:

Re: cannot assign result of a template with block argument unless surrounded by a block expression

2017-03-24 Thread evacchi
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

Re: cannot assign result of a template with block argument unless surrounded by a block expression

2017-03-24 Thread mashingan
I think if you substitutes the template directly into the assignment, it would be assigning a variable from multiple statements.

cannot assign result of a template with block argument unless surrounded by a block expression

2017-03-24 Thread evacchi
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 =