Skip to content

Commit

Permalink
resolve Warning mismatch by renaming functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Jun 23, 2016
1 parent 1892f74 commit d9495c7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 50 deletions.
42 changes: 21 additions & 21 deletions doc/manual/control-flow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ So, we could have defined the ``test`` function above as

.. doctest::

julia> function test(x,y)
julia> function test1(x,y)
if x < y
relation = "less than"
elseif x == y
Expand All @@ -138,7 +138,7 @@ So, we could have defined the ``test`` function above as
end
println("x is ", relation, " y.")
end
test (generic function with 1 method)
test1 (generic function with 1 method)

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

.. doctest::

julia> function test(x,y)
julia> function test2(x,y)
if x < y
relation = "less than"
elseif x == y
relation = "equal to"
end
println("x is ", relation, " y.")
end
test (generic function with 1 method)
test2 (generic function with 1 method)

julia> test(1,2)
julia> test2(1,2)
x is less than y.

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

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

.. doctest::

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

julia> test(1, 2)
julia> test4(1, 2)
x is less than y

julia> test(2, 1)
julia> test4(2, 1)
x is greater than y

julia> test(1, 1)
julia> test4(1, 1)
x is equal to y

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

.. doctest::

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

julia> f(1)
julia> g(1)
0.36787944117144233

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

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

.. doctest::

julia> f(x) = try
julia> h(x) = try
sqrt(x)
catch
sqrt(complex(x, 0))
end
f (generic function with 1 method)
h (generic function with 1 method)

julia> f(1)
julia> h(1)
1.0

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

It is important to note that in real code computing this function, one would
Expand Down
12 changes: 6 additions & 6 deletions doc/manual/methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -418,19 +418,19 @@ the intersection case:

.. doctest::

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

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

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

julia> g(2.0, 3)
julia> h(2.0, 3)
7.0

julia> g(2, 3.0)
julia> h(2, 3.0)
8.0

julia> g(2.0, 3.0)
julia> h(2.0, 3.0)
10.0

To suppress Julia's warning, the disambiguating method must be defined
Expand Down
46 changes: 23 additions & 23 deletions doc/manual/stacktraces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ helpful in many places, the most obvious application is in error handling and de
julia> @noinline bad_function() = undeclared_variable
bad_function (generic function with 1 method)

julia> @noinline example() = try
julia> @noinline example1() = try
bad_function()
catch
stacktrace()
end
example (generic function with 1 method)
example1 (generic function with 1 method)

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

.. doctest::

julia> @noinline bad_function() = undeclared_variable
bad_function (generic function with 1 method)
julia> @noinline bad_function1() = undeclared_variable
bad_function1 (generic function with 1 method)

julia> @noinline example() = try
bad_function()
julia> @noinline example2() = try
bad_function1()
catch
catch_stacktrace()
end
example (generic function with 1 method)
example2 (generic function with 1 method)

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

.. doctest::

julia> @noinline child() = error("Whoops!")
child (generic function with 1 method)
julia> @noinline child1() = error("Whoops!")
child1 (generic function with 1 method)

julia> @noinline parent() = child()
parent (generic function with 1 method)
julia> @noinline parent1() = child1()
parent1 (generic function with 1 method)

julia> @noinline function grandparent()
julia> @noinline function grandparent1()
try
parent()
parent1()
catch err
println("ERROR: ", err.msg)
catch_stacktrace()
end
end
grandparent (generic function with 1 method)
grandparent1 (generic function with 1 method)

julia> grandparent()
julia> grandparent1()
ERROR: Whoops!
...-element Array{StackFrame,1}:
in child() at none:1
in parent() at none:1
in grandparent() at none:3
in child1() at none:1
in parent1() at none:1
in grandparent1() at none:3
in eval(::Module, ::Any) at boot.jl:237
[inlined code] from sysimg.jl:11
...
Expand Down

0 comments on commit d9495c7

Please sign in to comment.