On Fri, Feb 03, 2023 at 12:55:30PM +0000, Bram Moolenaar wrote:
> > On Thu, Feb 02, 2023 at 05:28:03PM +0000, Bram Moolenaar wrote:
> > > 3. Add a mechanism to name the members in the call, e.g.
> > >   var obj = Class.new(line = 5, column = 0)
> > >    This is similar to 2. but puts it in one line.
> > >    It requires marking a method to not use positional arguments.a
> > > 
> > > Although 3. looks like a good solution, it requires implementing a new
> > > mechanism.  And disallowing positional arguments might be considered
> > > weird, I cannot think of a language that has this functionality.
> > 
> > Python lets you declare that a function will not accept positional
> > arguments:
> > 
> >     def fn(*, line, column, also_arg_with_a_default_value=42):
> >         ...
> > 
> >     fn(line=5, column=0)
> >     fn(column=0, line=5)
> >     fn(0, 5)    # <-- error, positional arguments not allowed
> >     fn(line=5)  # <-- error, 'column' argument is required
> 
> I have been using Python but didn't know about this mechanism.

This syntax was added in Python 3.0.  Since I started with Python 2.1, I
still think of it as "the new keyword-only argument syntax".  I'm old.

> Apparently the "*" can also appear later, e.g.
> 
>      def fn(line, *, column, also_arg_with_a_default_value=42):
> 
> Now you can use:
>       fn(5, column=0)
> 
> Although this works, I find it rather obscure.

It is a consequence of allowing variable number of arguments with *args:

    def fn(regular, args, *the_rest):

the Python designers decided to allow additional arguments after the
all-consuming varargs argument

    def fn(regular, args, *the_rest, keyword_only=None):

and then if you don't actually want the varargs you can omit the name
for it

    def fn(regular, args, *, keyword_only=None):

Anyway, I wasn't proposing this syntax for Vimscript, merely mentioning
that there are languages that have this functionality.

Marius Gedminas
-- 
Initially, there were few or no postal regulations governing packages mailed
parcel post. To construct a bank in Vernal, Utah in 1916, a Salt Lake City
Company figured out that the cheapest way to send 40 tons of bricks to the
building was by Parcel Post. Each brick was individually wrapped & mailed.
Postal rules were promptly rewritten.
        -- http://en.wikipedia.org/wiki/United_States_Postal_Service

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230204135355.t3dapt6ktwbttprc%40blynas.

Attachment: signature.asc
Description: PGP signature

Raspunde prin e-mail lui