Racket functions can also have keyword arguments, which are specified with a keyword followed by the argument expression. A keyword begins with the characters #:
, so a keyword argument looks like #:keyword arg-expr
. Within a function call this looks like (function #:keyword arg-expr)
.
> (define (hello #:name n)
(string-append "Hello " n))
> (hello #:name "John")
"Hello John"
> (hello #:name "Sarah")
"Hello Sarah"
> (define (kinetic-energy #:mass m #:velocity v)
(* 1/2 m (sqr v)))
> (kinetic-energy #:mass 2 #:velocity 1)
1
> (kinetic-energy #:mass 6 #:velocity 2)
12
For more information and examples, see Keyword Arguments in the Racket Guide.