Hari Krishna Dara wrote:
I have hit this thrice already, while using the ?: ternary operator, in
some conditions, you are forced to put whitespace to separate the
operator otherwise Vim gets confused. Here is something that fails:

  let direction = (a:0?a:1:1)

I had this issue before calling script-local functions from the
true or false condition. The workaround as I said for the above is:

  let direction = (a:0 ? a:1 :1)

The problem is, sometimes I have a force of habit to skip the whitespace
in some places when I want the code to be really compact/tight
(especially when with map(), filter() or \=), and I will not notice the
problem until sometime later when the code gets executed. If the code
happened to execute with a :silent, you may have to do quite a bit of
debugging to find this kind of errors. Is it possible for Vim to parse
this unambiguously? The usage could be even worse, something like:

  let direction = (a:0>1?a:2:a:1)


The problem comes from the two meanings of the colon: as part of the (?:) operator, or to separate the context prefix from the variable or function name in v: s: g: l: a: b: w: t: &g: &l:

To parse it unambiguously regardless of spaces, use parentheses:

        (a:0?(a:1):1)
and
        ((a:0>1)?(a:2):(a:1))

are unambiguous (and more legible too).


Best regards,
Tony.

Reply via email to