Lcd wrote:

> > > > [...]
> > > > > >     Actually, since you added two more values for type(), it
> > > > > > would make sense to make Bool and Null standard types, Vim
> > > > > > citizens with full rights.  But some careful consideration
> > > > > > would be needed for the interaction with the other types, so
> > > > > > that they can also be used for other purposes, unrelated to
> > > > > > JSON.
> > > > >
> > > > > The thing is that the only valid values are what we have now.
> > > > > Giving those types a name doesn't really help.
> > > > >
> > > > > >     The alternative would be to make jsondecode() return
> > > > > > only standard Vim values (that is, true --> 1, false --> 0,
> > > > > > null --> ''), and leave v:<special> only for encoding.  Less
> > > > > > powerful, but a lot simpler, and a lot more robust.
> > > > >
> > > > > Then you can't tell the difference between decoding a zero or
> > > > > "false".  This drops information that might be important.  I'm
> > > > > sure this will be a problem at a later time.
> > > >
> > > >     Yes, but now we have the worst of the two worlds: types that
> > > > aren't quite types, and values that aren't quite values.  They'll
> > > > break things eventually.  Actually, Nikolai Aleksandrovich Pavlov
> > > > has a few examples when they do.  F.i. eval(string(var)) is no
> > > > longer guaranteed to be the same as var.
> > > [...]
> > >
> > >     One more thing: adjusting the result of jsondecode() to contain
> > > only "standard" values involves deep traversal, which is not
> > > trivial.  Actually, it's pretty hard to get right.
> >
> > Example?
> 
>     Anything nested would do:
> 
> :echo jsondecode('[{"a":true, "b":false}, null, {"foo": true, "bar": true, 
> "baz": null}]')
> [{'a': true, 'b': false}, null, {'foo': true, 'baz': null, 'bar': true}]
> 
>     Replacing all true, false, and null with "plain" 0, 1, and '' means
> traversing the leaves of this.

When would that be needed?  v:true and v:false can be used in an
expression just like one and zero.  I don't know what to replace v:null
with, it must be recognized to know there is nothing there.  In this
example an empty dict is probably what you want, but that's not a
generic solution.

-- 
hundred-and-one symptoms of being an internet addict:
38. You wake up at 3 a.m. to go to the bathroom and stop and check your e-mail
    on the way back to bed.

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