No subject

From: ()
Date: Mon Dec 3 19:58:15 EST 2012

style.

What I'd really like, for the sake of flexibility / ease of use, is to
have no explicit keyword argument, but all arguments are implicit ones, so
that you can call a function by mixing by position and by name as you like,
without having specified so in the function's header.
(Visual Basic[1] and Python[2] do something along these lines.)

For example:
(define (foo x y [z 3] [t 4]) ....)

(foo 1 2 5)
(foo #:z 5 #:y 1 #:x 2)
(foo 1 #:t 6 #:y 3)

(foo #:x 3)
Error: missing mandatory argument `y'

(apply/kw f 2 #:y 3 '(5) '((t . 3)))

In particular, one would then not have to worry about the order of the
optional arguments in the function definition.

Headers would be also smaller, easier to read, and easier to write.

Pushing a bit further:
(define (foo x y . rest) ....)
would not accept keywords different from #:x and #:y, but
(define (foo x y . rest-by-pos . rest-by-name) ....)
would receive a list of positional argument values, and a dictionary of
names and values, even if these names are not x or y.

Laurent
[1] http://msdn.microsoft.com/en-us/library/51wfzyw0.aspx
[2]
http://www.diveintopython.net/power_of_introspection/optional_arguments.html

--047d7b6226f0a3551904de8a52d1
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On Fri, Jun 7, 2013 at 1:42 AM, Matthew Flatt <span dir=3D"ltr">&lt=
;<a href=3D"mailto:mflatt at cs.utah.edu" target=3D"_blank">mflatt at cs.utah.edu=
</a>&gt;</span> wrote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex"><div>At Thu, 9 May 2013 1=
6:22:54 +0200, Laurent wrote: <br></div></blockquote><blockquote class=3D"g=
mail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204=
,204,204);padding-left:1ex">

<div class=3D"im">
&gt; I&#39;ve always wondered why the syntax of keywords implied two elemen=
ts: the<br>
&gt; #:keyword and the identifier.<br>
&gt; I find that quite heavy for procedure headers, and most of the time I =
use<br>
&gt; the same symbol for the identifier and the keyword (and when I don&#39=
;t it&#39;s<br>
&gt; because I&#39;m simply lazy and use a shorter identifier).<br>
&gt;<br>
&gt; Is there a rationale somewhere for that?<br>
<br>
</div>The rationale is to make function definitions have the same shape as<=
br>
function calls.<br></blockquote><div><br></div></div>I see what you mean, t=
hough I wouldn&#39;t make a strong case of it (maybe I&#39;m <br>missing so=
mething).<br><br></div><div class=3D"gmail_extra">From time to time, I real=
ly feel frustrated by the current function header style.<br>

</div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">What =
I&#39;d really like, for the sake of flexibility / ease of use, is to<br>ha=
ve no explicit keyword argument, but all arguments are implicit ones, so <b=
r>

that you can call a function by mixing by position and by name as you like,=
 <br>without having specified so in the function&#39;s header.<br></div><di=
v class=3D"gmail_extra">(Visual Basic[1] and Python[2] do something along t=
hese lines.)<br>

</div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">For e=
xample:<br></div><div class=3D"gmail_extra">(define (foo x y [z 3] [t 4]) .=
...)<br><br></div><div class=3D"gmail_extra">(foo 1 2 5)<br></div><div clas=
s=3D"gmail_extra">

(foo #:z 5 #:y 1 #:x 2)<br></div><div class=3D"gmail_extra">(foo 1 #:t 6 #:=
y 3)<br><br></div><div class=3D"gmail_extra">(foo #:x 3)<br></div><div clas=
s=3D"gmail_extra">Error: missing mandatory argument `y&#39;<br><br></div><d=
iv class=3D"gmail_extra">

(apply/kw f 2 #:y 3 &#39;(5) &#39;((t . 3)))<br></div><div class=3D"gmail_e=
xtra"><br></div><div class=3D"gmail_extra">In particular, one would then no=
t have to worry about the order of the<br>optional arguments in the functio=
n definition.<br>

<br></div><div class=3D"gmail_extra">Headers would be also smaller, easier =
to read, and easier to write.<br></div><div class=3D"gmail_extra"><br></div=
><div class=3D"gmail_extra">Pushing a bit further:<br></div><div class=3D"g=
mail_extra">

(define (foo x y . rest) ....)<br></div><div class=3D"gmail_extra">would no=
t accept keywords different from #:x and #:y, but<br></div><div class=3D"gm=
ail_extra">(define (foo x y . rest-by-pos . rest-by-name) ....)<br></div><d=
iv class=3D"gmail_extra">

would receive a list of positional argument values, and a dictionary of <br=
>names and values, even if these names are not x or y.<br></div><div class=
=3D"gmail_extra"><br></div><div class=3D"gmail_extra">Laurent<br>[1] <a hre=
f=3D"http://msdn.microsoft.com/en-us/library/51wfzyw0.aspx">http://msdn.mic=
rosoft.com/en-us/library/51wfzyw0.aspx</a><br>

</div><div class=3D"gmail_extra">[2] <a href=3D"http://www.diveintopython.n=
et/power_of_introspection/optional_arguments.html">http://www.diveintopytho=
n.net/power_of_introspection/optional_arguments.html</a><br></div></div>

--047d7b6226f0a3551904de8a52d1--

Posted on the dev mailing list.