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
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.
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.
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`
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=?
The best option seems to be to rename the operator to `?.`, sorry.
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
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.
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)