<commit_before>#lang scribble/doc
@(require "mz.rkt")

@(define bool-eval (make-base-eval))
@(bool-eval '(require racket/bool))

@title[#:tag "booleans"]{Booleans and Equality}

True and false @deftech{booleans} are represented by the values
@racket[#t] and @racket[#f], respectively, though operations that
depend on a boolean value typically treat anything other than
@racket[#f] as true. The @racket[#t] value is always @racket[eq?] to
itself, and @racket[#f] is always @racket[eq?] to itself.

@see-read-print["boolean" #:print "booleans"]{booleans}

See also @racket[and], @racket[or], @racket[andmap], and @racket[ormap].


@defproc[(boolean? [v any/c]) boolean?]{

Returns @racket[#t] if @racket[v] is @racket[#t] or @racket[#f],
@racket[#f] otherwise.

@examples[
(boolean? #f)
(boolean? #t)
(boolean? 'true)
]}


@defproc[(not [v any/c]) boolean?]{

Returns @racket[#t] if @racket[v] is @racket[#f], @racket[#f] otherwise.

@examples[
(not #f)
(not #t)
(not 'we-have-no-bananas)
]}


@defproc[(equal? [v1 any/c] [v2 any/c]) boolean?]{

Two values are @racket[equal?] if and only if they are @racket[eqv?],
unless otherwise specified for a particular datatype.

Datatypes with further specification of @racket[equal?] 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 @racket[v1] and @racket[v2] contain
reference cycles, they are equal when the infinite unfoldings of the
values would be equal. See also @racket[gen:equal+hash] and @racket[prop:impersonator-of].

@examples[
(equal? 'yes 'yes)
(equal? 'yes 'no)
(equal? (expt 2 100) (expt 2 100))
(equal? 2 2.0)
(equal? (make-string 3 #\z) (make-string 3 #\z))
]}


@defproc[(eqv? [v1 any/c] [v2 any/c]) boolean?]{

Two values are @racket[eqv?] if and only if they are @racket[eq?],
unless otherwise specified for a particular datatype.

The @tech{number} and @tech{character} datatypes are the only ones for
which @racket[eqv?] differs from @racket[eq?]. Two numbers are
@racket[eqv?] when they have the same exactness, precision, and are
both equal and non-zero, both @racket[+0.0], both @racket[+0.0f0], both
@racket[-0.0], both @racket[-0.0f0], both @racket[+nan.0], or both
@racket[+nan.f]---considering real and imaginary components separately
in the case of @tech{complex numbers}. Two characters are
@racket[eqv?] when their @racket[char->integer] results are equal.

@examples[
(eqv? 'yes 'yes)
(eqv? 'yes 'no)
(eqv? (expt 2 100) (expt 2 100))
(eqv? 2 2.0)
(eqv? (integer->char #x3BB) (integer->char #x3BB))
(eqv? (make-string 3 #\z) (make-string 3 #\z))
]}


@defproc[(eq? [v1 any/c] [v2 any/c]) boolean?]{

Return @racket[#t] if @racket[v1] and @racket[v2] refer to the same
object, @racket[#f] otherwise. See also @secref["model-eq"].

@examples[
(eq? 'yes 'yes)
(eq? 'yes 'no)
(let ([v (mcons 1 2)]) (eq? v v))
(eq? (mcons 1 2) (mcons 1 2))
(eq? (make-string 3 #\z) (make-string 3 #\z))
]}


@defproc[(equal?/recur [v1 any/c] [v2 any/c] [recur-proc (any/c any/c -> any/c)]) boolean?]{

Like @racket[equal?], but using @racket[recur-proc] for recursive
comparisons (which means that reference cycles are not handled<commit_msg>Update examples for `equal?` `eqv?` `eq?` (#1391)<commit_after>#lang scribble/doc
@(require "mz.rkt")

@(define bool-eval (make-base-eval))
@(bool-eval '(require racket/bool))

@title[#:tag "booleans"]{Booleans and Equality}

True and false @deftech{booleans} are represented by the values
@racket[#t] and @racket[#f], respectively, though operations that
depend on a boolean value typically treat anything other than
@racket[#f] as true. The @racket[#t] value is always @racket[eq?] to
itself, and @racket[#f] is always @racket[eq?] to itself.

@see-read-print["boolean" #:print "booleans"]{booleans}

See also @racket[and], @racket[or], @racket[andmap], and @racket[ormap].


@defproc[(boolean? [v any/c]) boolean?]{

Returns @racket[#t] if @racket[v] is @racket[#t] or @racket[#f],
@racket[#f] otherwise.

@examples[
(boolean? #f)
(boolean? #t)
(boolean? 'true)
]}


@defproc[(not [v any/c]) boolean?]{

Returns @racket[#t] if @racket[v] is @racket[#f], @racket[#f] otherwise.

@examples[
(not #f)
(not #t)
(not 'we-have-no-bananas)
]}


@defproc[(equal? [v1 any/c] [v2 any/c]) boolean?]{

Two values are @racket[equal?] if and only if they are @racket[eqv?],
unless otherwise specified for a particular datatype.

Datatypes with further specification of @racket[equal?] 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 @racket[v1] and @racket[v2] contain
reference cycles, they are equal when the infinite unfoldings of the
values would be equal. See also @racket[gen:equal+hash] and @racket[prop:impersonator-of].

@examples[
(equal? 'yes 'yes)
(equal? 'yes 'no)
(equal? (expt 2 100) (expt 2 100))
(equal? 2 2.0)
(let ([v (mcons 1 2)]) (equal? v v))
(equal? (mcons 1 2) (mcons 1 2))
(equal? (integer->char 955) (integer->char 955))
(equal? (make-string 3 #\z) (make-string 3 #\z))
]}


@defproc[(eqv? [v1 any/c] [v2 any/c]) boolean?]{

Two values are @racket[eqv?] if and only if they are @racket[eq?],
unless otherwise specified for a particular datatype.

The @tech{number} and @tech{character} datatypes are the only ones for
which @racket[eqv?] differs from @racket[eq?]. Two numbers are
@racket[eqv?] when they have the same exactness, precision, and are
both equal and non-zero, both @racket[+0.0], both @racket[+0.0f0], both
@racket[-0.0], both @racket[-0.0f0], both @racket[+nan.0], or both
@racket[+nan.f]---considering real and imaginary components separately
in the case of @tech{complex numbers}. Two characters are
@racket[eqv?] when their @racket[char->integer] results are equal.

@examples[
(eqv? 'yes 'yes)
(eqv? 'yes 'no)
(eqv? (expt 2 100) (expt 2 100))
(eqv? 2 2.0)
(let ([v (mcons 1 2)]) (eqv? v v))
(eqv? (mcons 1 2) (mcons 1 2))
(eqv? (integer->char 955) (integer->char 955))
(eqv? (make-string 3 #\z) (make-string 3 #\z))
]}


@defproc[(eq? [v1 any/c] [v2 any/c]) boolean?]{

Return @racket[#t] if @racket[v1] and @racket[v2] refer to the same
object, @racket[#f] otherwise. See also @secref["model-eq"].

@examples[
(eq? 'yes 'yes)
(eq? 'yes 'no)
(eq? (expt 2 100) (expt 2 100))
(eq? 2 2.0)
(let ([v (mcons 1 2)]) (eq? v v))
(eq? (mcons 1 2) (mcons 1 2))
(eq? (integer->char 955) (integer->char 955))
(eq? (make-string 3 #\z) (make-string 3 #\z))
]}


@defproc[(equal?/recur [v1 any/c] [v2 any/c] [recur-proc (any/c any/c -> any/c)]) boolean?]{

Like @racket[equal?], but using @racket[recur-proc] for recursive
comparisons (which means that reference cycles are not handled
{'fraction_non_alphanumeric': 0.17582580358465413, 'fraction_numerical': 0.02384831876758999, 'mean_word_length': 5.160583941605839, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3429967', 'n_tokens_mistral': 2768, 'n_tokens_neox': 2625, 'n_words': 869}