Saturday, January 9, 2021

Bug somewhere in :put/map/range/lambda functions?

Tried this:

:put=range(1,10)

and it worked as expected, appending the numbers 1..10 to my file.
Same with:

:put=map(range(1,10), 'v:val')

which worked as expected. However using a no-op lambda function:

:put=map(range(1,10), {v -> v})

somehow gets the numbers 0..9 in the file instead of 1..10

This reduced it to the simplest case for demonstration. I stumbled
across it attempting FizzBuzz in a one-liner:

:put=map(range(1, 100), {v -> v % 15 ? v % 5 ? v % 3 ? v : 'Fizz' :
'Buzz' : 'FizzBuzz'})

confused why it kept putting 0/FizzBuzz as the first row.

This is 8.2.1558 on FreeBSD in case it matters:

:ver
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Oct 4 2020 13:32:14)
Included patches: 1-1558

I'm not sure where I'd start trying to troubleshoot this, but thought
I'd at least mention the oddity here.

-tim




--
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210109132658.30fe94fa%40bigbox.attlocal.net.

No comments: