Tutorial by Examples

You can call a function in Racket by wrapping it in parentheses with the arguments after it. This looks like (function argument ...). > (define (f x) x) > (f 1) 1 > (f "salmon") "salmon" > (define (g x y) (string-append x y)) > (g "large" "sal...
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 ...
If you have a list, and you want to use the elements of that list as the arguments to a function, what you want is apply: > (apply string-append (list "hello" " " "and hi" " " "are both words")) "hello and hi are both words" > (app...
Functions in Racket can be created with the lambda form. The form takes a list of arguments and a body. (lambda (x y) (* x y)) In the example above, the function takes in two arguments and returns the result of multiplying them. > ((lambda (x y) (* x y)) 4 4) 16 > ((lambda (x y) (* x y)...

Page 1 of 1