Lcd wrote:

> On 7 February 2016, Bram Moolenaar <[email protected]> wrote:
> > 
> > Patch 7.4.1285
> > Problem:    Cannot measure elapsed time.
> > Solution:   Add reltimefloat().
> [...]
> 
>     This is useful, thank you.
> 
>     Going on a tangent: it would be nice if floating point numbers had
> automatic stringification.  Example:
> 
>         :let a = 1.1
>         :echo a
>         1.1
> 
>         :echo ' ' . a
>         E806: using Float as a String
>         E15: Invalid expression: ' ' . a
> 
>     To handle that you have to go through printf():
> 
>         :echo printf(' %g', a)
>          1.1
> 
>     There's also a small inconsistency between %g (and echo), and %f:
> 
>         :echo printf(' %f', a)
>          1.100000
> 
>     reltimefloat() is a good illustration why all this matters, and how
> doing things the old way might still be less awkward than using the new
> function:
> 
>         if has('float') && exists('*reltimefloat')
>             echo printf('staring for %g seconds', 
> reltimefloat(reltime(delta)))
>         endif
> 
>     Compare that to the old trick:
> 
>         echo 'staring for ' . split(reltimestr(reltime(delta)))[0] . ' 
> seconds'
> 
>     Summary: it would be nice if floating point numbers in a string
> context would be stringified to printf('%g', number).

Yes and no.  There have been cases where automatic conversion causes
unexpected behavior.  I think the main one is converting a string to a
number.  We have to be careful not to add automatic conversion where
it's not expected.

Most likely it's OK when explicitly using the "." operator for string
concatenation.  Unfortunately "." is also used in floats, and in a few
case in an unexpected way:
        echo "a" . 1.1
        a11

But if we make this work:
        let a = 1.1
        echo "a" . a
        a1.1

Don't we get confused?

Anyway, I rather have things work in a sensible way than throwing error
messages.  It's going to be some work to do this right.

-- 
hundred-and-one symptoms of being an internet addict:
180. You maintain more than six e-mail addresses.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

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