There are various approaches to optional named arguments in Scheme.
It's easy to define a procedure which accepts optional arguments:
(define (xyz . args) ...)
It's also possible to have the procedure itself handle named arguments:
(define (xyz . args)
(let ((args (append args '(x 10 y 20 z 30))))
(let ((x (cadr (member 'x args)))
(y (cadr (member 'y args)))
(z (cadr (member 'z args))))
(list x y z))))
The parameters 'x', 'y', and 'z' have default values 10, 20, and 30. Example:
> (xyz)
(10 20 30)
> (xyz 'x 100)
(100 20 30)
> (xyz 'y 200)
(10 200 30)
> (xyz 'z 300 'y 200 'x 100)
(100 200 300)
One property of that approach is that the named argument handling occurs at runtime, each time 'xyz' is called.
The 'named-arguments' macro takes a different approach. It generates a macro which is responsible for handling the named arguments at expand time. There is no overhead for handling the named arguments at runtime.
Define a 'point' record type:
(define-record-type point (fields x y))
This generates a 'make-point' constructor for us. Let's make a 'create-point' named arguments macro:
(named-arguments create-point ((x 0) (y 0)) make-point)
And try it out:
> (create-point)
#[point 0 0]
> (create-point (x 10))
#[point 10 0]
> (create-point (y 20))
#[point 0 20]
> (create-point (y 20) (x 10))
#[point 10 20]
> (create-point (x 10) (y 20))
#[point 10 20]
(xitomatl keywords) by Derick Eddington.