Functions

To declare a new function use define, which has the following form:

(define (function-name parameter-names) body)

This creates a new function named function-name, which takes parameter-names as parameters. When the function is called, the parameter-names are initialized with the actual arguments. Then body is evaluated, and that becomes the result of the call.

For example in the factorial function we looked at recently, the function-name is factorial, and the parameter-names is x:

(define (factorial x)
  (if (< x 1) 1
  (* x (factorial (- x 1)))))

Anonymous functions

A lambda expression has the following form:

(lambda (parameter-names) body)

Optional and rest parameters

You can declare a function that takes optional argument, or variable number of arguments. You can also use keyword parameters. Read more here.