Re: How to count varargs[untyped] inside of template?

2018-04-02 Thread mratsim
At the very least, you can dispatch with macros at compile time. Not sure about the template issue. macro tmpl*(args: varargs[untyped]): untyped = if args.len > 0: result = quote do: foo else: result = quote do: bar

NimShooter

2018-04-02 Thread erasmo85
Hi everyone, I recently released a mini game derived from the work of ImpBox (Nico Framework, [https://impbox.itch.io)](https://impbox.itch.io\)), you can check it here [https://badchosenname.itch.io/nimshooter](https://badchosenname.itch.io/nimshooter) Basically it's a space vertical shooter

How to count varargs[untyped] inside of template?

2018-04-02 Thread r3d9u11
Hi. I have a template with vararg[untyped] parameters, can I get count of parameters and realize branching like a: template tmpl*(args: varargs[untyped]): untyped = when args.len > 0: # here is compilation will be excepted #... else: #... Thanks.

Re: How to rewrite this in Nim style?

2018-04-02 Thread Krux02
you should be able to just remove the ref in Token = ref object. That is one layer of indirection less, and therefore faster and less memory consumption. And a little comment on what you are doing. Tokens are not nested. What you are doing is already parsing. In brainfuck all tokens are

Re: Nim in Action errata

2018-04-02 Thread dom96
Sure, report them as well. I will put them in the errata but under a special section.

Nim in Action errata

2018-04-02 Thread dom96
Hello guys, So my publisher is asking me to update my errata list. Some of you have already reported errata here: [https://forums.manning.com/posts/list/41366.page](https://forums.manning.com/posts/list/41366.page) (which is the de-facto place for errata in Nim in Action). Before I compile an

Re: How to rewrite this in Nim style?

2018-04-02 Thread mashingan
I don't know if this is Nim's style or not, but your version somewhat more efficient type TokenKind = enum tokenNested, tokenSingle Token = ref object case kind: TokenKind of tokenNested: tokens: seq[Token] of tokenSingle:

Re: Protocol Buffer library for Nim

2018-04-02 Thread oswjk
These libraries have diverged a bit now. My library doesn't do compile time code generation any more. The protoc plugin has been made to generate all the necessary code. PMunch's library doesn't need any external tools for parsing the protobuf syntax as it does all of it at compile time. As a

Re: How to get string representation of int inside of the macros?

2018-04-02 Thread Arrrrrrrrr
repr works better than $ in macros.

Re: how to get unmodified / uninterpreted source code/AST of expression in macro?

2018-04-02 Thread mashingan
Perhaps this is what you want, dump [https://nim-lang.org/docs/future.html#dump.m,typed](https://nim-lang.org/docs/future.html#dump.m,typed)

how to get unmodified / uninterpreted source code/AST of expression in macro?

2018-04-02 Thread timothee
Is there a way to get unmodified / uninterpreted source code (as either string or AST) of an expression in a macro? motivation 1: to allow writing logging functions that show exact expression on left hand side, eg: mylog(1+1) # prints 1+1=2 motivation 2: to allow writing smart assert function

Re: How to get string representation of int inside of the macros?

2018-04-02 Thread r3d9u11
cool, thanks for another solution!

Re: Why macros can't find a local module?

2018-04-02 Thread r3d9u11
many thanks!

Re: How to get string representation of int inside of the macros?

2018-04-02 Thread jangko
or you can use intVal, strVal, etc on literal nodes import macros macro initNui(a:int): typed = result = parseStmt("const b=" & $a.intVal) initNui(1)

Re: Why macros can't find a local module?

2018-04-02 Thread GULPF
This looks like a bug with `parseStmt`. I think the module resolution is done relative to `macros.nim` instead of relative to the module which called `parseStmt`. Here is a version that works and doesn't hard code the module name: import macros macro loadModule(module: