Dominique wrote:
> I noticed that it's possible to use a :for loop
> on a blob and it's currently not documented:
>
> :for v in 0z0102003 | echo v | endfor
> 1
> 2
> 3
>
> So it apparently behaves like:
> :for v in [0x01,0x02,0x03] | echo v | endfor
> 1
> 2
> 3
>
> I wanted to document it, but then I then realized
> that it does not behaves as I'd expect in this
> example:
>
> echo "For loop with list"
> let l = [1, 2, 3]
> for x in l
> echo l
> call remove(l, 0)
> endfor
> echo l
>
> echo "For loop with blob"
> let b = 0z010203
> for x in b
> echo b
> call remove(b, 0)
> endfor
> echo b
>
> It outputs:
>
> For loop with list
> [1, 2, 3]
> [2, 3]
> [3]
> []
> For loop with blob
> 0z010203
> 0z0203
> 0z03
>
> Notice that:
> - the loop with list iterated 3 times, as expected, whereas
> the loop with blob iterated only 2 times which seems wrong.
> - at the end, list l is empty as expected, whereas blob b has
> 1 byte left which seems wrong.
>
> It looks like a bug to me. But since looping on a blob
> is not documented, I don't know what to expect.
The loop over blob does not handle the blob changing inside the loop.
Like you did, most users will expect it to behave like a list of bytes.
Thus I think we should fix that. Patch is welcome!
> Unrelated question: how do we convert a blob 0z010203
> into a list of integers [0x01,0x02,0x03]? Perhaps we
> should be able to do:
>
> :echo items(0z010203)
> [1,2,3]
>
> But that does not work. Any other way?
Why would you want to do that? Since the information in the Blob is
binary, when would you want to turn it into a list?
--
hundred-and-one symptoms of being an internet addict:
269. You receive an e-mail from the wife of a deceased president, offering
to send you twenty million dollar, and you are not even surprised.
/// 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.