Wednesday, January 6, 2021

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

On 2021/01/02 08:01, Tim Chase wrote
> though a lot of vim stuff takes inspiration from
> Python where min() is a vararg function letting
> you do as the OP requests
>
> min(arg1, arg2, arg3, arg4, …)
>
> so it's a reasonable sort of hope/expectation.
> It just doesn't happen to be a vim thing.
>
---
Is there any reason why vim couldn't have a simplified
version, "Min" that takes a variable number of args
rather than its current behavior of taking a fixed
number (1) of "list-args"?

I.e. it sounds like, by being declared "varargs",
that min could take a variable number of args (?).

Is a vim function capable of determining the type
of the arg(s) passed to it? Like if I passed
min(3,4,[1,2]), can vim determine that it got 3 arguments,
where it knows that they are two "plain" args, and
1 is a "List" such that it could automatically expand "List" args,
and "inline" its elements into 1 longer set of arguments
that 'min' can return the value of?

I.e., it seems like "min", rather than returning an "Error"
when presented with multiple-args, could simply return the
minimum of those args, _and_, if any of those args were a "List",
like [1,2], then merge those args into the set of multiple
args that was passed. This would mean that ([1,2]) would
automatically expand its List into multiple arguments (1,2), and
then return the "min" value, i.e. "doing the right thing", while
keeping compatibility with current behavior (except for returning
an error when unnecessary).

Wouldn't that be possible for "min" and similar functions
that can tell what the user wants, and just do it? (rather than
returning an error that doesn't seem necessary or useful)
> -tim
>
---
Thanks for the explanations! As you point out, vim, it
seems, could do the right thing while remaining functionally
compatible with older vim script.

-Linda

--
--
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/5FF6110E.7050102%40tlinx.org.

No comments:

Post a Comment