Skip to content

Commit e67a22c

Browse files
authored
Convert some julia-repl examples to doctests (#57452)
Some progress towards #56921.
1 parent b9a8d46 commit e67a22c

File tree

9 files changed

+31
-26
lines changed

9 files changed

+31
-26
lines changed

base/bitarray.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ BitVector() = BitVector(undef, 0)
8181
8282
Construct a `BitVector` from a tuple of `Bool`.
8383
# Examples
84-
```julia-repl
84+
```jldoctest
8585
julia> nt = (true, false, true, false)
8686
(true, false, true, false)
8787

base/essentials.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ f(y) = [x for x in y]
9393
9494
# Examples
9595
96-
```julia-repl
96+
```jldoctest; setup = :(using InteractiveUtils)
9797
julia> f(A::AbstractArray) = g(A)
9898
f (generic function with 1 method)
9999
@@ -102,7 +102,7 @@ g (generic function with 1 method)
102102
103103
julia> @code_typed f([1.0])
104104
CodeInfo(
105-
1 ─ %1 = invoke Main.g(_2::AbstractArray)::Float64
105+
1 ─ %1 = invoke g(A::AbstractArray)::Float64
106106
└── return %1
107107
) => Float64
108108
```

base/expr.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Take the expression `x` and return an equivalent expression with all macros remo
103103
for executing in module `m`.
104104
The `recursive` keyword controls whether deeper levels of nested macros are also expanded.
105105
This is demonstrated in the example below:
106-
```julia-repl
106+
```jldoctest; filter = r"#= .*:6 =#"
107107
julia> module M
108108
macro m1()
109109
42
@@ -118,7 +118,7 @@ julia> macroexpand(M, :(@m2()), recursive=true)
118118
42
119119
120120
julia> macroexpand(M, :(@m2()), recursive=false)
121-
:(#= REPL[16]:6 =# M.@m1)
121+
:(#= REPL[1]:6 =# @m1)
122122
```
123123
"""
124124
function macroexpand(m::Module, @nospecialize(x); recursive=true)
@@ -926,7 +926,7 @@ This can be used to limit the number of compiler-generated specializations durin
926926
927927
# Examples
928928
929-
```julia
929+
```jldoctest; setup = :(using InteractiveUtils)
930930
julia> f(A::AbstractArray) = g(A)
931931
f (generic function with 1 method)
932932
@@ -935,7 +935,7 @@ g (generic function with 1 method)
935935
936936
julia> @code_typed f([1.0])
937937
CodeInfo(
938-
1 ─ %1 = invoke Main.g(_2::AbstractArray)::Any
938+
1 ─ %1 = invoke g(A::AbstractArray)::Any
939939
└── return %1
940940
) => Any
941941
```

base/loading.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ otherwise it searches all recursive dependencies (from the resolved manifest of
417417
each environment) until it locates the context `where`, and from there
418418
identifies the dependency with the corresponding name.
419419
420-
```julia-repl
420+
```jldoctest
421421
julia> Base.identify_package("Pkg") # Pkg is a dependency of the default environment
422422
Pkg [44cfe95a-1eb2-52ea-b672-e2afdf69b78f]
423423

base/twiceprecision.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ representation, even though it is exact from the standpoint of binary
6363
representation.
6464
6565
Example:
66-
```julia-repl
66+
```jldoctest
6767
julia> 1.0 + 1.0001e-15
6868
1.000000000000001
6969
@@ -94,7 +94,7 @@ numbers. Mathematically, `zhi + zlo = x * y`, where `zhi` contains the
9494
most significant bits and `zlo` the least significant.
9595
9696
Example:
97-
```julia-repl
97+
```jldoctest
9898
julia> x = Float32(π)
9999
3.1415927f0
100100
@@ -126,7 +126,7 @@ numbers. Mathematically, `zhi + zlo ≈ x / y`, where `zhi` contains the
126126
most significant bits and `zlo` the least significant.
127127
128128
Example:
129-
```julia-repl
129+
```jldoctest
130130
julia> x, y = Float32(π), 3.1f0
131131
(3.1415927f0, 3.1f0)
132132

doc/src/manual/arrays.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ dimension `d`. For example, the builtin `Array` returned by `rand(5,7,2)` has it
11601160
arranged contiguously in column major order. This means that the stride of the first
11611161
dimension — the spacing between elements in the same column — is `1`:
11621162

1163-
```julia-repl
1163+
```jldoctest strides
11641164
julia> A = rand(5, 7, 2);
11651165
11661166
julia> stride(A, 1)
@@ -1172,7 +1172,7 @@ as many elements as there are in a single column (`5`). Similarly, jumping betwe
11721172
"pages" (in the third dimension) requires skipping `5*7 == 35` elements. The [`strides`](@ref)
11731173
of this array is the tuple of these three numbers together:
11741174

1175-
```julia-repl
1175+
```jldoctest strides
11761176
julia> strides(A)
11771177
(1, 5, 35)
11781178
```
@@ -1185,7 +1185,7 @@ This view `V` refers to the same memory as `A` but is skipping and re-arranging
11851185
elements. The stride of the first dimension of `V` is `3` because we're only selecting every
11861186
third row from our original array:
11871187

1188-
```julia-repl
1188+
```jldoctest strides
11891189
julia> V = @view A[1:3:4, 2:2:6, 2:-1:1];
11901190
11911191
julia> stride(V, 1)
@@ -1196,7 +1196,7 @@ This view is similarly selecting every other column from our original `A` — an
11961196
needs to skip the equivalent of two five-element columns when moving between indices in the
11971197
second dimension:
11981198

1199-
```julia-repl
1199+
```jldoctest strides
12001200
julia> stride(V, 2)
12011201
10
12021202
```
@@ -1205,7 +1205,7 @@ The third dimension is interesting because its order is reversed! Thus to get fr
12051205
"page" to the second one it must go _backwards_ in memory, and so its stride in this
12061206
dimension is negative!
12071207

1208-
```julia-repl
1208+
```jldoctest strides
12091209
julia> stride(V, 3)
12101210
-35
12111211
```

doc/src/manual/functions.md

+13-8
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,12 @@ The destructuring feature can also be used within a function argument.
584584
If a function argument name is written as a tuple (e.g. `(x, y)`) instead of just
585585
a symbol, then an assignment `(x, y) = argument` will be inserted for you:
586586

587-
```julia-repl
587+
```jldoctest
588588
julia> minmax(x, y) = (y < x) ? (y, x) : (x, y)
589+
minmax (generic function with 1 method)
589590
590591
julia> gap((min, max)) = max - min
592+
gap (generic function with 1 method)
591593
592594
julia> gap(minmax(10, 2))
593595
8
@@ -598,7 +600,7 @@ would be a two-argument function, and this example would not work.
598600

599601
Similarly, property destructuring can also be used for function arguments:
600602

601-
```julia-repl
603+
```jldoctest
602604
julia> foo((; x, y)) = x + y
603605
foo (generic function with 1 method)
604606
@@ -616,7 +618,7 @@ julia> foo(A(3, 4))
616618

617619
For anonymous functions, destructuring a single argument requires an extra comma:
618620

619-
```julia-repl
621+
```jldoctest
620622
julia> map(((x, y),) -> x + y, [(1, 2), (3, 4)])
621623
2-element Vector{Int64}:
622624
3
@@ -784,12 +786,15 @@ Optional arguments are actually just a convenient syntax for writing multiple me
784786
with different numbers of arguments (see [Note on Optional and keyword Arguments](@ref)).
785787
This can be checked for our `date` function example by calling the `methods` function:
786788

787-
```julia-repl
789+
```jldoctest date_default_args; filter = r"@ .*"a
788790
julia> methods(date)
789-
# 3 methods for generic function "date":
790-
[1] date(y::Int64) in Main at REPL[1]:1
791-
[2] date(y::Int64, m::Int64) in Main at REPL[1]:1
792-
[3] date(y::Int64, m::Int64, d::Int64) in Main at REPL[1]:1
791+
# 3 methods for generic function "date" from Main:
792+
[1] date(y::Int64, m::Int64, d::Int64)
793+
@ REPL[2]:1
794+
[2] date(y::Int64, m::Int64)
795+
@ REPL[2]:1
796+
[3] date(y::Int64)
797+
@ REPL[2]:1
793798
```
794799

795800
## Keyword Arguments

doc/src/manual/metaprogramming.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ Since expressions are just `Expr` objects which can be constructed programmatica
413413
it is possible to dynamically generate arbitrary code which can then be run using [`eval`](@ref).
414414
Here is a simple example:
415415

416-
```julia-repl
416+
```jldoctest
417417
julia> a = 1;
418418
419419
julia> ex = Expr(:call, :+, a, :b)

stdlib/Sockets/src/addrinfo.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Uses the operating system's underlying getaddrinfo implementation, which may do
129129
a DNS lookup.
130130
131131
# Examples
132-
```julia-repl
132+
```jldoctest
133133
julia> getaddrinfo("localhost", IPv6)
134134
ip"::1"
135135

0 commit comments

Comments
 (0)