Wednesday, January 6, 2021

Re: why doesn't min take more than 1 parameter?

Obviously, your example was just to make a point because you can easily tell which of two numbers is the smaller, unless it's in a programming environment. 

That said, I don't know how I feel about it. I see your point as there are already plenty of API that now take an extra parameter to optionally return a list and some take variable arguments, such as printf, so individual functions do support multiple flavours. 

On the other hand, there is often stuff that doesn't do exactly what one thinks is intuitive (not just Vim), and I write variations to make it do what I want all the time. While it may be worth arguing that anything that takes a list should also accept multiple arguments and figure it out, the version I wrote took very little time. (I wrote it specifically for this email chain: I use the built-in min function quite happily.)

I guess I don't find typing 'min([5, 2, 12])' instead of 'min(5, 2, 12)' that cumbersome. Also, in most language situations that arise, you usually pass min an array. (I realize that JavaScript and python do allow both, as you've also mentioned.)

Best regards,

--

Salman

On Wed, Jan 6, 2021, 22:17 L A Walsh <vim@tlinx.org> wrote:
On 2021/01/06 12:28, Salman Halim wrote:
> While I can't explain why things work the way they do, here is a
> custom function
---
    That's just the thing -- the functions in Vim should be the most general
possible so custom solutions are rarely, if ever needed.

On 2021/01/06 13:16, Salman Halim wrote:
>
> Of course, if you have dozens and dozens of arguments, you could wrap
> them in a [] pair to convert it into a list of arbitrary length (that
> process isn't limited by the 20 function parameter limit).
> Programmatically speaking, if you're doing this dynamically, it seems
> to me as if creating a list of arbitrary length is better than
> creating an execute statement that takes a large number of individual
> parameters.
---
    But non-programmatically, when you just want the min/max of 2, wouldn't
handling both cases be best?  So other functions could pass large numbers of
parameters in a list, but simple cases wouldn't need the overhead or special
syntax.

    If the function handled both cases min(3,4,5,[1,2]) would become
min(3,4,5,1,2) or min([3,4,5,1,2]) and either format would work.  Then users
expecting simple like 'min(1,2)', would just have it work, while those
wanting more complex, could use the equivalent min([1,2]);  Either way, it
would just "do the right thing" and not require the user to conform to one
one syntax or the other.

    As you point out -- it can be done today -- it just hasn't been,
yet.  :-)



--
--
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/5FF67D00.1030209%40tlinx.org.

--
--
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/CANuxnEeMsn-km_S_7ESa_sCRqztGRNuT2_3tyh3%2BF%2BO5yo1yJQ%40mail.gmail.com.

No comments:

Post a Comment