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 20:02

>>20
Could you explain how they don't obey lexical scope or cause name clashes? Some examples maybe?
I'm only familiar with them from CL, I don't know how different they are in Scheme than in CL. In CL, keywords are plain old symbols which lie in the KEYWORD package, which can be thought of as having an empty nickname, so you can write :some-keyword and the name would get interned(if it didn't exist) in said KEYWORD package. When you use a keyword, you do pollute said KEYWORD package, but that's not really a problem, as that's the intended purpose of the package - to simply store global names which can be used anywhere, as opposed to symbols which are interned in the current *package* or some other package. #:symbol is an uninterned symbol and (eq '#:symbol '#:symbol);=> NIL, but (let ((sym '#:symbol)) (eq sym sym)) ;=> T.

Keyword arguments could be implemented portably by just taking the entire argument list and destructuring it(or a limited form of destructuring, depending on what you're defining - a function, a macro, ...) according to its lambda list. Of course compilers are free to implement this much more efficiently, in ways that don't involve consing up argument lists (such as defining a compiler macro which does the destructuring at compile-time when possible (always possible except in cases of FUNCALL/APPLY usage) and calling a function/lambda with a constant number of args - this optimization is applicable for optional args as well).

What I'm confused about is where the problem you mentioned lies. The only problem I can see with keywords is that in CL, they require a junk package to be implemented, but if you think about it, there's nothing wrong about it, as long as you don't use keywords for other things than what they're meant to be used for.

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