> 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.

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.

-- 
You can't have everything.  Where would you put it?
                -- Steven Wright

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230203125530.664E51C25FD%40moolenaar.net.

Raspunde prin e-mail lui