why doesn't min take more than 1 parameter?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

why doesn't min take more than 1 parameter?

L A Walsh
I have the expression:

trunc(1+log(1+line('$'))/log(10))

to give me the width of the number columns when numbering is
on.  Seems that it is reserving a minimum of 3 columns, so I tried
using the 'min' function:

trunc(min(3,1+log(1+line('$'))/log(10)))

but I get E118: Too many arguments for function: min.

huh?  so how does one use 'min' to determine the lowest of 2 or
more numbers, or why doesn't the above work? :-(


*sigh*,
tnx


--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5FF08799.3040702%40tlinx.org.
Reply | Threaded
Open this post in threaded view
|

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

Yongwei Wu
Just do ":help min()", it will tell you:

min({expr}) Return the minimum value of all items in {expr}.
{expr} can be a |List| or a |Dictionary|.

So the simplest solution seems to be:

trunc(min([3, float2nr(1+log(1+line('$'))/log(10))]))

On Sat, 2 Jan 2021 at 22:49, L A Walsh <[hidden email]> wrote:
I have the expression:

trunc(1+log(1+line('$'))/log(10))

to give me the width of the number columns when numbering is
on.  Seems that it is reserving a minimum of 3 columns, so I tried
using the 'min' function:

trunc(min(3,1+log(1+line('$'))/log(10)))

but I get E118: Too many arguments for function: min.

huh?  so how does one use 'min' to determine the lowest of 2 or
more numbers, or why doesn't the above work? :-(


*sigh*,
tnx


--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5FF08799.3040702%40tlinx.org.


--
Yongwei Wu
URL: http://wyw.dcweb.cn/

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CADs46ifKSZWXycw-ft%2B-F8OFFLqcxcOFb9zasYSxta%3D3RDYSRw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

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

Tim Chase
In reply to this post by L A Walsh
On 2021-01-02 06:47, L A Walsh wrote:
> trunc(min(3,1+log(1+line('$'))/log(10)))
>
> but I get E118: Too many arguments for function: min.

min() expects a single list-like argument so try

  trunc(min([3,1+log(1+line('$'))/log(10)]))

which creates a list-literal with "3" as the first item and your 1+…
as the second element.

-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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210102085725.3c7bc956%40bigbox.attlocal.net.
Reply | Threaded
Open this post in threaded view
|

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

Tony Mechelynck
Using a single list-like argument is more general: it allows
determining the minimum of any number of values. If it accepted only
two Float arguments, then to determine the minimum of 8 values you
would have to do for instance

:let result = min(min(min(arg1, arg2), min(arg3, arg4)), min(min(arg5,
arg6), min(arg7, arg8)))

while now you can do

:let result = min([arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8])

which is much more elegant.

Best regards,
Tony.

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXuGXH5cYEdBkk_SXqBcKQ8%3D%3DrTAjs7MDNDsN%3Di4vzawVA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

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

Tim Chase
On 2021-01-02 16:48, Tony Mechelynck wrote:

> Using a single list-like argument is more general: it allows
> determining the minimum of any number of values. If it accepted only
> two Float arguments, then to determine the minimum of 8 values you
> would have to do for instance
>
> :let result = min(min(min(arg1, arg2), min(arg3, arg4)),
> min(min(arg5, arg6), min(arg7, arg8)))
>
> while now you can do
>
> :let result = min([arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8])
>
> which is much more elegant.

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.

-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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210102100154.42d4f4df%40bigbox.attlocal.net.
Reply | Threaded
Open this post in threaded view
|

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

L A Walsh
In reply to this post by Yongwei Wu
On 2021/01/02 06:57, Yongwei Wu wrote:
> Just do ":help min()", it will tell you:
>
> min({expr}) Return the minimum value of all items in {expr}.
> {expr} can be a |List| or a |Dictionary|.
>
> So the simplest solution seems to be:
>
> trunc(min([3, float2nr(1+log(1+line('$'))/log(10))]))
>
---
Thanks, when I typed ":help min()", I got
min({list}), and didn't know if the curly braces, "{}"
were needed, but never would have guess I needed
square brackets "[]".

I had 'trunc' to convert from float to a truncated
integer, but notice that you are using "float2nr".

Didn't know I would have needed that either (I had
used the output of 'printf' to go from a number to
a string.

Thanks for the hints and, especially, the example.

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5FF25BC2.8020208%40tlinx.org.
Reply | Threaded
Open this post in threaded view
|

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

L A Walsh
In reply to this post by Tim Chase
On 2021/01/02 08:01, Tim Chase wrote:
> On 2021-01-02 16:48, Tony Mechelynck wrote:
>  
>> Using a single list-like argument is more general: it allows
>> determining the minimum of any number of values. If it accepted only
>> two Float arguments, then to determine the minimum of 8 values you
>> would have to do for instance
>>    
----
    I asked why it didn't seem to take more than one parameter.
That ':help min' shows min({list}), which really means
min([itema, itemb...]), is what was throwing me.
>> :let result = min(min(min(arg1, arg2), min(arg3, arg4)),
>> min(min(arg5, arg6), min(arg7, arg8)))
>>
>> while now you can do
>>
>> :let result = min([arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8])
>>
>> which is much more elegant.
>>    
True.  Even more elegant, might have been:
result = min(1,2,3,4,5,6,7,8);
 (  = 1)


On 2021/01/02 08:01, Tim Chase wrote:
> though a lot of vim stuff takes inspiration from
> Python ...
>  
I think vim was around before python.  vim would have drawn from
'vi' and, earlier, 'ed', sorta like early perl was an attempt to
mix early shell tools (sed, tr, sort, etc), with a shell like
language.  Passing args in a list seems more like lisp -- maybe
drawing examples from emacs?


Hey, do you know how to determine the number of columns taken up by
fdc?  Doesn't seem I can use fdc directly as a number though.

Thanks!






--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5FF39360.20002%40tlinx.org.
Reply | Threaded
Open this post in threaded view
|

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

Charles Campbell-2
L A Walsh wrote:
>
> Hey, do you know how to determine the number of columns taken up by
> fdc?  Doesn't seem I can use fdc directly as a number though.

Try using &fdc ; the ampersand means to grab the information from an option.

Regards,
Chip Campbell

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/9fe56fc9-c4fe-bc97-bcac-53d123e62a2b%40drchip.org.
Reply | Threaded
Open this post in threaded view
|

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

Tim Chase
In reply to this post by L A Walsh
On 2021-01-04 14:14, L A Walsh wrote:
> On 2021/01/02 08:01, Tim Chase wrote:
> > though a lot of vim stuff takes inspiration from
> > Python ...
> >    
> I think vim was around before python.

Both were originally released in 1991.  However, some of the
vim-script language features like list-initializers and
dictionary-initializers and negative list-indexing came into vim long
after Python had them and they draw pretty strong syntactic influence
thence.

> vim would have drawn from 'vi' and, earlier, 'ed',

Indeed, vim does find its roots in vi(1) which in turn is the visual
mode of ex(1) which shares concepts with ed(1). (and if you are on
Twitter or Mastodon and enjoy ed(1), feel free to check out my
@ed1conf and @[hidden email] alter-ego accounts)

> Hey, do you know how to determine the number of columns taken up by
> fdc?  Doesn't seem I can use fdc directly as a number though.

As Dr. Chip mentions, prefix the setting-name with an "&"

  :echo 'The value of foldcolumn is set to '.&fdc

should do the trick.

-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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210104190149.6e2bd9c7%40bigbox.attlocal.net.
Reply | Threaded
Open this post in threaded view
|

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

L A Walsh
In reply to this post by Tim Chase
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5FF6110E.7050102%40tlinx.org.
Reply | Threaded
Open this post in threaded view
|

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

Salman Halim
While I can't explain why things work the way they do, here is a custom function that should do what you want (called Min); it takes a variable number of arguments, flattens incoming lists into a single list and then calls the built-in min. You can see that it uses the type() function to figure out the type of the incoming argument (to answer another question you asked herein):

function! Min( ... )
  let collection = []

  for entry in a:000
    if ( type( entry ) == v:t_list )
      call extend( collection, flatten( entry ) )
    else
      let collection += [ entry ]
    endif
  endfor

  return min( collection )
endfunction

" Sample call
" echo Min(9, 22, [5, [3, 7]])

On Wed, Jan 6, 2021 at 2:37 PM L A Walsh <[hidden email]> wrote:
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5FF6110E.7050102%40tlinx.org.


--
 
Salman

I, too, shall something make and glory in the making.

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEdT5fcqbQc5v8o2h8RiPrwqSgm9ew5jKyBxNBGo%3DiBo9g%40mail.gmail.com.
BPJ
Reply | Threaded
Open this post in threaded view
|

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

BPJ
Den ons 6 jan. 2021 21:29Salman Halim <[hidden email]> skrev:
While I can't explain why things work the way they do, here is a custom function that should do what you want (called Min); it takes a variable number of arguments, flattens incoming lists into a single list and then calls the built-in min. You can see that it uses the type() function to figure out the type of the incoming argument (to answer another question you asked herein):

function! Min( ... )
  let collection = []

  for entry in a:000
    if ( type( entry ) == v:t_list )
      call extend( collection, flatten( entry ) )
    else
      let collection += [ entry ]
    endif
  endfor

  return min( collection )
endfunction

" Sample call
" echo Min(9, 22, [5, [3, 7]])

Isn't the problem that the number of varargs to a Vimscript function is limited, while a List can have many more elements (although there is probably a limit there too)?



On Wed, Jan 6, 2021 at 2:37 PM L A Walsh <[hidden email]> wrote:
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5FF6110E.7050102%40tlinx.org.


--
 
Salman

I, too, shall something make and glory in the making.

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEdT5fcqbQc5v8o2h8RiPrwqSgm9ew5jKyBxNBGo%3DiBo9g%40mail.gmail.com.

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CADAJKhBiO2KacvOiZYpGi6jW0hKfhcPawsKUdJe0diqRZ80UzQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

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

Salman Halim
Yes, 20. I agree with the problem. It's undoubtedly a holdover from when you had to use a:0, a:1, etc., and couldn't get a:000 (as a list), before proper lists were added.

I think the system could be extended to allow an arbitrary number of arguments for a:000 and still limit to up to 20 via the old mechanism: if you want to access the 21st on, use a:000 instead. 

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.

--

Salman

On Wed, Jan 6, 2021, 15:38 BPJ <[hidden email]> wrote:
Den ons 6 jan. 2021 21:29Salman Halim <[hidden email]> skrev:
While I can't explain why things work the way they do, here is a custom function that should do what you want (called Min); it takes a variable number of arguments, flattens incoming lists into a single list and then calls the built-in min. You can see that it uses the type() function to figure out the type of the incoming argument (to answer another question you asked herein):

function! Min( ... )
  let collection = []

  for entry in a:000
    if ( type( entry ) == v:t_list )
      call extend( collection, flatten( entry ) )
    else
      let collection += [ entry ]
    endif
  endfor

  return min( collection )
endfunction

" Sample call
" echo Min(9, 22, [5, [3, 7]])

Isn't the problem that the number of varargs to a Vimscript function is limited, while a List can have many more elements (although there is probably a limit there too)?



On Wed, Jan 6, 2021 at 2:37 PM L A Walsh <[hidden email]> wrote:
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5FF6110E.7050102%40tlinx.org.


--
 
Salman

I, too, shall something make and glory in the making.

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEdT5fcqbQc5v8o2h8RiPrwqSgm9ew5jKyBxNBGo%3DiBo9g%40mail.gmail.com.

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CADAJKhBiO2KacvOiZYpGi6jW0hKfhcPawsKUdJe0diqRZ80UzQ%40mail.gmail.com.

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEeH0iDyQJPV2BKxcw3LSUX7dz8%2BiGtJ0Ci2TpztQhiO7Q%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

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

L A Walsh
In reply to this post by L A Walsh
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5FF67D00.1030209%40tlinx.org.
Reply | Threaded
Open this post in threaded view
|

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

Salman Halim
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 <[hidden email]> 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 [hidden email].
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 [hidden email].
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.