2016-01-24 17:05 GMT+03:00 Bram Moolenaar <[email protected]>:

>
> Marius Gedminas wrote:
>
> > On Sat, Jan 23, 2016 at 07:46:42PM +0100, Bram Moolenaar wrote:
> > >
> > > Patch 7.4.1154
> > > Problem:    No support for JSON.
> > > Solution:   Add jsonencode() and jsondecode().  Also add v:false,
> v:true,
> > >             v:null and v:none.
> >
> > Why do we need both v:null and v:none?
>
> Yes, because JSON has the "null" value and we need something for an
> empty spot in an array: [1,,3].
>

​And where is this value in spec you referenced in help (
http://www.ietf.org/rfc/rfc4627.txt)?​ JSON has nothing like this, and this
will not be understood by other RFC-compliant JSON parsers (e.g. built-in
Python `json` module). It is JavaScript that does have null values.



>
> > These seem to be unfriendly to vimscript tests:
> >
> >     :echo v:false == 0
> >     E685: Internal error: get_tv_number()
> >     1
> >
> >     :echo v:true == v:false
> >     E685: Internal error: get_tv_string_buf()
> >     E685: Internal error: get_tv_string_buf()
> >     1
> >
> >     :if v:true | echo "yes" | endif
> >     E685: Internal error: get_tv_number()
>
> These should work now.  Please watch out for more.
>
> Background: I first tried using an existing variable type instead of
> introducing a new one.  Such as a string with constant value.  But it
> quickly becomes a mess.
>

​When I had the same problem with msgpackdump/msgpackparse (Neovim) I
simply used lists for this case. I.e. if v:true is a list one can compare
something to v:true using `jsondecode('true') is v:true`. Though
msgpackdump()/msgpackparse() actually returns `{'_TYPE':
v:msgpack_types.boolean, '_VAL': 1}` and this has a perfect reasoning for
msgpack values: try `jsondecode('"\u0000"')​`: this is an empty string,
with msgpackparse() this is `{'_TYPE': v:msgpack_types.str, '_VAL':
["\n"]}` (readfile()-style list in _VAL). msgpackdump()/msgpackparse() with
“special dictionaries” concept is able to represent *any* msgpack value,
your code cannot represent any JSON value.

Not very convenient though, but I preferred to be able to parse absolutely
any msgpack string and dump back unmodified. In case of JSON there would be
five possible special dictionaries: for true, false and null and for
strings with embedded NULs and for dictionaries with empty keys or with
keys containing NUL.



>
> --
> Apparently, 1 in 5 people in the world are Chinese.  And there are 5
> people in my family, so it must be one of them.  It's either my mum
> or my dad.  Or my older brother Colin.  Or my younger brother
> Ho-Cha-Chu.  But I think it's Colin.
>
>  /// 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.
>

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