[racket-dev] Keywords
On Mon, Jun 17, 2013 at 5:09 PM, Matthias Felleisen <matthias at ccs.neu.edu>wrote:
>
> p.s. On second thought, for structs you want two constructors:
> -- one that takes positional arguments
> -- one that takes keyword arguments
>
My intent was that you could use both positional and keyword arguments at
the same time, for each argument.
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:
(define (fish name weight)
(list name weight))
and call it with:
(fish #:name "Nemo" #:weight 700)
or
(fish "Nemo" 700)
or
(fish "Nemo" #:weight 700)
and same for make-fish (for structs) and fish%. There would be no
difference in the calling style between proc, struct and class.
(Or maybe I misunderstood your point.)
On Mon, Jun 17, 2013 at 5:28 PM, Neil Van Dyke <neil at neilvandyke.org>wrote:
> I have used this in Python, and it is kinda neat and has its uses, but
> overall, I prefer the current way in Racket.
>
> 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.
>
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).
> 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.
>
> 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.
>
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.
(it actually seems to be easier to implement this way too.)
Though note that currently Racket does allow things like that:
(define (foo y #:x x )
(list x y))
(foo #:x 3 1) ; -> '(3 1)
Laurent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20130624/378651f6/attachment-0001.html>