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
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
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.
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
Sure, report them as well. I will put them in the errata but under a special
section.
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
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:
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
repr works better than $ in macros.
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)
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
cool, thanks for another solution!
many thanks!
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)
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:
15 matches
Mail list logo