--20cf303bf65cfeb90a04b0385009
Content-Type: text/plain; charset=UTF-8

On Wed, Oct 26, 2011 at 2:08 PM, Yukihiro Matsumoto <matz / ruby-lang.org>wrote:

> Hi,
>
> In message "Re: [ruby-core:40414] Re: [ruby-trunk - Feature
> #5474][Assigned] keyword argument"
>     on Thu, 27 Oct 2011 02:51:51 +0900, Charles Oliver Nutter <
> headius / headius.com> writes:
>
> |Evan and I would like to see support for non-default keyword args. So
> |the following form would require that "size" be provided as a keyword
> |arg, and otherwise raise an ArgumentError:
> |
> |def create_point(x, y, color: "white", size:)
>
> I don't know the reason why you need this value-less keyword
> argument.  If you want the default value, you just need to omit the
> keyword altogether.
>

I think the point is that not every argument necessarily has a reasonable
default. Imagine, for example, if we were to rewrite File.open to take
keyword arguments:

    class File
      def self.open(filename:, mode: 'r')
      ...

It would be desirable to call such a method as `File.open(filename:
"foo.txt")` but omitting the "filename:" argument should be an error.
Perhaps, if a hash-like syntax is desired, we could introduce a "required"
keyword:

    class File
      def self.open(filename: required, mode: 'r')
      ...

such that omitting the option raises an ArgumentError?

--20cf303bf65cfeb90a04b0385009
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<br><div class="gmail_quote">On Wed, Oct 26, 2011 at 2:08 PM, Yukihiro Matsumoto <span dir="ltr">&lt;matz / ruby-lang.org&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br>
<br>
In message &quot;Re: [ruby-core:40414] Re: [ruby-trunk - Feature #5474][Assigned] keyword argument&quot;<br>
<div class="im">  on Thu, 27 Oct 2011 02:51:51 +0900, Charlesliver Nutter &lt;headius / headius.com&gt; writes:<br>
<br>
|Evan and I would like to see support for non-default keyword args. So<br>
|the following form would require that &quot;size&quot; be provided as a keyword<br>
|arg, and otherwise raise an ArgumentError:<br>
|<br>
|def create_point(x, y, color: &quot;white&quot;, size:)<br>
<br>
</div>I don&#39;t know the reason why you need this value-less keyword<br>
argument. If you want the default value, you just need to omit the<br>
keyword altogether.<br></blockquote><div><br></div><div>I think the point is that not every argument necessarily has a reasonable default. Imagine, for example, if we were to rewrite File.open to take keyword arguments:</div>
<div><br></div><div>  class File</div><div>  ef self.open(filename:, mode: &#39;r&#39;)</div><div>  ..</div><div><br></div><div>It would be desirable to call such a method as `File.open(filename: &quot;foo.txt&quot;)` but omitting the &quot;filename:&quot; argument should be an error. Perhaps, if a hash-like syntax is desired, we could introduce a &quot;required&quot; keyword:</div>
<div><br></div><div>  class File</div><div>  ef self.open(filename: required, mode: &#39;r&#39;)</div><div>   ...</div><div><br></div><div>such that omitting the option raises an ArgumentError?</div></div>

--20cf303bf65cfeb90a04b0385009--