2016-12-21 20:45 GMT+03:00 Tony Mechelynck <[email protected]>:
> Unary + and unary - are accepted as operators for Numbers in
> vimscript. Floats are not expressly mentioned under ":help expr7" but
> I would expect them to be "some kind of number", thus + 1.2 should be
> a legitimate expression (1.2, unchanged) and so would - 1.2 (1.2, with
> sign change). These expressions would of course be subject to operator
> precedence. In particular 1.2 is an atomic Float (an expr9) and so is
> -1.2 (with no space), but - 1.2 (with space) is an expr7.

No, `-1.2`, `+1.2`, `- 1.2` and `+ 1.2` all contain unary operators.
expr7, expr8 and expr9 are all handled by a single function `eval7()`
which starts with recording initial position and skipping all three
(with `!`) unary operators to apply them later. expr9 is then handled
in a switch (which obviously does not expect any unary operators
because they all were already skipped) and then `handle_subscript()`
handles expr8. After handling subscripts function starts applying
unary operators.

So, internally there is no such a thing as “negative constant”.

>
> Best regards,
> Tony.
>
> On Wed, Dec 21, 2016 at 6:17 PM, Pavol Juhas <[email protected]> wrote:
>> On Wed, Dec 21, 2016 at 12:05 PM, Dominique Pellé
>> <[email protected]> wrote:
>> ...
>>> I also think that it's odd to accept spaces between the
>>> sign and the digits.  However, Vim already accepts spaces
>>> after the - sign and not after the + sign  (inconsistency addressed
>>> in patch in this thread).   If we instead give an error for
>>> str2float(" + 1.2"), then we break compatibility and potentially
>>> break existing scripts.
>>
>> True, but whichever script is relying on "+ 1.2" being a legitimate
>> float is already
>> buggy and fragile, because it breaks for "- 1.2".  I don't see there
>> would be much
>> damage caused by requiring attached signs.
>>
>> Pavol
>>
>> --
>> --
>> You received this message from the "vim_dev" maillist.
>> Do not top-post! Type your reply below the text you are replying to.
>> For more information, visit http://www.vim.org/maillist.php
>>
>> ---
>> You received this message because you are subscribed to the Google Groups 
>> "vim_dev" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups 
> "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui