<div dir="ltr"><br><br><br>On Mon, Jun 17, 2013 at 5:09 PM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">
<div><br></div><div>p.s. On second thought, for structs you want two constructors: </div><div> -- one that takes positional arguments </div><div> -- one that takes keyword arguments </div></blockquote><div><br></div><div>
My intent was that you could use both positional and keyword arguments at the same time, for each argument.<br></div><div>This way, you may even avoid the new for `new', and use the procedure itself, i.e., with the same procedure or struct or class, you can simply write:<br>
<br></div><div>(define (fish name weight)<br></div><div> (list name weight))<br><br>and call it with:<br></div><div><br>(fish #:name "Nemo" #:weight 700)<br><br>or<br><br></div><div>(fish "Nemo" 700)<br>
<br></div><div>or<br><br></div><div>(fish "Nemo" #:weight 700)<br><br>and same for make-fish (for structs) and fish%. There would be no difference in the calling style between proc, struct and class.<br></div><div>
(Or maybe I misunderstood your point.)<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 17, 2013 at 5:28 PM, Neil Van Dyke <span dir="ltr"><<a href="mailto:neil@neilvandyke.org" target="_blank">neil@neilvandyke.org</a>></span> wrote: <br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im"></div>
I have used this in Python, and it is kinda neat and has its uses, but overall, I prefer the current way in Racket.<br>
<br>
One reason I prefer the current way in Racket is that, if every argument can be positional, then you have to keep this in mind when adding keyword arguments to a procedure that is used by other code: new arguments can only be added at the end of the list, even if that does not make the most sense for documentation purposes.<br>
</blockquote><div><br></div><div>Good point. Then one possibility is to allow to force an argument to be by-name only (I don't see a strong reason to allow to force an argument to be by-position only, except maybe to avoid bad proc-call habits, but not even sure).<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Another reason is that the keyword arguments restrict the syntax somewhat, so, when a mistaken extraneous sexp is where we'd expect a keyword, it is flagged as an error, rather than be considered a positional argument.<br>
<br>
Related to the previous reason, if the programmer is *intentionally* intermixing keyword arguments with positionals, such as "(foo 37 #:x 41 74 #:a 34)", that seems error-like that I wish they would get an error and change their ways.<br>
</blockquote><div><br></div><div>I agree, although less strongly than for the above point. I wouldn't mind to force calls to take positional arguments first, and have no more positional arguments after the first keyword.<br>
</div><div>(it actually seems to be easier to implement this way too.)<br></div><div>Though note that currently Racket does allow things like that:<br><br>(define (foo y #:x x )<br> (list x y))<br><br>(foo #:x 3 1) ; -> '(3 1)<br>
</div></div><br></div><div class="gmail_extra">Laurent<br></div></div>