On Fri, 8 Sep 2006 at 4:41am, A.J.Mechelynck wrote:

> 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.

I know that this is possible, but as I said previously, it is a force of
habit to compact as much as possible in some situations, though I
normally prefer using whitespace and parenthesis to improve clarity.

Also, the reason I mentioned using spaces is not really as a workaround
but to show the subtle difference it makes to the parser. Once you use
parenthesis, there is nothing really ambiguous about it.

I have a suspcion that using parenthesis also didn't solve the issue in
one of the cases (I remember it was calling script-local functions as
part of map() expression). I have to try to reproduce it though, I don't
remember it now.

-- 
Thanks,
Hari
>


-- 
Thanks,
Hari

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to