[plt-scheme] keyword arguments (in v4.0, maybe)
At Tue, 12 Jun 2007 00:21:33 -0700, John Clements wrote:
>
> On Jun 12, 2007, at 12:08 AM, Matthew Flatt wrote:
>
> > At Tue, 12 Jun 2007 02:55:27 -0400, Eli Barzilay wrote:
> >>> One drawback of this strategy is that `(lambda args (apply f args))'
> >>> is not an all-purpose wrapper strategy, because that only works for
> >>> `f' that doesn't take keyword arguments. But there would be a new
> >>> way to create wrappers that works for both plain and
> >>> keyword-accepting procedures.
> >>
> >> Note that this one is a radical change. It means that using keywords
> >> will "infect" code: using keyword-unaware code will not be possible
> >> with keyword aware code. For example, SRFI code (or any portable
> >> Scheme code) can assume that
> >>
> >> (lambda args (apply f args))
> >>
> >> is exactly equivalent to `f' -- but this will not be the case for
> >> keyword procedures.
> >
> > Of course, it's also not the case for numbers, lists, regexps, etc.
> >
> > So probably `procedure?' should return #f for things that are like
> > procedures, but that require some keyword (as opposed to things that
> > work like procedures and accept keyword-based arguments, but all the
> > keyword arguments all optional). Then, the above remains true for
> > procedures.
> >
> > Meanwhile, it's true that there's a kind of infection to the
> > design, in
> > that many tools and libraries should be made to work with both
> > procedures and keyword-requiring things. But maybe working only for
> > procedures (that don't require any keywords) is a reasonable
> > specification for other tools and libraries.
> >
> > What examples do we have, other than `trace'?
>
> IIUC, this would include my tiny no-brainer tool, perhaps check
> syntax, the stepper (if keywords affect teaching languages).
Tools that work on expanded code won't have to change, I think, because
keyword arguments would be implemented as a library. And I don't expect
that keyword arguments would affect the teaching languages.
> How about the contract system? Can you write contracts for these things?
I'll leave this to Robby, but the intent is certainly to have contracts
for keyword-based procedures.
> What would the expansion look like?
The expression
(lambda (x #:y y) (list x y))
would expand to something like
(make-keyword-procedure-with-info
(lambda (kws x) (list a (cdar kws)))
'(#:y) ; required
'()) ; optional
The expression
(f 1 #:y 2)
would expand to something like
(let ([r f]
[a1 1]
[a2 2])
(keyword-apply r (list (cons #:y a2)) a1))
Matthew