dot-like operations and calls

2021-11-17 Thread markspanbroek
Interesting, I didn't see the [RFC](https://github.com/nim-lang/RFCs/issues/341) before. The `.?()` operator would indeed solve my problem. By the way: I tried the workaround with the `()` operator, but I ran into the problem that I cannot differentiate between a function call `option.?foo()` o

dot-like operations and calls

2021-11-17 Thread dwin
The dot like operator RFC included a proposal for a `.?()` operator too, which I think would be helpful for this case. Don't think it has been implemented.

dot-like operations and calls

2021-11-15 Thread markspanbroek
If you were to ask me, I would prefer either the `DotLike` or the old `Call` options, because they're explicit. The `Infix` with more arguments would also work for me. But I have no insight into how the parser works for the dot-like operators, and what is achievable without too much hassle.

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`

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)