▼ |  | Unstable

1 | Guidelines for developing unstable libraries
2 | Bytes
3 | Contracts
4 | Exceptions
5 | Lists
6 | Net
7 | Path
8 | Source Locations
9 | Strings
10 | Structs
11 | Syntax
12 | Anaphoric Contracts
13 | Finding Mutated Variables
14 | Find
15 | Interface-Oriented Programming for Classes
16 | Sequences
17 | Hash Tables
18 | Match
19 | Skip Lists
20 | Interval Maps
21 | GUI libraries

On this page:

non-empty-string/ c
port-number?
path-element?
if/ c
rename-contract

top← prev up next →

### 3`` Contracts

(require unstable/contract)

This library is unstable; compatibility will not be maintained. See Unstable for more information.

non-empty-string/c : contract?

Contract for non-empty strings.

port-number? : contract?

Equivalent to (between/c 1 65535).

path-element? : contract?

Equivalent to (or/c path-string? (symbols 'up 'same)).

> > > The subsequent bindings were added by Ryan Culpepper.

(if/c predicate then-contract else-contract) → contract?
predicate : (-> any/c any/c)
then-contract : contract?
else-contract : contract?

Produces a contract that, when applied to a value, first tests the value with predicate; if predicate returns true, the then-contract is applied; otherwise, the else-contract is applied. The resulting contract is a flat contract if both then-contract and else-contract are flat contracts.

For example, the following contract enforces that if a value is a procedure, it is a thunk; otherwise it can be any (non-procedure) value:
(if/c procedure? (-> any) any/c)
Note that the following contract is not equivalent:
(or/c (-> any) any/c) ; wrong!
The last contract is the same as any/c because or/c tries flat contracts before higher-order contracts.

(rename-contract contract name) → contract?
contract : contract?
name : any/c

Produces a contract that acts like contract but with the name name.

The resulting contract is a flat contract if contract is a flat contract.

top← prev up next →