On 23/06/08 19:37, Andy Armstrong wrote:
> On 23 Jun 2008, at 18:34, Gautam Iyer wrote:
>>> Doesn't that allow '+-3' ?
>> This seems to go unnoticed in some other languages too (e.g. Python).
>
>
> I assume that's because they support unary '+' as an operator. It's
> not part of the numeric constant:
>
>   >>>  print +(1+2)
> 3
>   >>>  print ++++++(1+2)
> 3
>   >>>  print ---1
> -1
>

Vim supports both + and - as unary operators, but apparently it supports 
-3 but not +3 as a single numeric token. (Where an expression is 
expected, +3 is accepted as the operator + acting on the number 3.)

For instance:
        :echo str2nr('-3')
-3
        :echo str2nr('+3')
0
        :echo str2nr('--3')
0
        :echo eval('-3')
-3
        :echo eval('+3')
3
        :echo eval('--3')
3

The difference is that str2nr() expects the string-form of a Number, 
eval() expects the string-form of an expression.

I suppose that now that we know it, we can live with it.


Best regards,
Tony.
-- 
Baltimore, n.:
        Where the women wear turtleneck sweaters to hide their flea
collars.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui