Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Keyword arguments in R7RS

Name: Anonymous 2010-03-18 6:27

Things are getting spicy.
[quote]
Neil Van Dyke
To get the keyword arguments discussion started, I'll provide a quick,
loosely-defined strawperson...
* Keywords look like ":foo", "foo:", or "#:foo", depending on your dialect.
* The main use of keywords is to name "keyword arguments" in procedure
applications and syntax uses, such as for optional arguments or for clarity.
* "lambda" is extended to permit keyword arguments to be defined, each
of which argument may have a default value.  The argument is optional
iff a default value was defined.
* The various syntax definition forms should permit syntax transformers
to be keyword-aware as well.
* Example:
(define f (lambda (a b c (:foo 42) :bar)  foo))
(f 1 2 3 :foo 4 :bar 5) ==> 4
(f 1 2 3 :bar 5) ==> 42
(f 1 2 3) =error=> :bar keyword argument required
(f 1 2 3 :foo 4 :bar 5 :zoo 6) =error=> unrecognized keyword :zoo
* Note: If keywords are first-class values, and you want to pass a
keyword as an argument in an application in a position in which it might
be parsed as a keyword, you cannot put  a keyword literal into the
application syntax directly.
* I probably wouldn't have keyword arguments in WG2, but their
implementation in WG2 would likely impose requirements on WG1.
--
[/quote]

Working Group 1 thread:
https://groups.google.com/group/scheme-reports-wg1/browse_frm/thread/3c0c5a48a520f32d
or
Working Group 2 thread:
https://groups.google.com/group/scheme-reports-wg2/browse_frm/thread/4f4b2a9a0eb86450

...what do the resident clispers in prague think? Should they exist in the core language or should we have a supplementary (i.e. "defun" in all its glory) macro for WG2 Scheme?

Name: Anonymous 2010-03-18 17:32

>>12
Making the code more verbose isn't inherently a bad thing, It can be useful if it makes the code more clear. I mean what does point(1,2,3); mean? Does it mean that it has three co-ordinates, or does it have 2 and say a color value of 3? How can we know without looking at the documentation? The order of the parameters isn't always useful in determining what a function means. It may be more illuminating to have point(x=1,y=2,z=3); or point(x=1, y=2, color=3); or indeed point(x=1, color=2, y=3. Now, we no longer need to know the argument order.
To take a more schemey example, the function number->string takes a number and an optional radix.
(number->string 12) ;=>"12"
(number->string 12 2) ;=>"1100"
If we imagine we wanted a more general number->string that takes one or more numbers and e.g. converts all the numbers and then concatentates them, then the logical extension would be to add more parameters to the end with a dotted list. But then we have a problem that if we want to take 2 or more numbers we need to supply the radix i.e.
(number->string 12 2) ;=>"1100" not what we want
(number->string 12 10 2) ;=> "122"
This requires extra arguments and makes the resulting code less clear. If radix was always a keyword parameter, then we could write
(number->string 12 2) ;=>"122"
(number->string 12 2 #:radix 2) ;=> "110010"

The important thing is not "How verbose is this", but "how readable is this".

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List