On 25 January 2016, Bram Moolenaar <[email protected]> wrote:
>
> Lcd wrote:
[...]
> >
> >     First example: syntastic.  Syntastic is a plugin that runs
> > various linters against a file, parses their output, and puts it in
> > a quickfix list.  Some of these linters produce more precise reports
> > when told to output JSON, and syntastic uses this function to parse
> > said reports:
> >
> >         https://goo.gl/ca8Tzb
>
> You could still do a string substitute over the JSON before giving it
> to jsondecode(), to change 'true' to 1, 'false' to 0, etc.

    This is not safe.  I'm parsing error messages, there may be plenty
of tue and false elsewhere in the text...

[...]
> I suppose what would be useful here is a variant of map() that, when
> an item is a list or dict, goes into that item, instead of evaluating
> the expression. perhaps treemap()?  That would find each leaf and
> evaluate the expression, replacing the existing item.  Since we
> already have map() that would not be so difficult to implement.

    This might be a good solution for the particular problem at hand,
but it won't be a diirect extension of map().  For map(dict, '...') both
v:key and dict[v:key] make sense.  For the new function only v:val would
make sense; v:key would be a path to the current leaf, and v:val might
not be a direct value of a dict item.  Just saying.

On 25 January 2016, Bram Moolenaar <[email protected]> wrote:
> 
> Lcd wrote:
[...]
> >     Yes.  My point was, there is no comparison
> > 
> >         [v:true] cmp [1]
> > 
> > that returns true.
> 
> Yes, and the same for [1.0] cmp [1].  Changing the semantics of "=="
> could work, but then we need another operator for when we do want
> types to match.  So adding a new operator that doesn't check the type,
> only the effective value, could be the solution.  We also still need
> an operator that avoids that '' and zero are deemed equal:
>       echo '' == 0
>       1
> Which is actually the opposite of making something less strict than ==.
> Darn.  We can't change that without breaking lots of scripts.

    A new operator for comparing lists (and perhaps also dicts) could be
another good solution.  It could be called cmp, with variants cmp? and
cmp#.  It would be equivalent to something like this:

        a[key_0] == b[key_0] && ... && a[key_n] == b[key_n]

> That could be done with "===" (like in Javascript, type must match).

    I don't think it needs to also apply to single values.  This is
consistent with is and isnot, hence the name cmp.

> But we still don't have something for "equal value".  So we would need
> yet another operator. "=*=" ???

    I suppose that could be useful too.  An operator named === (with
variants ===? and ===#) could do this.  It would be equivalent to:

        type(a) == type(b) && a == b

    It would apply to both single values, lists, and dicts, and the name
=== would be consistent with the rest of the =* menagerie.

    /lcd

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