Saturday, January 9, 2021

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

Hi, Tim,

On Sat, Jan 9, 2021 at 11:27 AM Tim Chase <vim@tim.thechases.com> wrote:
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

The lambda function is called with two arguments (the index of the current
item in the list and the value of the item). In your example, you are using
the index of the list item instead of the value. You can try using one of
the following:

     :put=map(range(1, 10), {i, v -> v})
or
     :put=map(range(1, 10), {-> v:val})
 
Regards,
Yegappan


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/CAAW7x7kq5-F0H8L%3DVriUoq%2Bn7oTQmaAoPDiAFffE-V_hxuc-%3DA%40mail.gmail.com.

No comments: