racket Functions Keyword arguments

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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.



Got any racket Question?