Skip to content

Commit d9495c7

Browse files
committed
resolve Warning mismatch by renaming functions
1 parent 1892f74 commit d9495c7

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

doc/manual/control-flow.rst

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ So, we could have defined the ``test`` function above as
128128

129129
.. doctest::
130130

131-
julia> function test(x,y)
131+
julia> function test1(x,y)
132132
if x < y
133133
relation = "less than"
134134
elseif x == y
@@ -138,7 +138,7 @@ So, we could have defined the ``test`` function above as
138138
end
139139
println("x is ", relation, " y.")
140140
end
141-
test (generic function with 1 method)
141+
test1 (generic function with 1 method)
142142

143143
The variable ``relation`` is declared inside the ``if`` block, but used
144144
outside. However, when depending on this behavior, make sure all possible
@@ -147,22 +147,22 @@ the above function results in a runtime error
147147

148148
.. doctest::
149149

150-
julia> function test(x,y)
150+
julia> function test2(x,y)
151151
if x < y
152152
relation = "less than"
153153
elseif x == y
154154
relation = "equal to"
155155
end
156156
println("x is ", relation, " y.")
157157
end
158-
test (generic function with 1 method)
158+
test2 (generic function with 1 method)
159159

160-
julia> test(1,2)
160+
julia> test2(1,2)
161161
x is less than y.
162162

163-
julia> test(2,1)
163+
julia> test2(2,1)
164164
ERROR: UndefVarError: relation not defined
165-
in test(::Int64, ::Int64) at ./none:7
165+
in test2(::Int64, ::Int64) at ./none:7
166166
in eval(::Module, ::Any) at ./boot.jl:237
167167

168168
``if`` blocks also return a value, which may seem unintuitive to users
@@ -238,17 +238,17 @@ together:
238238

239239
.. doctest::
240240

241-
julia> test(x, y) = println(x < y ? "x is less than y" :
241+
julia> test4(x, y) = println(x < y ? "x is less than y" :
242242
x > y ? "x is greater than y" : "x is equal to y")
243-
test (generic function with 1 method)
243+
test4 (generic function with 1 method)
244244

245-
julia> test(1, 2)
245+
julia> test4(1, 2)
246246
x is less than y
247247

248-
julia> test(2, 1)
248+
julia> test4(2, 1)
249249
x is greater than y
250250

251-
julia> test(1, 1)
251+
julia> test4(1, 1)
252252
x is equal to y
253253

254254
To facilitate chaining, the operator associates from right to left.
@@ -684,15 +684,15 @@ if the argument is negative:
684684

685685
.. doctest::
686686

687-
julia> f(x) = x>=0 ? exp(-x) : throw(DomainError())
688-
f (generic function with 1 method)
687+
julia> g(x) = x>=0 ? exp(-x) : throw(DomainError())
688+
g (generic function with 1 method)
689689

690-
julia> f(1)
690+
julia> g(1)
691691
0.36787944117144233
692692

693-
julia> f(-1)
693+
julia> g(-1)
694694
ERROR: DomainError:
695-
in f(::Int64) at ./none:1
695+
in g(::Int64) at ./none:1
696696
in eval(::Module, ::Any) at ./boot.jl:237
697697

698698
Note that :exc:`DomainError` without parentheses is not an exception, but a type of
@@ -808,17 +808,17 @@ call either the real or complex square root method on demand using
808808

809809
.. doctest::
810810

811-
julia> f(x) = try
811+
julia> h(x) = try
812812
sqrt(x)
813813
catch
814814
sqrt(complex(x, 0))
815815
end
816-
f (generic function with 1 method)
816+
h (generic function with 1 method)
817817

818-
julia> f(1)
818+
julia> h(1)
819819
1.0
820820

821-
julia> f(-1)
821+
julia> h(-1)
822822
0.0 + 1.0im
823823

824824
It is important to note that in real code computing this function, one would

doc/manual/methods.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,19 @@ the intersection case:
418418

419419
.. doctest::
420420

421-
julia> g(x::Float64, y::Float64) = 2x + 2y;
421+
julia> h(x::Float64, y::Float64) = 2x + 2y;
422422

423-
julia> g(x::Float64, y) = 2x + y;
423+
julia> h(x::Float64, y) = 2x + y;
424424

425-
julia> g(x, y::Float64) = x + 2y;
425+
julia> h(x, y::Float64) = x + 2y;
426426

427-
julia> g(2.0, 3)
427+
julia> h(2.0, 3)
428428
7.0
429429

430-
julia> g(2, 3.0)
430+
julia> h(2, 3.0)
431431
8.0
432432

433-
julia> g(2.0, 3.0)
433+
julia> h(2.0, 3.0)
434434
10.0
435435

436436
To suppress Julia's warning, the disambiguating method must be defined

doc/manual/stacktraces.rst

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ helpful in many places, the most obvious application is in error handling and de
118118
julia> @noinline bad_function() = undeclared_variable
119119
bad_function (generic function with 1 method)
120120

121-
julia> @noinline example() = try
121+
julia> @noinline example1() = try
122122
bad_function()
123123
catch
124124
stacktrace()
125125
end
126-
example (generic function with 1 method)
126+
example1 (generic function with 1 method)
127127

128-
julia> example()
128+
julia> example1()
129129
...-element Array{StackFrame,1}:
130130
[inlined code] from stacktraces.jl:135
131-
in example() at none:2
131+
in example1() at none:2
132132
in eval(::Module, ::Any) at boot.jl:237
133133
[inlined code] from sysimg.jl:11
134134
...
@@ -146,20 +146,20 @@ returns stack information for the context of the most recent exception:
146146

147147
.. doctest::
148148

149-
julia> @noinline bad_function() = undeclared_variable
150-
bad_function (generic function with 1 method)
149+
julia> @noinline bad_function1() = undeclared_variable
150+
bad_function1 (generic function with 1 method)
151151

152-
julia> @noinline example() = try
153-
bad_function()
152+
julia> @noinline example2() = try
153+
bad_function1()
154154
catch
155155
catch_stacktrace()
156156
end
157-
example (generic function with 1 method)
157+
example2 (generic function with 1 method)
158158

159-
julia> example()
159+
julia> example2()
160160
...-element Array{StackFrame,1}:
161-
in bad_function() at none:1
162-
in example() at none:2
161+
in bad_function1() at none:1
162+
in example2() at none:2
163163
in eval(::Module, ::Any) at boot.jl:237
164164
[inlined code] from sysimg.jl:11
165165
...
@@ -168,28 +168,28 @@ Notice that the stack trace now indicates the appropriate line number and the mi
168168

169169
.. doctest::
170170

171-
julia> @noinline child() = error("Whoops!")
172-
child (generic function with 1 method)
171+
julia> @noinline child1() = error("Whoops!")
172+
child1 (generic function with 1 method)
173173

174-
julia> @noinline parent() = child()
175-
parent (generic function with 1 method)
174+
julia> @noinline parent1() = child1()
175+
parent1 (generic function with 1 method)
176176

177-
julia> @noinline function grandparent()
177+
julia> @noinline function grandparent1()
178178
try
179-
parent()
179+
parent1()
180180
catch err
181181
println("ERROR: ", err.msg)
182182
catch_stacktrace()
183183
end
184184
end
185-
grandparent (generic function with 1 method)
185+
grandparent1 (generic function with 1 method)
186186

187-
julia> grandparent()
187+
julia> grandparent1()
188188
ERROR: Whoops!
189189
...-element Array{StackFrame,1}:
190-
in child() at none:1
191-
in parent() at none:1
192-
in grandparent() at none:3
190+
in child1() at none:1
191+
in parent1() at none:1
192+
in grandparent1() at none:3
193193
in eval(::Module, ::Any) at boot.jl:237
194194
[inlined code] from sysimg.jl:11
195195
...

0 commit comments

Comments
 (0)