On this page:
3.1 Contract Types
contract?
flat-contract?
chaperone-contract?
impersonator-contract?
3.2 Reflection
contract-name
has-contract?
value-contract
has-blame?
value-blame
3.3 Trivial Contracts
any/  c
none/  c
3.4 Simple Combinators
∩/  c
∪/  c
¬/  c
if/  c
3.5 Procedure Contracts
λ/  c
any
8.12

3 Contracts🔗

Elle inherits Racket’s robust contract system.

3.1 Contract Types🔗

procedure

(contract? v)  boolean?

  v : any/c
Returns #true, if v is a contract; #false, otherwise.

procedure

(flat-contract? v)  boolean?

  v : any/c
Returns #true, if v is a flat contract; #false, otherwise.

procedure

(chaperone-contract? v)  boolean?

  v : any/c
Returns #true, if v is a chaperone contract; #false, otherwise.

procedure

(impersonator-contract? v)  boolean?

  v : any/c
Returns #true, if v is an impersonator contract; #false, otherwise.

3.2 Reflection🔗

procedure

(contract-name ctc)  any/c

  ctc : contract?
Returns the name of ctc, which is used in error reporting.

procedure

(has-contract? v)  boolean?

  v : any/c
Returns #true, if v is contracted; #false, otherwise.

procedure

(value-contract v)  (option/c contract?)

  v : any/c
Returns a present value containing the contract of v, if it has one; absent, otherwise.

procedure

(has-blame? v)  boolean?

  v : any/c
Returns #true, if v has a contract with blame information; #false, otherwise.

procedure

(value-blame v)  (option/c blame?)

  v : any/c
Returns a present value containing the blame informmation forthe contract of v, if it has one; absent, otherwise.

3.3 Trivial Contracts🔗

value

any/c : contract?

A flat contract which matches any single value.

value

none/c : contract?

A flat contract which matches no values.

3.4 Simple Combinators🔗

procedure

(∩/c contract ...)  contract?

  contract : contract?
Returns a contract that is satisfied only if every contract is satisfied.

procedure

(∪/c contract ...)  contract?

  contract : contract?
Returns a contract that is satisfied by any contract given. The resulting contract checks flat contracts first.

procedure

(¬/c contract)  flat-contract?

  contract : flat-contract?
Returns a flat contract that requires any value that does not match contract.

procedure

(if/c predicate then-contract else-contract)  contract?

  predicate : {λ/c any/c  boolean?}
  then-contract : contract?
  else-contract : contract?
Returns a contract that will first check predicate then, if the result is #true, will check then-contract; else-contract, otherwise.

3.5 Procedure Contracts🔗

syntax

{λ/c args-spec  result-spec}

 
args-spec = margs-spec maybe-oargs-spec maybe-rest
  | #:unconstrained
     
margs-spec = arg-ctc ... kw-arg ...
     
maybe-oargs-spec = 
  | [arg-ctc ... kw-arg ...]
     
kw-arg = #:<kw> arg-ctc
     
maybe-rest = 
  | arg-ctc ...
  | arg-ctc ...+
     
result-spec = result-ctc
  | (values result-ctc ...)
  | #:unconstrained
 
  arg-ctc : contract?
  result-ctc : contract?
Builds a contract that requires a procedure with the specified inputs and return result. The contract will be checked each time that the procedure is called and each time it returns.

syntax

any

A contract that is always satisfied. Used only in the result position of procedure contracts.

syntax

Used as a literal token in some forms. Not valid as an expression.