Treat memory allocation as effect?

2021-11-11 Thread elcritch
Would it be possible to treat allocation memory as an effect in Nim? Much like IO operations, there are contexts where being able to assert "no allocation" would be powerful. I haven't noticed any "allocation effect" tags in the standard library. Is is just a matter of annotating the effects or

How do I inject a NimNode directly instead of going through a macro or template?

2021-11-11 Thread ynfle
I think this is what you want import macros proc helloNode():NimNode {.compileTime.} = newLit("hello") macro hello(x: static proc(): NimNode):untyped = let node = x() result = quote do: `node` ec

How do I inject a NimNode directly instead of going through a macro or template?

2021-11-11 Thread Hlaaftana
Worst case, you can do this: import macros template useNode(n: NimNode): untyped {.dirty.} = macro temp(): untyped {.gensym.} = result = n temp() echo useNode(newLit("hello")) Run Don't know if `dirty` and `gensym` help but I includ

dot-like operations and calls

2021-11-11 Thread Hlaaftana
Given that the distinction for "dot-like operators" are made, would it make sense for `a.?b(c)` to transform into: Infix Ident ".?" Ident "a" Ident "b" Ident "c" Run or maybe a new `DotLike` node kind instead of Infix? Or just transform `Call`

How do I inject a NimNode directly instead of going through a macro or template?

2021-11-11 Thread doofenstein
does a typed/untyped parameter do what you want to do? macro x(val: untyped): untyped = val echo x("hallo") # generates the ast echo "hallo" Run Note that while the type of the parameter is written as untyped/typed it's actually of type NimNode. The dif

How do I inject a NimNode directly instead of going through a macro or template?

2021-11-11 Thread deech
I would like echo splice(helloNode()) Run to not be in a `static` context, I'd like it to be the same as if I just typed: echo "hello" Run

How do I inject a NimNode directly instead of going through a macro or template?

2021-11-11 Thread enthus1ast
i do not fully understand what you try to archive, but this compiles for me: import macros proc helloNode(): NimNode {.compileTime.} = newLit("hello") macro hello():untyped = helloNode() static: echo hello() macro splice(n: NimNode

How do I inject a NimNode directly instead of going through a macro or template?

2021-11-11 Thread deech
Currently compile time `proc` s the build up `NimNode` s are usually called in template or macro, eg: import macros proc helloNode():NimNode {.compileTime.} = newLit("hello") macro hello():untyped = helloNode() echo hello() Run I

when will nimble be ready for new/nightly nim?

2021-11-11 Thread oyster
in short word, when will `nimble` be ready for new/nightly `nim` Yes, I have read the issues of `nimble` which said that old `nimble` should be used, but till when? TLDR; # 1\. build from source I often build `nim` ( and thus `nimble` from latest `nim` source code), however the `nimble` does

dot-like operations and calls

2021-11-11 Thread markspanbroek
Thanks, I can do that. In previous versions I actually called the operator `?.`, but I moved away from it because of its low precedence. It does mean that users of the library will need to use extra parentheses in some places. For example, expressions such as `if a =? b.?c:` would become `if a=?

dot-like operations and calls

2021-11-11 Thread Araq
The best option seems to be to rename the operator to `?.`, sorry.

dot-like operations and calls

2021-11-11 Thread markspanbroek
I tried this, but ran into two problems: 1. I don't know how many arguments `foo` has, because I no longer see the call in the macro, only the identifier of the proc. 2. I'm not able to differentiate between a function call `option.?foo()` or a field access `option.?foo`, so I don't know whe

dot-like operations and calls

2021-11-11 Thread PMunch
Haven't tested this, but writing a `macro` with the name `.?` which returns a closure that takes the same arguments as `foo` but does the option branching first should work.

dot-like operations and calls

2021-11-11 Thread markspanbroek
I'm struggling with the new dot-like operators in Nim 1.6. I wrote a library called [questionable](https://github.com/status-im/questionable) that makes heavy use of the `.?` operator. You can for instance call a function on an optional value like this: option.?foo(bar)