Assertions are a way of breaking out of code when there is an error or an unexpected input.

Some languages throw exceptions and some treat it as a break point.



Task

Show an assertion in your language by asserting that an integer variable is equal to 42.




#lang racket
 
(define/contract x
  (=/c 42) ; make sure x = 42
  42)
 
(define/contract f
  (-> number? (or/c 'yes 'no)) ; function contract
  (lambda (x)
    (if (= 42 x) 'yes 'no)))
 
(f 42)    ; succeeds
(f "foo") ; contract error!
 