Contracts

We have been writing signatures for functions by using comments.

 ; double-it: number -> number

This works fine for organizing your thoughts, but it would be nice if Racket could actually stop you from doing something different from what you said you would do.

Intermediate student mode is required to use contracts. (require racket/contract)

  • Contract Intro
  • An introduction to using contracts.

  • Contract for Structs
  • When you are working with a structure, the best way to make sure it does not get “broken” is to write a function to check that each part of the struct has the correct type.