2015-11-24 1:14 GMT+03:00 Bram Moolenaar <b...@moolenaar.net>:

>
> Nikolay Pavlov wrote:
>
> 2015-11-21 16:41 GMT+03:00 Damien <damien...@gmx.fr>:
>
> > > Hi list,
> > >
> > > Vim function `py{,3}eval()` cannot used with a void expression.
> > >     :call pyeval('None')
> > >     E859: Failed to convert returned python object to vim value
> > >
> > > This is expected?
> > >
> >
> > Yes, of course. Pyeval is for getting result from Python expressions, for
> > executing expressions for their side-effects there is `:python` and
> > `:execute`. And VimL does not have `None` equivalent to convert Python
> > `None` to it.
>
> Well, it's possible that a Python function returns None in some
> situations.  Would be good to be able to handle that in a simple way.
>
> We do have the problem that there is no equivalent of None.  Perhaps the
> simples is to use the string 'None'.  Using something like zero is more
> easily confused with a valid return value.
>

`None` is also valid return value.


>
>         let result = pyeval(expression)
>         if result != 'None'
>

​No, this is invalid: function can just as well return string `None`. And
if author expects return to be `None` he can easily make expression return
something else, Python is far more flexible.

// By the way, why you are suggesting `!=` for string comparison? It must
never be used due to &ignorecase option effects.

// Also the code you wrote suggests that function returns a string: (0 !=
'None') will evaluate to false, non-string and non-number types are errors.
But if it returns a string how can you distinguish `None` and `'None'`? You
see: such approach is very prone to errors. Forcing author to think what to
return for `None` is less prone. // I would suggest `isnot#` operator in
this case.

Current variant is more pythonic: None is not converted automatically to
any value (unlike True/False: 1 + True == 2, for historical reasons), thus
does not have any equivalents in VimL and falls under “explicit is better
then implicit” approach.

Authors may also use `:try/:catch` in such cases, though it will be more
verbose (and eats tracebacks AFAIR).



>           " do something with result
>         endif
>
>
> --
> I'm writing a book.  I've got the page numbers done.
>
>  /// Bram Moolenaar -- b...@moolenaar.net -- 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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui