#### 3.18.4 Do Loops
> ```
syntax
(do ([id init-expr step-expr-maybe] ...)
> ( stop?-expr finish-expr ... )
> expr ... )
step-expr-maybe   =
    |   step-expr
```
Iteratively evaluates the exprs for as long as stop?-expr returns #f.

To initialize the loop, the init-exprs are evaluated in order and bound to the corresponding ids. The ids are bound in all expressions within the form other than the init-exprs.

After the ids have been bound, the stop?-expr is evaluated. If it produces #f, each expr is evaluated for its side-effect. The ids are then effectively updated with the values of the step-exprs, where the default step-expr for id is just id; more precisely, iteration continues with fresh locations for the ids that are initialized with the values of the corresponding step-exprs.

When stop?-expr produces a true value, then the finish-exprs are evaluated in order, and the last one is evaluated in tail position to produce the overall value for the do form. If no finish-expr is provided, the value of the do form is #<void>.

------------------------------------------------------------------------

# 3.19 Continuation Marks: with-continuation-mark

### 3.19 Continuation Marks: with-continuation-mark

>
<colgroup><col style="width: 100%" /></colgroup>

syntax

(with-continuation-mark key-expr val-expr result-expr)

The key-expr, val-expr, and result-expr expressions are evaluated in order. After key-expr is evaluated to obtain a key and val-expr is evaluated to obtain a value, the key is mapped to the value as a continuation mark in the current continuation’s initial continuation frame. If the frame already has a mark for the key, the mark is replaced. Finally, the result-expr is evaluated; the continuation for evaluating result-expr is the continuation of the with-continuation-mark expression (so the result of the result-expr is the result of the with-continuation-mark expression, and result-expr is in tail position for the with-continuation-mark expression).

> > > Continuation Marks provides more information on continuation marks.

------------------------------------------------------------------------

# 3.20 Quasiquoting: quasiquote, unquote, and unquote-splicing

### 3.20 Quasiquoting: quasiquote, unquote, and unquote-splicing

> > > Quasiquoting: quasiquote and ‘ in The Racket Guide introduces quasiquote.

>
<colgroup><col style="width: 100%" /></colgroup>

syntax

(quasiquote datum)

The same as 'datum if datum does not include (unquote expr) or (unquote-splicing expr). An (unquote expr) form escapes from the quote, however, and the result of the expr takes the place of the (unquote expr) form in the quasiquote result. An (unquote-splicing expr) similarly escapes, but the expr produces a list whose elements are spliced as multiple values place of the (unquote-splicing expr).

An unquote or unquote-splicing form is recognized in any of the following escaping positions within datum: in a pair, in a vector, in a box, in a prefab structure field after the name position, and in hash table value position (but not in a hash table key position). Such escaping positions can be nested to an arbitrary depth.

An unquote-splicing form must appear as the car of a quoted pair, as an element of a quoted vector, or as an element of a quoted prefab structure. In the case of a pair, if the cdr of the relevant quoted pair is empty, then expr need not produce a list, and its result is used directly in place of the quoted pair (in the same way that append accepts a non-list final argument).

If unquote or unquote-splicing appears within quasiquote in an escaping position but in a way other than as (unquote expr) or (unquote-splicing expr), a syntax error is reported.

Examples:

> ```racket
> > ( quasiquote ( 0 1 2 ) )
> '(0 1 2)
> > ( quasiquote ( 0 ( unquote ( + 1 2 ) ) 4 ) )
> '(0 3 4)
> > ( quasiquote ( 0 ( unquote-splicing ( list 1 2 ) ) 4 ) )
> '(0 1 2 4)
> > ( quasiquote ( 0 ( unquote-splicing 1 ) 4 ) )
> unquote-splicing: contract violation
> expected: list?
> given: 1
> > ( quasiquote ( 0 ( unquote-splicing 1 ) ) )
> '(0 . 1)
> ```

A quasiquote, unquote, or unquote-splicing form is typically abbreviated with \`, ,, or ,@, respectively. See also Reading Quotes.

Examples:

> ```racket
> > ` ( 0 1 2 )
> '(0 1 2)
> > ` ( 1 , ( + 1 2 ) 4 )
> '(1 3 4)
> > ` #s ( stuff 1 , ( + 1 2 ) 4 )
> '#s(stuff 1 3 4)
> > ` #hash ( ( "a" . , ( + 1 2 ) ) )
> '#hash(("a" . 3))
> > ` #hash ( ( , ( + 1 2 ) . "a" ) )
> '#hash((,(+ 1 2) . "a"))
> > ` ( 1 ,@ ( list 1 2 ) 4 )
> '(1 1 2 4)
> > ` # ( 1 ,@ ( list 1 2 ) 4 )
> '#(1 1 2 4)
> ```

A quasiquote form within the original datum increments the level of quasiquotation: within the quasiquote form, each unquote or unquote-splicing is preserved, but a further nested unquote or unquote-splicing escapes. Multiple nestings of quasiquote require multiple nestings of unquote or unquote-splicing to escape.

Examples:

> ```racket
> > ` ( 1 ` , ( + 1 , ( + 2 3 ) ) 4 )
> '(1 `,(+ 1 5) 4)
> > ` ( 1 ` ` ` , ,@ , ,@ ( list ( + 1 2 ) ) 4 )
> '(1 ```,,@,3 4)
> ```

The quasiquote form allocates only as many fresh cons cells, vectors, and boxes as are needed without analyzing unquote and unquote-splicing expressions. For example, in

> \`(,1 2 3)

a single tail '(2 3) is used for every evaluation of the quasiquote expression. When allocating fresh data, the quasiquote form allocates mutable vectors, mutable boxes and immutable hashes.

Examples:

> ```racket
> > ( immutable? ` # ( , 0 ) )
> #f
> > ( immutable? ` #hash ( ( a . , 0 ) ) )
> #t
> ```

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>unquote</p></blockquote></td></tr></tbody></table>

See quasiquote, where unquote is recognized as an escape. An unquote form as an expression is a syntax error.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>unquote-splicing</p></blockquote></td></tr></tbody></table>

See quasiquote, where unquote-splicing is recognized as an escape. An unquote-splicing form as an expression is a syntax error.

------------------------------------------------------------------------

# 3.21 Syntax Quoting: quote-syntax

### 3.21 Syntax Quoting: quote-syntax

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(quote-syntax datum)</p></blockquote></td></tr><tr><td>(quote-syntax datum #:local)</td></tr></tbody></table>

Similar to quote, but produces a syntax object that preserves the lexical information and source-location information attached to datum at expansion time.

When #:local is specified, then all scopes in the syntax object’s lexical information are preserved. When #:local is omitted, then the scope sets within datum are pruned to omit the scope for any binding form that appears between the quote-syntax form and the enclosing top-level context, module body, or phase level crossing, whichever is closer.

Unlike syntax (#'), quote-syntax does not substitute pattern variables bound by with-syntax, syntax-parse, or syntax-case.

Examples:

> ```racket
> > ( syntax? ( quote-syntax x ) )
> #t
> > ( quote-syntax ( 1 2 3 ) )
> #<syntax:eval:78:0 (1 2 3)>
> > ( with-syntax ( [ a #' 5 ] ) ( quote-syntax ( a b c ) ) )
> #<syntax:eval:79:0 (a b c)>
> > ( free-identifier=? ( let ( [ x 1 ] ) ( quote-syntax x ) ) ( quote-syntax x ) )
> #t
> > ( free-identifier=? ( let ( [ x 1 ] ) ( quote-syntax x #:local ) ) ( quote-syntax x ) )
> #f
> ```

Changed in version 6.3 of package base: Added scope pruning and support for #:local.

------------------------------------------------------------------------

# 3.22 Interaction Wrapper: #%top-interaction

### 3.22 Interaction Wrapper: #%top-interaction

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(#%top-interaction . form)</p></blockquote></td></tr></tbody></table>

Expands to simply form. The #%top-interaction form is similar to #%app and #%module-begin, in that it provides a hook to control interactive evaluation through load (more precisely, the default load handler) or read-eval-print-loop.

------------------------------------------------------------------------

# 3.23 Blocks: block

### 3.23 Blocks: block

|  |  |
|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  (require [racket/block]()) |  package: base |

The bindings documented in this section are provided by the [racket/block]() library, not racket/base or racket.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(block defn-or-expr ...)</p></blockquote></td></tr></tbody></table>

Supports a mixture of expressions and mutually recursive definitions, as in a module body. Unlike an internal-definition context, the last defn-or-expr need not be an expression.

The result of the block form is the result of the last defn-or-expr if it is an expression, #<void> otherwise. If no defn-or-expr is provided (after flattening begin forms), the result is #<void>.

The final defn-or-expr is executed in tail position, if it is an expression.

Examples:

> ```racket
> > ( define ( f x ) ( block ( define y ( add1 x ) ) ( displayln y ) ( define z ( * 2 y ) ) ( + 3 z ) ) )
> > ( f 12 )
> 13
> 29
> ```

------------------------------------------------------------------------

# 3.24 Internal-Definition Limiting: #%stratified-body

### 3.24 Internal-Definition Limiting: #%stratified-body

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(#%stratified-body defn-or-expr ...)</p></blockquote></td></tr></tbody></table>

Like (let () defn-or-expr ...) for an internal-definition context sequence, except that an expression is not allowed to precede a definition, and all definitions are treated as referring to all other definitions (i.e., locations for variables are all allocated first, like letrec and unlike letrec-syntaxes+values).

The #%stratified-body form is useful for implementing syntactic forms or languages that supply a more limited kind of internal-definition context.

------------------------------------------------------------------------

# 3.25 Performance Hints: begin-encourage-inline

### 3.25 Performance Hints: begin-encourage-inline

|  |  |
|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  (require [racket/performance-hint]()) |  package: base |

The bindings documented in this section are provided by the [racket/performance-hint]() library, not racket/base or racket.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(begin-encourage-inline form ...)</p></blockquote></td></tr></tbody></table>

Attaches a 'compiler-hint:cross-module-inline syntax property to each form, which is useful when a form is a function definition. See define-values.

The begin-encourage-inline form is also provided by the (submod racket/performance-hint begin-encourage-inline) module, which has fewer dependencies than [racket/performance-hint]().

Changed in version 6.2 of package base: Added the (submod racket/performance-hint begin-encourage-inline) submodule.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(define-inline id expr)</p></blockquote></td></tr><tr><td>(define-inline (head args) body ...+)</td></tr><tr><td> </td></tr><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: right;" data-valign="baseline">head</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">=</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">id</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">(head args)</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td></tr><tr><td style="text-align: right;" data-valign="baseline">args</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">=</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">arg ...</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">arg ... . rest-id</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td></tr><tr><td style="text-align: right;" data-valign="baseline">arg</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">=</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">arg-id</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">[arg-id default-expr]</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">keyword arg-id</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">keyword [arg-id default-expr]</td></tr></tbody></table></td></tr></tbody></table>

Like define, but ensures that the definition will be inlined at its call sites. Recursive calls are not inlined, to avoid infinite inlining. Higher-order uses are supported, but also not inlined. Misapplication (by supplying the wrong number of arguments or incorrect keyword arguments) is also not inlined and left as a run-time error.

The define-inline form may interfere with the Racket compiler’s own inlining heuristics, and should only be used when other inlining attempts (such as begin-encourage-inline) fail.

Changed in version 8.1.0.5 of package base: Changed to treat misapplication as a run-time error.

------------------------------------------------------------------------

# 3.26 Importing Modules Lazily: lazy-require

### 3.26 Importing Modules Lazily: lazy-require

|  |  |
|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  (require [racket/lazy-require]()) |  package: base |

The bindings documented in this section are provided by the [racket/lazy-require]() library, not racket/base or racket.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(lazy-require [module-path (fun-import ...)] ...)</p></blockquote></td></tr><tr><td> </td></tr><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: right;" data-valign="baseline">fun-import</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">=</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">fun-id</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">(orig-fun-id fun-id)</td></tr></tbody></table></td></tr></tbody></table>

Defines each fun-id as a function that, when called, dynamically requires the export named orig-fun-id from the module specified by module-path and calls it with the same arguments. If orig-fun-id is not given, it defaults to fun-id.

If the enclosing relative phase level is not 0, then module-path is also placed in a submodule (with a use of define-runtime-module-path-index at phase level 0 within the submodule). Introduced submodules have the names lazy-require-auxn-m, where n is a phase-level number and m is a number.

When the use of a lazily-required function triggers module loading, it also triggers a use of register-external-module to declare an indirect compilation dependency (in case the function is used in the process of compiling a module).

Examples:

> ```racket
> > ( lazy-require [ racket/list ( partition ) ] )
> > ( partition even? ' ( 1 2 3 4 5 ) )
> '(2 4) '(1 3 5)
> > ( module hello racket/base ( provide hello ) ( printf "starting hello server\n" ) ( define ( hello ) ( printf "hello!\n" ) ) )
> > ( lazy-require [ ' hello ( [ hello greet ] ) ] )
> > ( greet )
> starting hello server hello!
> ```

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(lazy-require-syntax [module-path (macro-import ...)] ...)</p></blockquote></td></tr><tr><td> </td></tr><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: right;" data-valign="baseline">macro-import</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">=</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">macro-id</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">(orig-macro-id macro-id)</td></tr></tbody></table></td></tr></tbody></table>

Like lazy-require but for macros. That is, it defines each macro-id as a macro that, when used, dynamically loads the macro’s implementation from the given module-path. If orig-macro-id is not given, it defaults to macro-id.

Use lazy-require-syntax in the implementation of a library with large, complicated macros to avoid a dependence from clients of the library on the macro “compilers.” Note that only macros with exceptionally large compile-time components (such as Typed Racket, which includes a type checker and optimizer) benefit from lazy-require-syntax; typical macros do not.

Warning: lazy-require-syntax breaks the invariants that Racket’s module loader and linker rely on; these invariants normally ensure that the references in code produced by a macro are loaded before the code runs. Safe use of lazy-require-syntax requires a particular structure in the macro implementation. (In particular, lazy-require-syntax cannot simply be introduced in the client code.) The macro implementation must follow these rules:

1.  the interface module must require the runtime-support module

2.  the compiler module must require the runtime-support module via an absolute module path rather than a relative path

To explain the concepts of “interface, compiler, and runtime-support modules”, here is an example module that exports a macro:

> ```racket
> ( module original racket/base
> ( define ( ntimes-proc n thunk )
> ( for ( [ i ( in-range n ) ] ) ( thunk ) ) )
> ( define-syntax-rule ( ntimes n expr )
> ( ntimes-proc n ( lambda ( ) expr ) ) )
> ( provide ntimes ) )
> ```

Suppose we want to use lazy-require-syntax to lazily load the implementation of the ntimes macro transformer. The original module must be split into three parts:

> ```racket
> ( module runtime-support racket/base
> ( define ( ntimes-proc n thunk )
> ( for ( [ i ( in-range n ) ] ) ( thunk ) ) )
> ( provide ntimes-proc ) )
> ( module compiler racket/base
> ( require ' runtime-support )
> ( define-syntax-rule ( ntimes n expr )
> ( ntimes-proc n ( lambda ( ) expr ) ) )
> ( provide ntimes ) )
> ( module interface racket/base
> ( require racket/lazy-require )
> ( require ' runtime-support )
> ( lazy-require-syntax [ ' compiler ( ntimes ) ] )
> ( provide ntimes ) )
> ```

The runtime support module contains the function and value definitions that the macro refers to. The compiler module contains the macro definition(s) themselves—the part of the code that “disappears” after compile time. The interface module lazily loads the macro transformer, but it makes sure the runtime support module is defined at run time by requiring it normally. In a larger example, of course, the runtime support and compiler may both consist of multiple modules.

Here what happens when we don’t separate the runtime support into a separate module:

> ```racket
> > ( module bad-no-runtime racket/base ( define ( ntimes-proc n thunk ) ( for ( [ i ( in-range n ) ] ) ( thunk ) ) ) ( define-syntax-rule ( ntimes n expr ) ( ntimes-proc n ( lambda ( ) expr ) ) ) ( provide ntimes ) )
> > ( module bad-client racket/base ( require racket/lazy-require ) ( lazy-require-syntax [ ' bad-no-runtime ( ntimes ) ] ) ( ntimes 3 ( printf "hello?\n" ) ) )
> > ( require ' bad-client )
> require: namespace mismatch;
> reference to a module that is not instantiated
> module: 'bad-no-runtime
> phase: 0
> ```

A similar error occurs when the interface module doesn’t introduce a dependency on the runtime support module.

------------------------------------------------------------------------

# 4 Datatypes

## 4 Datatypes

> > > <img src="finger.png" width="24" height="24" alt="+" />Built-In Datatypes in The Racket Guide introduces Datatypes.

Each pre-defined datatype comes with a set of procedures for manipulating instances of the datatype.

|  |
|-------------------------------------------------------------------------------------|
|     4.1 Equality  |
|     4.2 Booleans  |
|     4.3 Numbers  |
|     4.4 Strings  |
|     4.5 Byte Strings  |
|     4.6 Characters  |
|     4.7 Symbols  |
|     4.8 Regular Expressions  |
|     4.9 Keywords  |
|     4.10 Pairs and Lists  |
|     4.11 Mutable Pairs and Lists  |
|     4.12 Vectors  |
|     4.13 Stencil Vectors  |
|     4.14 Boxes  |
|     4.15 Hash Tables  |
|     4.16 Treelists  |
|     4.17 Sequences and Streams |
|     4.18 Dictionaries  |
|     4.19 Sets  |
|     4.20 Procedures  |
|     4.21 Void  |
|     4.22 Undefined  |

------------------------------------------------------------------------

# 4.1 Equality

8.18.0.13

### 4.1 Equality

Equality is the concept of whether two values are “the same.” Racket supports a few different kinds of equality by default, although equal? is preferred for most uses.

> ```
(equal? v1 v2) → boolean?
  v1 : any/c
  v2 : any/c```

Two values are [equal?](#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29) if and only if they are [eqv?](#%28def._%28%28quote._~23~25kernel%29._eqv~3f%29%29), unless otherwise specified for a particular datatype.

Datatypes with further specification of [equal?](#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29) include strings, byte strings, pairs, mutable pairs, vectors, boxes, hash tables, and inspectable structures. In the last six cases, equality is recursively defined; if both v1 and v2 contain reference cycles, they are equal when the infinite unfoldings of the values would be equal. See also [gen:equal+hash](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._gen~3aequal%2Bhash%29%29) and [prop:impersonator-of](chaperones.html#%28def._%28%28quote._~23~25kernel%29._prop~3aimpersonator-of%29%29).

Examples:

> ```racket
> > ( equal? ' yes ' yes )
> #t
> > ( equal? ' yes ' no )
> #f
> > ( equal? ( * 6 7 ) 42 )
> #t
> > ( equal? ( expt 2 100 ) ( expt 2 100 ) )
> #t
> > ( equal? 2 2.0 )
> #f
> > ( let ( [ v ( mcons 1 2 ) ] ) ( equal? v v ) )
> #t
> > ( equal? ( mcons 1 2 ) ( mcons 1 2 ) )
> #t
> > ( equal? ( integer->char 955 ) ( integer->char 955 ) )
> #t
> > ( equal? ( make-string 3 #\z ) ( make-string 3 #\z ) )
> #t
> > ( equal? #t #t )
> #t
> ```

> ```
(equal-always? v1 v2)  →  boolean?
  v1 : any/c
  v2 : any/c
```


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
Indicates whether v1 and v2 are equal and will always stay equal independent of mutations. Generally, for two values to be equal-always, corresponding immutable values within v1 and v2 must be equal?, while corresponding mutable values within them must be eq?. Precedents for this operator in other languages include egal \[Baker93\].
Two values v1 and v2 are equal-always? if and only if there exists a third value v3 such that v1 and v2 are both chaperones of v3, meaning (chaperone-of? v1 v3) and (chaperone-of? v2 v3) are both true.
For values that include no chaperones or other impersonators, v1 and v2 can be considered equal-always if they are equal?, except that corresponding mutable vectors, boxes, hash tables, strings, byte strings, mutable pairs, and mutable structures within v1 and v2 must be eq?, and equality on structures can be specialized for equal-always? through gen:equal-mode+hash.
Examples:


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
> ```racket
> > ( equal-always? ' yes ' yes )
> #t
> > ( equal-always? ' yes ' no )
> #f
> > ( equal-always? ( * 6 7 ) 42 )
> #t
> > ( equal-always? ( expt 2 100 ) ( expt 2 100 ) )
> #t
> > ( equal-always? 2 2.0 )
> #f
> > ( equal-always? ( list 1 2 ) ( list 1 2 ) )
> #t
> > ( let ( [ v ( mcons 1 2 ) ] ) ( equal-always? v v ) )
> #t
> > ( equal-always? ( mcons 1 2 ) ( mcons 1 2 ) )
> #f
> > ( equal-always? ( integer  →  char 955 ) ( integer  →  char 955 ) )
> #t
> > ( equal-always? ( make-string 3 #\z ) ( make-string 3 #\z ) )
> #f
> > ( equal-always? ( string  →  immutable-string ( make-string 3 #\z ) ) ( string  →  immutable-string ( make-string 3 #\z ) ) )
> #t
> > ( equal-always? #t #t )
> #t
> ```
Added in version 8.5.0.3 of package base.
> ```
(eqv? v1 v2) → boolean?
  v1 : any/c
  v2 : any/c```
Two values are [eqv?](#%28def._%28%28quote._~23~25kernel%29._eqv~3f%29%29) if and only if they are [eq?](#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29), unless otherwise specified for a particular datatype.


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
The [number](numbers.html#%28tech._number%29) and [character](characters.html#%28tech._character%29) datatypes are the only ones for which [eqv?](#%28def._%28%28quote._~23~25kernel%29._eqv~3f%29%29) differs from [eq?](#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29). Two numbers are [eqv?](#%28def._%28%28quote._~23~25kernel%29._eqv~3f%29%29) when they have the same exactness, precision, and are both equal and non-zero, both +0.0, both +0.0f0, both -0.0, both -0.0f0, both +nan.0, or both +nan.f—considering real and imaginary components separately in the case of [complex numbers](numbers.html#%28tech._complex._number%29). Two characters are [eqv?](#%28def._%28%28quote._~23~25kernel%29._eqv~3f%29%29) when their [char->integer](characters.html#%28def._%28%28quote._~23~25kernel%29._char-~3einteger%29%29) results are equal.
Generally, [eqv?](#%28def._%28%28quote._~23~25kernel%29._eqv~3f%29%29) is identical to [equal?](#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29) except that the former cannot recursively compare the contents of compound data types (such as lists and structs) and cannot be customized by user-defined data types. The use of [eqv?](#%28def._%28%28quote._~23~25kernel%29._eqv~3f%29%29) is lightly discouraged in favor of [equal?](#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29).
Examples:


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
> ```racket
> > ( eqv? ' yes ' yes )
> #t
> > ( eqv? ' yes ' no )
> #f
> > ( eqv? ( * 6 7 ) 42 )
> #t
> > ( eqv? ( expt 2 100 ) ( expt 2 100 ) )
> #t
> > ( eqv? 2 2.0 )
> #f
> > ( let ( [ v ( mcons 1 2 ) ] ) ( eqv? v v ) )
> #t
> > ( eqv? ( mcons 1 2 ) ( mcons 1 2 ) )
> #f
> > ( eqv? ( integer->char 955 ) ( integer->char 955 ) )
> #t
> > ( eqv? ( make-string 3 #\z ) ( make-string 3 #\z ) )
> #f
> > ( eqv? #t #t )
> #t
> ```
> ```
(eq? v1 v2)  →  boolean?
  v1 : any/c
  v2 : any/c


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
```
Return #t if v1 and v2 refer to the same object, #f otherwise. As a special case among numbers, two fixnums that are = are also the same according to eq?. See also Object Identity and Comparisons.

Examples:

> ```racket
> > ( eq? ' yes ' yes )
> #t
> > ( eq? ' yes ' no )
> #f
> > ( eq? ( * 6 7 ) 42 )
> #t
> > ( eq? ( expt 2 100 ) ( expt 2 100 ) )
> #f
> > ( eq? 2 2.0 )
> #f
> > ( let ( [ v ( mcons 1 2 ) ] ) ( eq? v v ) )
> #t
> > ( eq? ( mcons 1 2 ) ( mcons 1 2 ) )
> #f
> > ( eq? ( integer  →  char 955 ) ( integer  →  char 955 ) )
> #t
> > ( eq? ( make-string 3 #\z ) ( make-string 3 #\z ) )
> #f
> > ( eq? #t #t )
> #t
> ```

> ```
(equal?/recur v1 v2 recur-proc) → boolean?
  v1 : any/c
  v2 : any/c
  recur-proc : (any/c any/c .  →  . any/c)```

Like [equal?](#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29), but using recur-proc for recursive comparisons (which means that reference cycles are not handled automatically). Non-#f results from recur-proc are converted to #t before being returned by [equal?/recur](#%28def._%28%28quote._~23~25kernel%29._equal~3f%2Frecur%29%29).

Examples:

> ```racket
> > ( equal?/recur 1 1 ( lambda ( a b ) #f ) )
> #t
> > ( equal?/recur ' ( 1 ) ' ( 1 ) ( lambda ( a b ) #f ) )
> #f
> > ( equal?/recur ' # ( 1 1 1 ) ' # ( 1 1.2 3/4 ) ( lambda ( a b ) ( <= ( abs ( - a b ) ) 0.25 ) ) )> #t
> ```

> ```
(equal-always?/recur v1 v2 recur-proc)  →  boolean?
  v1 : any/c
  v2 : any/c
  recur-proc : (any/c any/c .  →  . any/c)
```


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
Like equal-always?, but using recur-proc for recursive comparisons (which means that reference cycles are not handled automatically). Non-#f results from recur-proc are converted to #t before being returned by equal-always?/recur.
Examples:
> ```racket
> > ( equal-always?/recur 1 1 ( lambda ( a b ) #f ) )
> #t
> > ( equal-always?/recur ' ( 1 ) ' ( 1 ) ( lambda ( a b ) #f ) )
> #f
> > ( equal-always?/recur ( vector-immutable 1 1 1 ) ( vector-immutable 1 1.2 3/4 ) ( lambda ( a b ) ( <= ( abs ( - a b ) ) 0.25 ) ) )> #t
> ```


#### 4.1.1 Object Identity and Comparisons
The eq? operator compares two values, returning #t when the values refer to the same object. This form of equality is suitable for comparing objects that support imperative update (e.g., to determine that the effect of modifying an object through one reference is visible through another reference). Also, an eq? test evaluates quickly, and eq?-based hashing is more lightweight than equal?-based hashing in hash tables.
In some cases, however, eq? is unsuitable as a comparison operator, because the generation of objects is not clearly defined. In particular, two applications of + to the same two exact integers may or may not produce results that are eq?, although the results are always equal?. Similarly, evaluation of a lambda form typically generates a new procedure object, but it may re-use a procedure object previously generated by the same source lambda form.
The behavior of a datatype with respect to eq? is generally specified with the datatype and its associated procedures.


#### 4.1.2 Equality and Hashing
All comparable values have at least one hash code — an arbitrary integer (more specifically a fixnum) computed by applying a hash function to the value. The defining property of these hash codes is that equal values have equal hash codes. Note that the reverse is not true: two unequal values can still have equal hash codes. Hash codes are useful for various indexing and comparison operations, especially in the implementation of hash tables. See Hash Tables for more information.
> ```
(equal-hash-code v) → fixnum?
  v : any/c```
Returns a [hash code](#%28tech._hash._code%29) consistent with [equal?](#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29). For any two calls with [equal?](#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29) values, the returned number is the same. A hash code is computed even when v contains a cycle through pairs, vectors, boxes, and/or inspectable structure fields. Additionally, user-defined data types can customize how this hash code is computed by implementing [gen:equal+hash](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._gen~3aequal%2Bhash%29%29) or [gen:equal-mode+hash](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._gen~3aequal-mode%2Bhash%29%29).


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
For any v that could be produced by [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29), if v2 is produced by [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29) for the same input characters, the ([equal-hash-code](#%28def._%28%28quote._~23~25kernel%29._equal-hash-code%29%29) v) is the same as ([equal-hash-code](#%28def._%28%28quote._~23~25kernel%29._equal-hash-code%29%29) v2) — even if v and v2 do not exist at the same time (and therefore could not be compared by calling [equal?](#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29)).
Changed in version 6.4.0.12 of package base: Strengthened guarantee for [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29)able values.
> ```
(equal-hash-code/recur v recur-proc)  →  fixnum?
  v : any/c
  recur-proc : (  →   any/c exact-integer?)


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
```
Like equal-hash-code, but using recur-proc for recursive hashing within v.

Examples:

> ```racket
> > ( define ( rational-hash x ) ( cond [ ( rational? x ) ( equal-hash-code ( inexact  →  exact x ) ) ] [ else ( equal-hash-code/recur x rational-hash ) ] ) )
> > ( = ( rational-hash 0.0 ) ( rational-hash -0 .0 ) )
> #t
> > ( = ( rational-hash 1.0 ) ( rational-hash -1 .0 ) )
> #f
> > ( = ( rational-hash ( list ( list ( list 4.0 0.0 ) 9.0 ) 6.0 ) ) ( rational-hash ( list ( list ( list 4 0 ) 9 ) 6 ) ) )
> #t
> ```

Added in version 8.8.0.9 of package base.

> ```
(equal-secondary-hash-code v) → fixnum?
  v : any/c```

Like [equal-hash-code](#%28def._%28%28quote._~23~25kernel%29._equal-hash-code%29%29), but computes a secondary [hash code](#%28tech._hash._code%29) suitable for use in double hashing.

> ```
(equal-always-hash-code v)  →  fixnum?
  v : any/c
```
Returns a hash code consistent with equal-always?. For any two calls with equal-always? values, the returned number is the same.
As equal-always-hash-code traverses v, immutable values within v are hashed with equal-hash-code, while mutable values within v are hashed with eq-hash-code.
> ```
(equal-always-hash-code/recur v recur-proc)   →   fixnum?
  v : any/c
  recur-proc : (  →   any/c exact-integer?)```


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
Like [equal-always-hash-code](#%28def._%28%28quote._~23~25kernel%29._equal-always-hash-code%29%29), but using recur-proc for recursive hashing within v.
Added in version 8.8.0.9 of package base.
> ```
(equal-always-secondary-hash-code v)  →  fixnum?
  v : any/c
```
Like equal-always-hash-code, but computes a secondary hash code suitable for use in double hashing.

> ```
(eq-hash-code v)   →   fixnum?
  v : any/c```

Returns a [hash code](#%28tech._hash._code%29) consistent with [eq?](#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29). For any two calls with [eq?](#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29) values, the returned number is the same.

> > > Equal [fixnums](numbers.html#%28tech._fixnum%29) are always [eq?](#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29).

> ```
(eqv-hash-code v)  →  fixnum?
  v : any/c
```
Returns a hash code consistent with eqv?. For any two calls with eqv? values, the returned number is the same.


#### 4.1.3 Implementing Equality for Custom Types
>
<colgroup><col style="width: 100%" /></colgroup>

value

gen:equal+hash : any/c

A generic interface (see Generic Interfaces) for types that can be compared for equality using equal?. The following methods must be implemented:
-  equal-proc : (  →  any/c any/c (  →  any/c any/c boolean?) any/c) — tests whether the first two arguments are equal, where both values are instances of the structure type to which the generic interface is associated (or a subtype of the structure type).
The third argument is an equal? predicate to use for recursive equality checks; use the given predicate instead of equal? to ensure that data cycles are handled properly and to work with equal?/recur (but beware that an arbitrary function can be provided to equal?/recur for recursive checks, which means that arguments provided to the predicate might be exposed to arbitrary code).
The equal-proc is called for a pair of structures only when they are not eq?, and only when they both have a gen:equal+hash value inherited from the same structure type. With this strategy, the order in which equal? receives two structures does not matter. It also means that, by default, a structure sub-type inherits the equality predicate of its parent, if any.


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
-  hash-proc : (  →  any/c (  →  any/c exact-integer?) exact-integer?) — computes a hash code for the given structure, like equal-hash-code. The first argument is an instance of the structure type (or one of its subtypes) to which the generic interface is associated.
The second argument is an equal-hash-code-like procedure to use for recursive hash-code computation; use the given procedure instead of equal-hash-code to ensure that data cycles are handled properly.
Although the result of hash-proc can be any exact integer, it will be truncated for most purposes to a fixnum (e.g., for the result of equal-hash-code). Roughly, truncation uses bitwise-and to take the lower bits of the number. Thus, variation in the hash-code computation should be reflected in the fixnum-compatible bits of hash-proc’s result. Consumers of a hash code are expected to use variation within the fixnum range appropriately, and producers are not responsible to reflect variation in hash codes across the full range of bits that fit within a fixnum.
-  hash2-proc : (  →  any/c (  →  any/c exact-integer?) exact-integer?) — computes a secondary hash code for the given structure. This procedure is like hash-proc, but analogous to equal-secondary-hash-code.


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
Take care to ensure that hash-proc and hash2-proc are consistent with equal-proc. Specifically, hash-proc and hash2-proc should produce the same value for any two structures for which equal-proc produces a true value.
The equal-proc is not only used for equal?, it is also used for equal?/recur, and impersonator-of?. Furthermore, if the structure type has no mutable fields, equal-proc is used for equal-always?, and chaperone-of?. Likewise hash-proc and hash2-proc are used for equal-always-hash-code and equal-always-secondary-hash-code, respectively, when the structure type has no mutable fields. Instances of these methods should follow the guidelines in Honest Custom Equality to implement all of these operations reasonably. In particular, these methods should not access mutable data unless the struct is declared mutable.


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
When a structure type has no gen:equal+hash or gen:equal-mode+hash implementation, then transparent structures (i.e., structures with an inspector that is controlled by the current inspector) are equal? when they are instances of the same structure type (not counting sub-types), and when they have equal? field values. For transparent structures, equal-hash-code and equal-secondary-hash-code (in the case of no mutable fields) derive hash code using the field values. For a transparent structure type with at least one mutable field, equal-always? is the same as eq?, and an equal-secondary-hash-code result is based only on eq-hash-code. For opaque structure types, equal? is the same as eq?, and equal-hash-code and equal-secondary-hash-code results are based only on eq-hash-code. If a structure has a prop:impersonator-of property, then the prop:impersonator-of property takes precedence over gen:equal+hash if the property value’s procedure returns a non-#f value when applied to the structure.
Examples:


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
> ```racket
> ( define ( farm=? farm1 farm2 recursive-equal? ) ( and ( = ( farm-apples farm1 ) ( farm-apples farm2 ) ) ( = ( farm-oranges farm1 ) ( farm-oranges farm2 ) ) ( = ( farm-sheep farm1 ) ( farm-sheep farm2 ) ) ) ) ( define ( farm-hash-code farm recursive-equal-hash ) ( + ( * 10000 ( farm-apples farm ) ) ( * 100 ( farm-oranges farm ) ) ( * 1 ( farm-sheep farm ) ) ) ) ( define ( farm-secondary-hash-code farm recursive-equal-hash ) ( + ( * 10000 ( farm-sheep farm ) ) ( * 100 ( farm-apples farm ) ) ( * 1 ( farm-oranges farm ) ) ) ) ( struct farm ( apples oranges sheep ) #:methods gen:equal+hash [ ( define equal-proc farm=? ) ( define hash-proc farm-hash-code ) ( define hash2-proc farm-secondary-hash-code ) ] ) ( define eastern-farm ( farm 5 2 20 ) ) ( define western-farm ( farm 18 6 14 ) ) ( define northern-farm ( farm 5 20 20 ) ) ( define southern-farm ( farm 18 6 14 ) )
> > ( equal? eastern-farm western-farm )
> #f
> > ( equal? eastern-farm northern-farm )
> #f
> > ( equal? western-farm southern-farm )
> #t
> ```
Changed in version 8.7.0.5 of package base: Added a check so that omitting any of equal-proc, hash-proc, and hash2-proc is now a syntax error.
>
<colgroup><col style="width: 100%" /></colgroup>

value

gen:equal-mode+hash : any/c


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
A generic interface (see Generic Interfaces) for types that may specify differences between equal? and equal-always?. The following methods must be implemented:
-  equal-mode-proc : (  →  any/c any/c (  →  any/c any/c boolean?) boolean? any/c) — the first two arguments are the values to compare, the third argument is an equality function to use for recursive comparisons, and the last argument is the mode: #t for an equal? or impersonator-of? comparison or #f for an equal-always? or chaperone-of? comparison.
-  hash-mode-proc : (  →  any/c (  →  any/c exact-integer?) boolean? exact-integer?) — the first argument is the value to compute a hash code for, the second argument is a hashing function to use for recursive hashing, and the last argument is the mode: #t for equal? hashing or #f for equal-always? hashing.
The hash-mode-proc implementation is used both for a primary hash code and secondary hash code.
When implementing these methods, follow the guidelines in Honest Custom Equality. In particular, these methods should only access mutable data if the “mode” argument is true to indicate equal? or impersonator-of?.
Implementing gen:equal-mode+hash is most useful for types that specify differences between equal? and equal-always?, such as a structure type that wraps mutable data with getter and setter procedures:
Examples:


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
> ```racket
> > ( define ( get gs ) ( ( getset-getter gs ) ) )
> > ( define ( set gs new ) ( ( getset-setter gs ) new ) )
> > ( struct getset ( getter setter ) #:methods gen:equal-mode+hash [ ( define ( equal-mode-proc self other rec mode ) ( and mode ( rec ( get self ) ( get other ) ) ) ) ( define ( hash-mode-proc self rec mode ) ( if mode ( rec ( get self ) ) ( eq-hash-code self ) ) ) ] )
> > ( define x 1 )
> > ( define y 2 )
> > ( define gsx ( getset ( lambda ( ) x ) ( lambda ( new ) ( set! x new ) ) ) )
> > ( define gsy ( getset ( lambda ( ) y ) ( lambda ( new ) ( set! y new ) ) ) )
> > ( equal? gsx gsy )
> #f
> > ( equal-always? gsx gsy )
> #f
> > ( set gsx 3 )
> > ( set gsy 3 )
> > ( equal? gsx gsy )
> #t
> > ( equal-always? gsx gsy )
> #f
> > ( equal-always? gsx gsx )
> #t
> ```
Added in version 8.5.0.3 of package base.
Changed in version 8.7.0.5: Added a check so that omitting either equal-mode-proc or hash-mode-proc is now a syntax error.
>
<colgroup><col style="width: 100%" /></colgroup>

value

prop:equal+hash : struct-type-property?


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
A structure type property (see Structure Type Properties) that supplies an equality predicate and hashing functions for a structure type. Using the prop:equal+hash property is an alternative to using the gen:equal+hash or gen:equal-mode+hash generic interface.
A prop:equal+hash property value is a list of either three procedures (list equal-proc hash-proc hash2-proc) or two procedures (list equal-mode-proc hash-mode-proc):
-  The three-procedure case corresponds to the procedures of gen:equal-hash:
-  equal-proc : (  →  any/c any/c (  →  any/c any/c boolean?) any/c)
-  hash-proc : (  →  any/c (  →  any/c exact-integer?) exact-integer?)
-  hash2-proc : (  →  any/c (  →  any/c exact-integer?) exact-integer?)
-  The two-procedure case corresponds to the procedures of gen:equal-mode-hash:
-  equal-mode-proc : (  →  any/c any/c (  →  any/c any/c boolean?) boolean? any/c)
-  hash-mode-proc : (  →  any/c (  →  any/c exact-integer?) boolean? exact-integer?)
When implementing these methods, follow the guidelines in Honest Custom Equality. In particular, these methods should only access mutable data if the struct is declared mutable or the mode is true.
Changed in version 8.5.0.3 of package base: Added support for two-procedure values to customize equal-always?.


#### 4.1.4 Honest Custom Equality
Since the equal-proc or equal-mode-proc is used for more than just equal?, instances of them should follow certain guidelines to make sure that they work correctly for equal-always?, chaperone-of?, and impersonator-of?.
Due to the differences between these operations, avoid calling equal? within them. Instead, use the third argument to “recur” on the pieces, which allows equal?/recur to work properly, lets the other operations behave in their own distinct ways on the pieces, and enables some cycle detection.

<colgroup><col style="width: 50%" /><col style="width: 50%" /></colgroup>

good

( define ( equal-proc self other rec )
(rec (fish-size self) (fish-size other)))

bad

(define (equal-proc self other rec)
( equal? ( fish-size self ) ( fish-size other ) ) )


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
Don’t use the third argument to “recur” on counts of elements. When a data structure cares about discrete numbers, it can use = on those, not equal? or “recur”. Using “recur” on counts is bad when a “recur” argument from equal?/recur is too tolerant on numbers within some range of each other.```
good( define ( equal-proc self other rec )
(and (= (tuple-length self) (tuple-length other))
( for/and ( [ i ( in-range ( tuple-length self ) ) ] )
( rec ( ( tuple-getter self ) i )
( ( tuple-getter other ) i ) ) ) ) ) bad( define ( equal-proc self other rec )
( and ( rec ( tuple-length self ) ( tuple-length other ) )
( for/and ( [ i ( in-range ( tuple-length self ) ) ] )
( rec ( ( tuple-getter self ) i )
( ( tuple-getter other ) i ) ) ) ) )
```

The operations [equal?](#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29) and [equal-always?](#%28def._%28%28quote._~23~25kernel%29._equal-always~3f%29%29) should be symmetric, so equal-proc instances should not change their answer when the arguments swap:

```
good( define ( equal-proc self other rec )
(rec (fish-size self) (fish-size other))) bad(define (equal-proc self other rec)
( <= ( fish-size self ) ( fish-size other ) ) )


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
```
However, the operations chaperone-of? and impersonator-of? are not symmetric, so when calling the third argument to “recur” on pieces, pass the pieces in the same order they came in:

<table data-border="1" data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 50%" /><col style="width: 50%" /></colgroup><tbody><tr><td style="text-align: left;" data-valign="top" width="500"><blockquote><p>good</p><blockquote><pre><code>( define ( equal-proc self other rec )
(rec (fish-size self) (fish-size other)))</code></pre></blockquote></blockquote></td><td style="text-align: left;" data-valign="top" width="500"><blockquote><p>bad</p><blockquote><pre><code>(define (equal-proc self other rec)
( rec ( fish-size other ) ( fish-size self ) ) )</code></pre></blockquote></blockquote></td></tr></tbody></table>

The operations equal-always? and chaperone-of? shouldn’t change on mutation, so equal-proc instances should not access potentially-mutable data. This includes avoiding string=?, since strings can be mutable. Type-specific equality functions for immutable types, such as symbol=?, are fine.```
fine( define ( equal-proc self other rec )
; symbols are immutable: no problem
(symbol=? (thing-name self) (thing-name other))) bad(define (equal-proc self other rec)
; strings can be mutable: accesses mutable data
( string=? ( thing-name self ) ( thing-name other ) ) )
```


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
Declaring a struct as mutable makes [equal-always?](#%28def._%28%28quote._~23~25kernel%29._equal-always~3f%29%29) and [chaperone-of?](chaperones.html#%28def._%28%28quote._~23~25kernel%29._chaperone-of~3f%29%29) avoid using equal-proc, so equal-proc instances are free to access mutable data if the struct is declared mutable:
```
good( struct mcell ( value ) #:mutable
#:methods gen:equal+hash
[ ( define ( equal-proc self other rec )
(rec (mcell-value self)
( mcell-value other ) ) )
( define ( hash-proc self rec )
( + ( eq-hash-code struct:mcell )
( rec ( mcell-value self ) ) ) )
( define ( hash2-proc self rec )
( + ( eq-hash-code struct:mcell )
( rec ( mcell-value self ) ) ) ) ] ) bad( struct mcell ( box )
; not declared mutable,
; but represents mutable data anyway
#:methods gen:equal+hash
[ ( define ( equal-proc self other rec )
( rec ( unbox ( mcell-box self ) )
( unbox ( mcell-box other ) ) ) )
( define ( hash-proc self rec )
( + ( eq-hash-code struct:mcell )
( rec ( unbox ( mcell-value self ) ) ) ) )
( define ( hash2-proc self rec )
( + ( eq-hash-code struct:mcell )
( rec ( unbox ( mcell-value self ) ) ) ) ) ] )
```


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
Another way for a struct to control access to mutable data is by implementing [gen:equal-mode+hash](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._gen~3aequal-mode%2Bhash%29%29) instead of [gen:equal+hash](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._gen~3aequal%2Bhash%29%29). When the mode is true, equal-mode-proc instances are free to access mutable data, and when the mode is false, they shouldn’t:
```
also good( struct mcell ( value ) #:mutable
; only accesses mutable data when mode is true
#:methods gen:equal-mode+hash
[ ( define ( equal-mode-proc self other rec mode )
(and mode
( rec ( mcell-value self )
( mcell-value other ) ) ) )
( define ( hash-mode-proc self rec mode )
( if mode
( + ( eq-hash-code struct:mcell )
( rec ( mcell-value self ) ) )
( eq-hash-code self ) ) ) ] ) still bad( struct mcell ( value ) #:mutable
; accesses mutable data ignoring mode
#:methods gen:equal-mode+hash
[ ( define ( equal-mode-proc self other rec mode )
( rec ( mcell-value self )
( mcell-value other ) ) )
( define ( hash-mode-proc self rec mode )
( + ( eq-hash-code struct:mcell )
( rec ( mcell-value self ) ) ) ) ] )
```


#### 4.1.5 Combining Hash Codes
|  |  |
|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  (require racket/hash-code) |  package: base |
The bindings documented in this section are provided by the racket/hash-code library, not racket/base or racket.
Added in version 8.8.0.5 of package base.
> ```
(hash-code-combine hc ...) → fixnum?
  hc : exact-integer?```
Combines the hcs into a [hash code](#%28tech._hash._code%29) that depends on the order of the inputs. Useful for combining the hash codes of different fields in a structure.
Examples:


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
> ```racket
> > ( require racket/hash-code )
> > ( struct ordered-triple ( fst snd thd ) #:methods gen:equal+hash [ ( define ( equal-proc self other rec ) ( and ( rec ( ordered-triple-fst self ) ( ordered-triple-fst other ) ) ( rec ( ordered-triple-snd self ) ( ordered-triple-snd other ) ) ( rec ( ordered-triple-thd self ) ( ordered-triple-thd other ) ) ) ) ( define ( hash-proc self rec ) ( hash-code-combine ( eq-hash-code struct:ordered-triple ) ( rec ( ordered-triple-fst self ) ) ( rec ( ordered-triple-snd self ) ) ( rec ( ordered-triple-thd self ) ) ) ) ( define ( hash2-proc self rec ) ( hash-code-combine ( eq-hash-code struct:ordered-triple ) ( rec ( ordered-triple-fst self ) ) ( rec ( ordered-triple-snd self ) ) ( rec ( ordered-triple-thd self ) ) ) ) ] )
> > ( equal? ( ordered-triple ' A ' B ' C ) ( ordered-triple ' A ' B ' C ) )
> #t
> > ( = ( equal-hash-code ( ordered-triple ' A ' B ' C ) ) ( equal-hash-code ( ordered-triple ' A ' B ' C ) ) )
> #t
> > ( equal? ( ordered-triple ' A ' B ' C ) ( ordered-triple ' C ' B ' A ) )
> #f
> > ( = ( equal-hash-code ( ordered-triple ' A ' B ' C ) ) ( equal-hash-code ( ordered-triple ' C ' B ' A ) ) )
> #f
> > ( equal? ( ordered-triple ' A ' B ' C ) ( ordered-triple ' C ' A ' B ) )
> #f
> > ( = ( equal-hash-code ( ordered-triple ' A ' B ' C ) ) ( equal-hash-code ( ordered-triple ' C ' A ' B ) ) )
> #f
> ```


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
With one argument, ([hash-code-combine](#%28def._%28%28lib._racket%2Fhash-code..rkt%29._hash-code-combine%29%29) hc) mixes the hash code so that it isn’t just hc.
Examples:
> ```racket
> > ( require racket/hash-code )
> > ( struct wrap ( value ) #:methods gen:equal+hash [ ( define ( equal-proc self other rec ) ( rec ( wrap-value self ) ( wrap-value other ) ) ) ( define ( hash-proc self rec ) ; demonstrates `hash-code-combine` with only one argument ; but it's good to combine `(eq-hash-code struct:wrap)` too ( hash-code-combine ( rec ( wrap-value self ) ) ) ) ( define ( hash2-proc self rec ) ( hash-code-combine ( rec ( wrap-value self ) ) ) ) ] )
> > ( equal? ( wrap ' A ) ( wrap ' A ) )
> #t
> > ( = ( equal-hash-code ( wrap ' A ) ) ( equal-hash-code ( wrap ' A ) ) )
> #t
> > ( equal? ( wrap ' A ) ' A )
> #f
> > ( = ( equal-hash-code ( wrap ' A ) ) ( equal-hash-code ' A ) )
> #f
> ```
> ```
(hash-code-combine-unordered hc ...) → fixnum?
  hc : exact-integer?


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
```
Combines the hcs into a hash code that does not depend on the order of the inputs. Useful for combining the hash codes of elements of an unordered set.

Examples:

> ```racket
> > ( require racket/hash-code )
> > ( struct flip-triple ( left mid right ) #:methods gen:equal+hash [ ( define ( equal-proc self other rec ) ( and ( rec ( flip-triple-mid self ) ( flip-triple-mid other ) ) ( or ( and ( rec ( flip-triple-left self ) ( flip-triple-left other ) ) ( rec ( flip-triple-right self ) ( flip-triple-right other ) ) ) ( and ( rec ( flip-triple-left self ) ( flip-triple-right other ) ) ( rec ( flip-triple-right self ) ( flip-triple-left other ) ) ) ) ) ) ( define ( hash-proc self rec ) ( hash-code-combine ( eq-hash-code struct:flip-triple ) ( rec ( flip-triple-mid self ) ) ( hash-code-combine-unordered ( rec ( flip-triple-left self ) ) ( rec ( flip-triple-right self ) ) ) ) ) ( define ( hash2-proc self rec ) ( hash-code-combine ( eq-hash-code struct:flip-triple ) ( rec ( flip-triple-mid self ) ) ( hash-code-combine-unordered ( rec ( flip-triple-left self ) ) ( rec ( flip-triple-right self ) ) ) ) ) ] )
> > ( equal? ( flip-triple ' A ' B ' C ) ( flip-triple ' A ' B ' C ) )
> #t
> > ( = ( equal-hash-code ( flip-triple ' A ' B ' C ) ) ( equal-hash-code ( flip-triple ' A ' B ' C ) ) )
> #t
> > ( equal? ( flip-triple ' A ' B ' C ) ( flip-triple ' C ' B ' A ) )
> #t
> > ( = ( equal-hash-code ( flip-triple ' A ' B ' C ) ) ( equal-hash-code ( flip-triple ' C ' B ' A ) ) )
> #t
> > ( equal? ( flip-triple ' A ' B ' C ) ( flip-triple ' C ' A ' B ) )
> #f
> > ( = ( equal-hash-code ( flip-triple ' A ' B ' C ) ) ( equal-hash-code ( flip-triple ' C ' A ' B ) ) )
> #f
> > ( struct rotate-triple ( rock paper scissors ) #:methods gen:equal+hash [ ( define ( equal-proc self other rec ) ( or ( and ( rec ( rotate-triple-rock self ) ( rotate-triple-rock other ) ) ( rec ( rotate-triple-paper self ) ( rotate-triple-paper other ) ) ( rec ( rotate-triple-scissors self ) ( rotate-triple-scissors other ) ) ) ( and ( rec ( rotate-triple-rock self ) ( rotate-triple-paper other ) ) ( rec ( rotate-triple-paper self ) ( rotate-triple-scissors other ) ) ( rec ( rotate-triple-scissors self ) ( rotate-triple-rock other ) ) ) ( and ( rec ( rotate-triple-rock self ) ( rotate-triple-scissors other ) ) ( rec ( rotate-triple-paper self ) ( rotate-triple-rock other ) ) ( rec ( rotate-triple-scissors self ) ( rotate-triple-paper other ) ) ) ) ) ( define ( hash-proc self rec ) ( define r ( rec ( rotate-triple-rock self ) ) ) ( define p ( rec ( rotate-triple-paper self ) ) ) ( define s ( rec ( rotate-triple-scissors self ) ) ) ( hash-code-combine ( eq-hash-code struct:rotate-triple ) ( hash-code-combine-unordered ( hash-code-combine r p ) ( hash-code-combine p s ) ( hash-code-combine s r ) ) ) ) ( define ( hash2-proc self rec ) ( define r ( rec ( rotate-triple-rock self ) ) ) ( define p ( rec ( rotate-triple-paper self ) ) ) ( define s ( rec ( rotate-triple-scissors self ) ) ) ( hash-code-combine ( eq-hash-code struct:rotate-triple ) ( hash-code-combine-unordered ( hash-code-combine r p ) ( hash-code-combine p s ) ( hash-code-combine s r ) ) ) ) ] )
> > ( equal? ( rotate-triple ' A ' B ' C ) ( rotate-triple ' A ' B ' C ) )
> #t
> > ( = ( equal-hash-code ( rotate-triple ' A ' B ' C ) ) ( equal-hash-code ( rotate-triple ' A ' B ' C ) ) )
> #t
> > ( equal? ( rotate-triple ' A ' B ' C ) ( rotate-triple ' C ' B ' A ) )
> #f
> > ( = ( equal-hash-code ( rotate-triple ' A ' B ' C ) ) ( equal-hash-code ( rotate-triple ' C ' B ' A ) ) )
> #f
> > ( equal? ( rotate-triple ' A ' B ' C ) ( rotate-triple ' C ' A ' B ) )
> #t
> > ( = ( equal-hash-code ( rotate-triple ' A ' B ' C ) ) ( equal-hash-code ( rotate-triple ' C ' A ' B ) ) )
> #t
> ```

> ```
(hash-code-combine* hc ... hcs) → fixnum?
  hc : exact-integer?
  hcs : (listof exact-integer?)```

Like [hash-code-combine](#%28def._%28%28lib._racket%2Fhash-code..rkt%29._hash-code-combine%29%29), but the last argument is used as a list of arguments for [hash-code-combine](#%28def._%28%28lib._racket%2Fhash-code..rkt%29._hash-code-combine%29%29), so ([hash-code-combine*](#%28def._%28%28lib._racket%2Fhash-code..rkt%29._hash-code-combine%2A%29%29) hc [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29) hcs) is the same as ([apply](procedures.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._apply%29%29) [hash-code-combine](#%28def._%28%28lib._racket%2Fhash-code..rkt%29._hash-code-combine%29%29) hc [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29) hcs). In other words, the relationship between [hash-code-combine](#%28def._%28%28lib._racket%2Fhash-code..rkt%29._hash-code-combine%29%29) and [hash-code-combine*](#%28def._%28%28lib._racket%2Fhash-code..rkt%29._hash-code-combine%2A%29%29) is similar to the one between [list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) and [list*](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%2A%29%29).

> ```
(hash-code-combine-unordered* hc ... hcs) → fixnum?
  hc : exact-integer?
  hcs : (listof exact-integer?)
```


### 3.14 Definitions: [define](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29), [define-syntax](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29), ...
Like hash-code-combine-unordered, but the last argument is used as a list of arguments for hash-code-combine-unordered, so (hash-code-combine-unordered* hc ... hcs) is the same as (apply hash-code-combine-unordered hc ... hcs). In other words, the relationship between hash-code-combine-unordered and hash-code-combine-unordered* is similar to the one between list and list*.
------------------------------------------------------------------------


# 4.2 Booleans


### 4.2 Booleans
True and false booleans are represented by the values #t and #f, respectively, though operations that depend on a boolean value typically treat anything other than #f as true. The #t value is always eq? to itself, and #f is always eq? to itself.
See Reading Booleans for information on reading booleans and Printing Booleans for information on printing booleans.
See also and, or, andmap, and ormap.
> ```
(boolean? v) → boolean?
  v : any/c```
Returns #t if v is #t or #f, #f otherwise.
Examples:
> ```racket
> > ( boolean? #f )
> #t
> > ( boolean? #t )
> #t
> > ( boolean? ' true )
> #f
> ```
> ```
(not v)  →  boolean?
  v : any/c
```

Returns #t if v is #f, #f otherwise.

Examples:

> ```racket
> > ( not #f )
> #t
> > ( not #t )
> #f
> > ( not ' we-have-no-bananas )
> #f
> ```

> ```
(immutable? v)  →  boolean?
  v : any/c
```
Returns #t if v is an immutable [string](strings.html#%28tech._string%29), [byte string](bytestrings.html#%28tech._byte._string%29), [vector](vectors.html#%28tech._vector%29), [hash table](hashtables.html#%28tech._hash._table%29), or [box](boxes.html#%28tech._box%29), #f otherwise.


# 4.2 Booleans
Note that [immutable?](#%28def._%28%28quote._~23~25kernel%29._immutable~3f%29%29) is not a general predicate for immutability (despite its name). It works only for a handful of datatypes for which a single predicate—[string?](strings.html#%28def._%28%28quote._~23~25kernel%29._string~3f%29%29), [vector?](vectors.html#%28def._%28%28quote._~23~25kernel%29._vector~3f%29%29), etc.—recognizes both mutable and immutable variants of the datatype. In particular, [immutable?](#%28def._%28%28quote._~23~25kernel%29._immutable~3f%29%29) produces #f for a [pair](pairs.html#%28tech._pair%29), even though pairs are immutable, since [pair?](pairs.html#%28def._%28%28quote._~23~25kernel%29._pair~3f%29%29) implies immutability.
See also [immutable-string?](#%28def._%28%28lib._racket%2Fmutability..rkt%29._immutable-string~3f%29%29), [mutable-string?](#%28def._%28%28lib._racket%2Fmutability..rkt%29._mutable-string~3f%29%29), etc.
Examples:
> ```racket
> > ( immutable? ' hello )
> #f
> > ( immutable? "a string" )
> #t
> > ( immutable? ( box 5 ) )
> #f
> > ( immutable? # ( 0 1 2 3 ) )
> #t
> > ( immutable? ( make-hash ) )
> #f
> > ( immutable? ( make-immutable-hash ' ( [ a b ] ) ) )
> #t
> > ( immutable? #t )
> #f
> ```


#### 4.2.1 Boolean Aliases
|                                                                                |                                                                                |
|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/bool](#%28mod-path._racket%2Fbool%29)) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |
The bindings documented in this section are provided by the [racket/bool](#%28mod-path._racket%2Fbool%29) and [racket](index.html) libraries, but not [racket/base](index.html).
>
<colgroup><col style="width: 100%" /></colgroup>

value

[true](#%28def._%28%28lib._racket%2Fbool..rkt%29._true%29%29) : [boolean?](#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29)

An alias for #t.
>
<colgroup><col style="width: 100%" /></colgroup>

value


# 4.2 Booleans

[false](#%28def._%28%28lib._racket%2Fbool..rkt%29._false%29%29) : [boolean?](#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29)

An alias for #f.
> ```
(parameter)	→
```
Returns (equal? a b) (if a and b are symbols).

> ```
(boolean=? a b) → boolean?
  a : boolean?
  b : boolean?```

Returns ([equal?](Equality.html#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29) a b) (if a and b are booleans).

> ```
(false? v)  →  boolean?
  v : any/c
```
Returns (not v).
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

(nand expr ...)

Same as (not (and expr ...)).
Examples:
> ```racket
> > ( nand #f #t )
> #t
> > ( nand #f ( error ' ack "we don't get here" ) )
> #t
> ```
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

(nor expr ...)

Same as (not (or expr ...)).
In the two argument case, returns #t if neither of the arguments is a true value.
Examples:
> ```racket
> > ( nor #f #t )
> #f
> > ( nor #t ( error ' ack "we don't get here" ) )
> #f
> ```
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

(implies expr1 expr2)

Checks to be sure that the first expression implies the second.
Same as (if expr1 expr2 #t).


# 4.2 Booleans
Examples:
> ```racket
> > ( implies #f #t )
> #t
> > ( implies #f #f )
> #t
> > ( implies #t #f )
> #f
> > ( implies #f ( error ' ack "we don't get here" ) )
> #t
> ```
> ```
(xor b1 b2) → any
  b1 : any/c
  b2 : any/c```
Returns the exclusive or of b1 and b2.
If exactly one of b1 and b2 is not #f, then return it. Otherwise, returns #f.
Examples:
> ```racket
> > ( xor 11 #f )
> 11
> > ( xor #f 22 )
> 22
> > ( xor 11 22 )
> #f
> > ( xor #f #f )
> #f
> ```


#### 4.2.2 Mutability Predicates
|                                                                                |                                                                                |
|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/mutability](#%28mod-path._racket%2Fmutability%29)) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |
The bindings documented in this section are provided by the [racket/mutability](#%28mod-path._racket%2Fmutability%29) library, not [racket/base](index.html) or [racket](index.html).
Added in version 8.9.0.3 of package base.
> ```
(mutable-string? v)  →  boolean?
  v : any/c
(immutable-string? v)  →  boolean?
  v : any/c
(mutable-bytes? v)  →  boolean?
  v : any/c
(immutable-bytes? v)  →  boolean?
  v : any/c
(mutable-vector? v)  →  boolean?
  v : any/c
(immutable-vector? v)  →  boolean?
  v : any/c
(mutable-box? v)  →  boolean?
  v : any/c
(immutable-box? v)  →  boolean?
  v : any/c
(mutable-hash? v)  →  boolean?
  v : any/c


# 4.2 Booleans
(immutable-hash? v)  →  boolean?
  v : any/c
```
Predicates that combine string?, bytes?, vector?, box?, and hash? with immutable? or its inverse. The predicates are potentially faster than using immutable? and other predicates separately.

------------------------------------------------------------------------

# 4.3 Numbers

### 4.3 Numbers

> > > <img src="finger.png" width="24" height="24" alt="+" />Numbers in The Racket Guide introduces numbers.

All numbers are complex numbers. Some of them are real numbers, and all of the real numbers that can be represented are also rational numbers, except for +inf.0 (positive infinity), +inf.f (single-precision variant, when enabled via read-single-flonum), -inf.0 (negative infinity), -inf.f (single-precision variant, when enabled), +nan.0 (not-a-number), and +nan.f (single-precision variant, when enabled). Among the rational numbers, some are integers, because round applied to the number produces the same number.

> > > <img src="magnify.png" width="24" height="24" alt="+" />See Reading Numbers for information on the syntax of number literals.

Orthogonal to those categories, each number is also either an exact number or an inexact number. Unless otherwise specified, computations that involve an inexact number produce inexact results. Certain operations on inexact numbers, however, produce an exact number, such as multiplying an inexact number with an exact 0. Operations that mathematically produce irrational numbers for some rational arguments (e.g., sqrt) may produce inexact results even for exact arguments.

In the case of complex numbers, either the real and imaginary parts are both exact or inexact with the same precision, or the number has an exact zero real part and an inexact imaginary part; a complex number with an exact zero imaginary part is a real number.

Inexact real numbers are implemented as double-precision IEEE floating-point numbers, also known as flonums, or as single-precision IEEE floating-point numbers, also known as single-flonums. Single-flonums are supported only when (single-flonum-available?) reports #t. Although we write +inf.f, -inf.f, and +nan.f to mean single-flonums, those forms read as double-precision flonums by default, since read-single-flonum is #f by default. When single-flonums are supported, inexact numbers are still represented as flonums by default, and single precision is used only when a computation starts with single-flonums.

Inexact numbers can be coerced to exact form, except for the inexact numbers +inf.0, +inf.f, -inf.0, -inf.f, +nan.0, and +nan.f, which have no exact form. Dividing a number by exact zero raises an exception; dividing a non-zero number other than +nan.0 or +nan.f by an inexact zero returns +inf.0, +inf.f, -inf.0 or -inf.f, depending on the sign and precision of the dividend. The +nan.0 value is not = to itself, but +nan.0 is eqv? to itself, and +nan.f is similarly eqv? but not = to itself. Conversely, (= 0.0 -0.0) is #t, but (eqv? 0.0 -0.0) is #f, and the same for 0.0f0 and -0.0f0 (which are single-precision variants). The datum -nan.0 refers to the same constant as +nan.0, and -nan.f is the same as +nan.f.

Calculations with infinities produce results consistent with IEEE double- or single-precision floating point where IEEE specifies the result; in cases where IEEE provides no specification, the result corresponds to the limit approaching infinity, or +nan.0 or +nan.f if no such limit exists.

The precision and size of exact numbers is limited only by available memory (and the precision of operations that can produce irrational numbers). In particular, adding, multiplying, subtracting, and dividing exact numbers always produces an exact result.

A fixnum is an exact integer whose two’s complement representation fits into 30 or 31 bits (depending on the Racket variant) on a 32-bit platform or 61 or 63 bits (depending on the Racket variant) on a 64-bit platform. No allocation is required when computing with fixnums. See also the racket/fixnum module, below.

Two fixnums that are = are also the same according to eq?. Otherwise, the result of eq? applied to two numbers is undefined, except that numbers produced by the default reader in read-syntax mode are interned and therefore eq? when they are eqv?.

Two real numbers are eqv? when they are both inexact with the same precision or both exact, and when they are = (except for +nan.0, +nan.f, 0.0, +0.0f0, -0.0, and -0.0f0, as noted above). Two complex numbers are eqv? when their real and imaginary parts are eqv?. Two numbers are equal? when they are eqv?.

See Reading Numbers for information on reading numbers and Printing Numbers for information on printing numbers.

|  |
|----------------------------------------------------------------------------------------------------------------------------------------------|
|     4.3.1 Number Types  |
|     4.3.2 Generic Numerics  |
|       4.3.2.1 Arithmetic  |
|       4.3.2.2 Number Comparison  |
|       4.3.2.3 Powers and Roots  |
|       4.3.2.4 Trigonometric Functions  |
|       4.3.2.5 Complex Numbers  |
|       4.3.2.6 Bitwise Operations  |
|       4.3.2.7 Random Numbers  |
|       4.3.2.8 Other Randomness Utilities  |
|       4.3.2.9 Number–String Conversions  |
|       4.3.2.10 Extra Constants and Functions |
|     4.3.3 Flonums  |
|       4.3.3.1 Flonum Arithmetic  |
|       4.3.3.2 Flonum Vectors  |
|     4.3.4 Fixnums  |
|       4.3.4.1 Fixnum Arithmetic  |
|       4.3.4.2 Fixnum Vectors  |
|       4.3.4.3 Fixnum Range  |
|     4.3.5 Extflonums  |
|       4.3.5.1 Extflonum Arithmetic  |
|       4.3.5.2 Extflonum Constants  |
|       4.3.5.3 Extflonum Vectors  |
|       4.3.5.4 Extflonum Byte Strings  |

------------------------------------------------------------------------

# 4.3.1 Number Types

#### 4.3.1 Number Types

> ```
(number? v) → boolean?
  v : any/c```

Returns #t if v is a number, #f otherwise.

Examples:

> ```racket
> > ( number? 1 )
> #t
> > ( number? 2+3i )
> #t
> > ( number? "hello" )
> #f
> > ( number? +nan.0 )
> #t
> ```

> ```
(complex? v)  →  boolean?
  v : any/c
```


# 4.2 Booleans
Returns (number? v), because all numbers are complex numbers.
> ```
(real? v)   →   boolean?
  v : any/c```
Returns #t if v is a [real number](numbers.html#%28tech._real._number%29), #f otherwise.
Examples:
> ```racket
> > ( real? 1 )
> #t
> > ( real? +inf.0 )
> #t
> > ( real? 2+3i )
> #f
> > ( real? 2.0+0.0i )
> #f
> > ( real? "hello" )
> #f
> ```
> ```
(rational? v)  →  boolean?
  v : any/c
```
Returns #t if v is a rational number, #f otherwise.

Examples:

> ```racket
> > ( rational? 1 )
> #t
> > ( rational? +inf.0 )
> #f
> > ( rational? "hello" )
> #f
> ```

> ```
(integer? v)   →   boolean?
  v : any/c```

Returns #t if v is a number that is an [integer](numbers.html#%28tech._integer%29), #f otherwise.

Examples:

> ```racket
> > ( integer? 1 )
> #t
> > ( integer? 2.3 )
> #f
> > ( integer? 4.0 )
> #t
> > ( integer? +inf.0 )
> #f
> > ( integer? 2+3i )
> #f
> > ( integer? "hello" )
> #f
> ```

> ```
(exact-integer? v)  →  boolean?
  v : any/c
```
Returns (and (integer? v) (exact? v)).
Examples:
> ```racket
> > ( exact-integer? 1 )
> #t
> > ( exact-integer? 4.0 )
> #f
> ```
> ```
(exact-nonnegative-integer? v)   →   boolean?
  v : any/c```
Returns ([and](if.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._and%29%29) ([exact-integer?](#%28def._%28%28quote._~23~25kernel%29._exact-integer~3f%29%29) v) ([not](booleans.html#%28def._%28%28quote._~23~25kernel%29._not%29%29) ([negative?](#%28def._%28%28quote._~23~25kernel%29._negative~3f%29%29) v))).
Examples:


# 4.2 Booleans
> ```racket
> > ( exact-nonnegative-integer? 0 )
> #t
> > ( exact-nonnegative-integer? -1 )
> #f
> ```
> ```
(exact-positive-integer? v)  →  boolean?
  v : any/c
```
Returns (and (exact-integer? v) (positive? v)).

Examples:

> ```racket
> > ( exact-positive-integer? 1 )
> #t
> > ( exact-positive-integer? 0 )
> #f
> ```

> ```
(inexact-real? v)   →   boolean?
  v : any/c```

Returns ([and](if.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._and%29%29) ([real?](#%28def._%28%28quote._~23~25kernel%29._real~3f%29%29) v) ([inexact?](#%28def._%28%28quote._~23~25kernel%29._inexact~3f%29%29) v)).

> ```
(fixnum? v)  →  boolean?
  v : any/c
```
Return #t if v is a fixnum, #f otherwise.
Note: the result of this function is platform-dependent, so using it in syntax transformers can lead to platform-dependent bytecode files. See also fixnum-for-every-system?.
> ```
(flonum? v)   →   boolean?
  v : any/c```
Return #t if v is a [flonum](numbers.html#%28tech._flonum%29), #f otherwise.
> ```
(double-flonum? v)  →  boolean?
  v : any/c
```
Identical to flonum?.

> ```
(single-flonum? v)   →   boolean?
  v : any/c```

Return #t if v is a [single-flonum](numbers.html#%28tech._single._flonum%29) (i.e., a single-precision floating-point number), #f otherwise.

> ```
(single-flonum-available?)  →  boolean?
```
Returns #t if single-flonums are supported on the current platform, #f otherwise.
Currently, single-flonum-available? produces #t when (system-type 'vm) produces 'racket, and single-flonum-available? produces #f otherwise.


# 4.2 Booleans
If the result is #f, then single-flonum? also produces #f for all arguments.
Added in version 7.3.0.5 of package base.
> ```
(zero? z)   →   boolean?
  z : number?```
Returns ([=](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._~3d%29%29) 0 z).
Examples:
> ```racket
> > ( zero? 0 )
> #t
> > ( zero? -0 .0 )
> #t
> ```
> ```
(positive? x)  →  boolean?
  x : real?
```
Returns (> x 0).

Examples:

> ```racket
> > ( positive? 10 )
> #t
> > ( positive? -1 0 )
> #f
> > ( positive? 0.0 )
> #f
> ```

> ```
(negative? x)   →   boolean?
  x : real?```

Returns ([<](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._~3c%29%29) x 0).

Examples:

> ```racket
> > ( negative? 10 )
> #f
> > ( negative? -1 0 )
> #t
> > ( negative? -0 .0 )
> #f
> ```

> ```
(even? n)  →  boolean?
  n : integer?
```
Returns (zero? (modulo n 2)).
Examples:
> ```racket
> > ( even? 10.0 )
> #t
> > ( even? 11 )
> #f
> > ( even? +inf.0 )
> even?: contract violation
> expected: integer?
> given: +inf.0
> ```
> ```
(odd? n)   →   boolean?
  n : integer?```
Returns ([not](booleans.html#%28def._%28%28quote._~23~25kernel%29._not%29%29) ([even?](#%28def._%28%28quote._~23~25kernel%29._even~3f%29%29) n)).
Examples:
> ```racket
> > ( odd? 10.0 )
> #f
> > ( odd? 11 )
> #t
> > ( odd? +inf.0 )
> odd?: contract violation
> expected: integer?
> given: +inf.0
> ```
> ```
(exact? z)  →  boolean?
  z : number?
```

Returns #t if z is an exact number, #f otherwise.

Examples:

> ```racket
> > ( exact? 1 )
> #t
> > ( exact? 1.0 )
> #f
> ```

> ```
(inexact? z)  →  boolean?
  z : number?
```


# 4.2 Booleans
Returns #t if z is an inexact number, #f otherwise.
Examples:
> ```racket
> > ( inexact? 1 )
> #f
> > ( inexact? 1.0 )
> #t
> ```
> ```
(inexact  →  exact z)  →  exact?
  z : number?
```
Coerces z to an exact number. If z is already exact, it is returned. If z is +inf.0, -inf.0, +nan.0, +inf.f, -inf.f, or +nan.f, then the exn:fail:contract exception is raised.

Examples:

> ```racket
> > ( inexact  →  exact 1 )
> 1
> > ( inexact  →  exact 1.0 )
> 1
> ```

> ```
(exact  →  inexact z)   →   inexact?
  z : number?```

Coerces z to an inexact number. If z is already inexact, it is returned.

Examples:

> ```racket
> > ( exact->inexact 1 )
> 1.0
> > ( exact->inexact 1.0 )
> 1.0
> ```

> ```
(real  →  single-flonum x)  →  single-flonum?
  x : real?
```
Coerces x to a single-precision floating-point number. If x is already a single-precision floating-point number, it is returned.
> ```
(real  →  double-flonum x)  →  flonum?
  x : real?
```

Coerces x to a double-precision floating-point number. If x is already a double-precision floating-point number, it is returned.

------------------------------------------------------------------------

# 4.3.2 Generic Numerics

#### 4.3.2 Generic Numerics

Most Racket numeric operations work on any kind of number.

##### 4.3.2.1 Arithmetic

> ```
(+ z ...)  →  number?
  z : number?
```
Returns the sum of the zs, adding pairwise from left to right. If no arguments are provided, the result is 0.
Examples:
> ```racket
> > ( + 1 2 )
> 3
> > ( + 1.0 2+3i 5 )
> 8.0+3.0i
> > ( + )
> 0
> ```
> ```


# 4.2 Booleans
(- z)  →  number?
  z : number?
(- z w ...+)  →  number?
  z : number?
  w : number?
```

When no ws are supplied, returns ([-](#%28def._%28%28quote._~23~25kernel%29._-%29%29) 0 z). Otherwise, returns the subtraction of the ws from z working pairwise from left to right.

Examples:

> ```racket
> > ( - 5 3.0 )
> 2.0
> > ( - 1 )
> -1
> > ( - 2+7i 1 3 )
> -2+7i
> ```

> ```
(* z ...)  →  number?
  z : number?
```
Returns the product of the zs, multiplying pairwise from left to right. If no arguments are provided, the result is 1. Multiplying any number by exact 0 produces exact 0.
Examples:
> ```racket
> > ( * 2 3 )
> 6
> > ( * 8.0 9 )
> 72.0
> > ( * 1+2i 3+4i )
> -5+10i
> ```
> ```
(/ z)  →  number?
  z : number?
(/ z w ...+)  →  number?
  z : number?
  w : number?
```

When no ws are supplied, returns ([/](#%28def._%28%28quote._~23~25kernel%29._%2F%29%29) 1 z). Otherwise, returns the division of z by the ws working pairwise from left to right.

If z is exact 0 and no w is exact 0, then the result is exact 0. If any w is exact 0, the [exn:fail:contract:divide-by-zero](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract~3adivide-by-zero%29%29) exception is raised.

Examples:

> ```racket
> > ( / 3 4 )
> 3/4
> > ( / 81 3 3 )
> 9
> > ( / 10.0 )
> 0.1
> > ( / 1+2i 3+4i )
> 11/25+2/25i
> ```

> ```
(quotient n m)  →  integer?
  n : integer?
  m : integer?
```
Returns (truncate (/ n m)).
Examples:


# 4.2 Booleans
> ```racket
> > ( quotient 10 3 )
> 3
> > ( quotient -1 0.0 3 )
> -3.0
> > ( quotient +inf.0 3 )
> quotient: contract violation
> expected: integer?
> given: +inf.0
> ```
> ```
(remainder n m)   →   integer?
  n : integer?
  m : integer?```
Returns q with the same sign as n such that
-   ([abs](#%28def._%28%28quote._~23~25kernel%29._abs%29%29) q) is between 0 (inclusive) and ([abs](#%28def._%28%28quote._~23~25kernel%29._abs%29%29) m) (exclusive), and
-   ([+](#%28def._%28%28quote._~23~25kernel%29._%2B%29%29) q ([*](#%28def._%28%28quote._~23~25kernel%29._%2A%29%29) m ([quotient](#%28def._%28%28quote._~23~25kernel%29._quotient%29%29) n m))) equals n.
If m is exact 0, the [exn:fail:contract:divide-by-zero](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract~3adivide-by-zero%29%29) exception is raised.
Examples:
> ```racket
> > ( remainder 10 3 )
> 1
> > ( remainder -1 0.0 3 )
> -1.0
> > ( remainder 10.0 -3 )
> 1.0
> > ( remainder -1 0 -3 )
> -1
> > ( remainder +inf.0 3 )
> remainder: contract violation
> expected: integer?
> given: +inf.0
> ```
> ```
(quotient/remainder n m)    →    integer?   integer?
  n : integer?
  m : integer?


# 4.2 Booleans
```
Returns (values (quotient n m) (remainder n m)), but the combination may be computed more efficiently than separate calls to quotient and remainder.

Example:

> ```racket
> > ( quotient/remainder 10 3 )
> 3 1
> ```

> ```
(modulo n m)   →   integer?
  n : integer?
  m : integer?```

Returns q with the same sign as m where

-   ([abs](#%28def._%28%28quote._~23~25kernel%29._abs%29%29) q) is between 0 (inclusive) and ([abs](#%28def._%28%28quote._~23~25kernel%29._abs%29%29) m) (exclusive), and

-   the difference between q and ([-](#%28def._%28%28quote._~23~25kernel%29._-%29%29) n ([*](#%28def._%28%28quote._~23~25kernel%29._%2A%29%29) m ([quotient](#%28def._%28%28quote._~23~25kernel%29._quotient%29%29) n m))) is a multiple of m.

If m is exact 0, the [exn:fail:contract:divide-by-zero](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract~3adivide-by-zero%29%29) exception is raised.

Examples:

> ```racket
> > ( modulo 10 3 )
> 1
> > ( modulo -1 0.0 3 )
> 2.0
> > ( modulo 10.0 -3 )
> -2.0
> > ( modulo -1 0 -3 )
> -1
> > ( modulo +inf.0 3 )
> modulo: contract violation
> expected: integer?
> given: +inf.0
> ```

> ```
(add1 z)  →  number?
  z : number?
```
Returns (+ z 1).
> ```
(sub1 z)   →   number?
  z : number?```
Returns ([-](#%28def._%28%28quote._~23~25kernel%29._-%29%29) z 1).
> ```
(abs x)  →  number?
  x : real?


# 4.2 Booleans
```
Returns the absolute value of x.

Examples:

> ```racket
> > ( abs 1.0 )
> 1.0
> > ( abs -1 )
> 1
> ```

> ```
(max x ...+) → real?
  x : real?```

Returns the largest of the xs, or +nan.0 if any x is +nan.0. If any x is inexact, the result is coerced to inexact. See also [argmax](pairs.html#%28def._%28%28lib._racket%2Flist..rkt%29._argmax%29%29).

Examples:

> ```racket
> > ( max 1 3 2 )
> 3
> > ( max 1 3 2.0 )
> 3.0
> ```

> ```
(min x ...+) → real?
  x : real?
```
Returns the smallest of the xs, or +nan.0 if any x is +nan.0. If any x is inexact, the result is coerced to inexact. See also argmin.
Examples:
> ```racket
> > ( min 1 3 2 )
> 1
> > ( min 1 3 2.0 )
> 1.0
> ```
> ```
(gcd n ...) → rational?
  n : rational?```
Returns the greatest common divisor (a non-negative number) of the ns; for non-integer ns, the result is the [gcd](#%28def._%28%28quote._~23~25kernel%29._gcd%29%29) of the numerators divided by the [lcm](#%28def._%28%28quote._~23~25kernel%29._lcm%29%29) of the denominators. If no arguments are provided, the result is 0. If all arguments are zero, the result is zero.
Examples:
> ```racket
> > ( gcd 10 )
> 10
> > ( gcd 12 81.0 )
> 3.0
> > ( gcd 1/2 1/3 )
> 1/6
> ```
> ```
(lcm n ...) → (or/c rational? +inf.0)
  n : rational?


# 4.2 Booleans
```
Returns the least common multiple (a non-negative number) of the ns. For two non-integer ns, the result is the absolute value of the product divided by the gcd. If no arguments are provided, the result is 1. If any argument is zero, the result is zero; furthermore, if any argument is exact 0, the result is exact 0.

Examples:

> ```racket
> > ( lcm 10 )
> 10
> > ( lcm 3 4.0 )
> 12.0
> > ( lcm 1/2 2/3 )
> 2
> ```

> ```
(round x)   →   (or/c integer? +inf.0 -inf.0 +nan.0)
  x : real?```

Returns the integer closest to x, resolving ties in favor of an even number, but +inf.0, -inf.0, and +nan.0 round to themselves.

Examples:

> ```racket
> > ( round 17/4 )
> 4
> > ( round -1 7/4 )
> -4
> > ( round 2.5 )
> 2.0
> > ( round -2 .5 )
> -2.0
> > ( round +inf.0 )
> +inf.0
> ```

> ```
(floor x)  →  (or/c integer? +inf.0 -inf.0 +nan.0)
  x : real?
```
Returns the largest integer that is no more than x, but +inf.0, -inf.0, and +nan.0 floor to themselves.
Examples:
> ```racket
> > ( floor 17/4 )
> 4
> > ( floor -1 7/4 )
> -5
> > ( floor 2.5 )
> 2.0
> > ( floor -2 .5 )
> -3.0
> > ( floor +inf.0 )
> +inf.0
> ```
> ```
(ceiling x)  →  (or/c integer? +inf.0 -inf.0 +nan.0)
  x : real?
```

Returns the smallest integer that is at least as large as x, but +inf.0, -inf.0, and +nan.0 ceiling to themselves.

Examples:

> ```racket
> > ( ceiling 17/4 )
> 5
> > ( ceiling -1 7/4 )
> -4
> > ( ceiling 2.5 )
> 3.0
> > ( ceiling -2 .5 )
> -2.0
> > ( ceiling +inf.0 )
> +inf.0
> ```

> ```
(truncate x)  →  (or/c integer? +inf.0 -inf.0 +nan.0)
  x : real?
```


# 4.2 Booleans
Returns the integer farthest from 0 that is not farther from 0 than x, but +inf.0, -inf.0, and +nan.0 truncate to themselves.
Examples:
> ```racket
> > ( truncate 17/4 )
> 4
> > ( truncate -1 7/4 )
> -4
> > ( truncate 2.5 )
> 2.0
> > ( truncate -2 .5 )
> -2.0
> > ( truncate +inf.0 )
> +inf.0
> ```
> ```
(numerator q)  →  integer?
  q : rational?
```

Coerces q to an exact number, finds the numerator of the number expressed in its simplest fractional form, and returns this number coerced to the exactness of q.

Examples:

> ```racket
> > ( numerator 5 )
> 5
> > ( numerator 17/4 )
> 17
> > ( numerator 2.3 )
> 2589569785738035.0
> ```

> ```
(denominator q)  →  (and/c integer? positive?)
  q : rational?
```
Coerces q to an exact number, finds the denominator of the number expressed in its simplest fractional form, and returns this number coerced to the exactness of q.
Examples:
> ```racket
> > ( denominator 5 )
> 1
> > ( denominator 17/4 )
> 4
> > ( denominator 2.3 )
> 1125899906842624.0
> ```
> ```
(rationalize x tolerance)  →  real?
  x : real?
  tolerance : real?


# 4.2 Booleans
```

Among the real numbers within ([abs](#%28def._%28%28quote._~23~25kernel%29._abs%29%29) tolerance) of x, returns the one corresponding to an exact number whose [denominator](#%28def._%28%28quote._~23~25kernel%29._denominator%29%29) is the smallest. If multiple integers are within tolerance of x, the one closest to 0 is used.

Examples:

> ```racket
> > ( rationalize 1/4 1/10 )
> 1/3
> > ( rationalize -1 /4 1/10 )
> -1/3
> > ( rationalize 1/4 1/4 )
> 0
> > ( rationalize 11/40 1/4 )
> 1/2
> ```

##### 4.3.2.2 Number Comparison

> ```
(= z w ...)  →  boolean?
  z : number?
  w : number?
```
Returns #t if all of the arguments are numerically equal, #f otherwise. An inexact number is numerically equal to an exact number when the exact coercion of the inexact number is the exact number. Also, 0.0 and -0.0 are numerically equal, but +nan.0 is not numerically equal to itself.
Examples:
> ```racket
> > ( = 1 1.0 )
> #t
> > ( = 1 2 )
> #f
> > ( = 2+3i 2+3i 2+3i )
> #t
> > ( = 1 )
> #t
> ```
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
>
<colgroup><col style="width: 100%" /></colgroup>

procedure

(< x y ...)  →  boolean?

  x : real?

  y : real?

Returns #t if the arguments in the given order are strictly increasing, #f otherwise.
Examples:


# 4.2 Booleans
> ```racket
> > ( < 1 1 )> #f
> > ( < 1 2 3 )> #t
> > ( < 1 )> #t
> > ( < 1 +inf.0 )> #t
> > ( < 1 +nan.0 )> #f
> ```
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
>
<colgroup><col style="width: 100%" /></colgroup>

procedure

(<= x y ...)  →  boolean?

  x : real?

  y : real?

Returns #t if the arguments in the given order are non-decreasing, #f otherwise.
Examples:
> ```racket
> > ( <= 1 1 )> #t
> > ( <= 1 2 1 )> #f
> ```
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
> ```
(> x y ...)   →   boolean?
  x : real?
  y : real?```
Returns #t if the arguments in the given order are strictly decreasing, #f otherwise.
Examples:
> ```racket
> > ( > 1 1 )
> #f
> > ( > 3 2 1 )
> #t
> > ( > +inf.0 1 )
> #t
> > ( > +nan.0 1 )
> #f
> ```
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
> ```
(>= x y ...)  →  boolean?
  x : real?
  y : real?


# 4.2 Booleans
```
Returns #t if the arguments in the given order are non-increasing, #f otherwise.

Examples:

> ```racket
> > ( >= 1 1 )
> #t
> > ( >= 1 2 1 )
> #f
> ```

Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.

##### 4.3.2.3 Powers and Roots

> ```
(sqrt z) → number?
  z : number?```

Returns the principal square root of z. The result is exact if z is exact and z’s square root is rational. See also [integer-sqrt](#%28def._%28%28quote._~23~25kernel%29._integer-sqrt%29%29).

Examples:

> ```racket
> > ( sqrt 4/9 )
> 2/3
> > ( sqrt 2 )
> 1.4142135623730951
> > ( sqrt -1 )
> 0+1i
> ```

> ```
(integer-sqrt n)  →  complex?
  n : integer?
```
Returns (floor (sqrt n)) for positive n. The result is exact if n is exact. For negative n, the result is (* (integer-sqrt (- n)) 0+1i).
Examples:
> ```racket
> > ( integer-sqrt 4.0 )
> 2.0
> > ( integer-sqrt 5 )
> 2
> > ( integer-sqrt -4 .0 )
> 0.0+2.0i
> > ( integer-sqrt -4 )
> 0+2i
> ```
> ```
(integer-sqrt/remainder n)    →    complex?   integer?
  n : integer?```
Returns ([integer-sqrt](#%28def._%28%28quote._~23~25kernel%29._integer-sqrt%29%29) n) and ([-](#%28def._%28%28quote._~23~25kernel%29._-%29%29) n ([expt](#%28def._%28%28quote._~23~25kernel%29._expt%29%29) ([integer-sqrt](#%28def._%28%28quote._~23~25kernel%29._integer-sqrt%29%29) n) 2)).
Examples:
> ```racket
> > ( integer-sqrt/remainder 4.0 )
> 2.0 0.0
> > ( integer-sqrt/remainder 5 )
> 2 1
> ```
> ```
(expt z w)  →  number?
  z : number?
  w : number?


# 4.2 Booleans
```
Returns z raised to the power of w.

If w is exact 0, the result is exact 1. If w is 0.0 or -0.0 and z is a real number other than exact 1 or 0, the result is 1.0 (even if z is +nan.0).

If z is exact 1, the result is exact 1. If z is 1.0 and w is a real number, the result is 1.0 (even if w is +nan.0).

If z is exact 0, the result is as follows:

-  w is exact 0 — result is 1

-  w is 0.0 or -0.0 — result is 1.0

-  real part of w is negative — the exn:fail:contract:divide-by-zero exception is raised

-  w is nonreal with a nonpositive real part — the exn:fail:contract:divide-by-zero exception is raised

-  w is +nan.0 — result is +nan.0

-  otherwise — result is 0

If w is exact 1/2, the result is the same as (sqrt z), which can be exact. Other fractional powers are not treated specially in this manner:

Examples:

> ```racket
> > ( expt 9 1/2 )
> 3
> > ( expt 9 0.5 )
> 3.0
> > ( expt 16 1/4 )
> 2.0
> > ( expt 16 0.25 )
> 2.0
> ```

Further special cases when w is a real number: These special cases correspond to pow in C99 \[C99\], except when z is negative and w is a not an integer.

-

(expt 0.0 w):

-  w is negative — result is +inf.0

-  w is positive — result is 0.0

-

(expt -0.0 w):

-

w is negative:

-  w is an odd integer — result is -inf.0

-  w otherwise rational — result is +inf.0

-

w is positive:

-  w is an odd integer — result is -0.0

-  w otherwise rational — result is 0.0

-

(expt z -inf.0) for positive z:

-  z is less than 1.0 — result is +inf.0

-  z is greater than 1.0 — result is 0.0

-

(expt z +inf.0) for positive z:

-  z is less than 1.0 — result is 0.0

-  z is greater than 1.0 — result is +inf.0

-

(expt -inf.0 w) for integer w:

-

w is negative:

-  w is odd — result is -0.0

-  w is even — result is 0.0

-

w is positive:

-  w is odd — result is -inf.0

-  w is even — result is +inf.0

-

(expt +inf.0 w):

-  w is negative — result is 0.0

-  w is positive — result is +inf.0

Examples:

> ```racket
> > ( expt 2 3 )
> 8
> > ( expt 4 0.5 )
> 2.0
> > ( expt +inf.0 0 )
> 1
> ```

> ```
(exp z) → number?
  z : number?```

Returns Euler’s number raised to the power of z. The result is normally inexact, but it is exact 1 when z is an exact 0. See also [expt](#%28def._%28%28quote._~23~25kernel%29._expt%29%29).

Examples:

> ```racket
> > ( exp 1 )
> 2.718281828459045
> > ( exp 2+3i )
> -7.315110094901103+1.0427436562359045i
> > ( exp 0 )
> 1
> ```

> ```
(log z [b) → number?
  z : number?
  b : number? = (exp 1)
```


# 4.2 Booleans
Returns the natural logarithm of z. The result is normally inexact, but it is exact 0 when z is an exact 1. When z is exact 0, exn:fail:contract:divide-by-zero exception is raised.
If b is provided, it serves as an alternative base. It is equivalent to (/ (log z) (log b)), but can potentially run faster. If b is exact 1, exn:fail:contract:divide-by-zero exception is raised.
Consider using fllogb from math/flonum instead when accuracy is important.
Examples:
> ```racket
> > ( log ( exp 1 ) )
> 1.0
> > ( log 2+3i )
> 1.2824746787307684+0.982793723247329i
> > ( log 1 )
> 0
> > ( log 100 10 )
> 2.0
> > ( log 8 2 )
> 3.0
> > ( log 5 5 )
> 1.0
> ```
Changed in version 6.9.0.1 of package base: Added second argument for arbitrary bases.