[plt-scheme] struct copy with optional arguments
On Apr 2, Jon Rafkind wrote:
>
> ..BTW it would have been cool if I could have done
> (define/kw (copy obj #:key (field (field-accessor obj)) ...)
>
> instead of adding that ugly if. Can kw support something like that?
It does, both the 372 kw library:
> (require (lib "kw.ss"))
> (define/kw (foo a #:key [b (add1 a)] [c (* b 2)]) (list a b c))
> (foo 1)
(1 2 4)
> (foo 1 #:b 10)
(1 10 20)
and the built-in support in 3.99:
> (define (foo a #:b [b (add1 a)] #:c [c (* b 2)]) (list a b c))
> (foo 1)
(1 2 4)
> (foo 1 #:b 10)
(1 10 20)
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!