Function definition skeleton

A function definition tells Scheme the name of a new function and how it works. The skeleton of a function definition is a first draft, essentially translating the contract into Scheme syntax but not specifying how the function does its job. It has the following form:
(define (function-name parameter-name)
  ... )
You can also have functions with several parameters:
(define (function-name param-name another-param-name third-param-name)
  ... )
A function definition consists of several parts, each separated by a space (and anywhere you can put a space, you can also put a new line): The first four of these are collectively called the header, and traditionally go on one line, with the body starting on the next line.

Example:

(define (cube number)
   ... )
Note that the function-name and parameter-name can each be whatever you want, as long as each is a sequence of letters (and perhaps some punctuation marks, but no spaces). Typically the function-name is chosen to suggest what the function does, and the parameter-name is chosen to suggest the parameter's type or role.


Last modified: Mon Aug 25 12:01:51 EDT 2008
Stephen Bloch / sbloch@adelphi.edu