Tuesday, February 20, 2018

Re: build dict key:val from map list and substitute

2018-02-20 22:52 GMT+03:00 Ni Va <nivaemail@gmail.com>:
> Hi,
>
> map(copy(totaltimelist)[0:10], 'substitute(v:val, linepat, "\\1 : \\2", "")')
>
> Two values as backward ref are retrieved from a mapped list but I would like to use :
> - first value \\1 as dict.key
> - second value \\2 is added to dict[key].values = [\\2,...,..]
>
>
> How doing this into first map( function above ?

You need to use `\=` as a replacement with `submatch(1)` for `\1`.
Expressions after `\=` are fully capable of side-effects, though I
should say that unless there are performance requirements replacing
`map()` with `:for` would be more readable. Also unless you do need
`substitute()` results it is better to discard `substitute()` and use
`matchlist()`, putting side-effects in the top-level expression thus
saving another level of escaping. Though most likely you would need
`extend(l:, …)` to create temporary variables in this case, as I said
earlier lambdas are not good for performance.

Ah, and you must remove `copy()`. What you are doing here is creating
a copy of a list, slicing it (thus creating *another* list) and
immediately discarding the list created by `copy()`.

>
> Thank in advance
> Nicolas
>
> --
> --
> You received this message from the "vim_use" 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_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: