diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index d1142f0775412..f42382d9ba2de 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -5445,7 +5445,8 @@ julia> deleteat!([6, 5, 4, 3, 2, 1], 1:2:5) julia> deleteat!([6, 5, 4, 3, 2, 1], (2, 2)) ERROR: ArgumentError: indices must be unique and sorted - in deleteat! at array.jl:543 + in deleteat!(::Array{Int64,1}, ::Tuple{Int64,Int64}) at ./array.jl:511 + ... ``` """ deleteat!(collection, itr) @@ -8104,7 +8105,8 @@ julia> convert(Int, 3.0) julia> convert(Int, 3.5) ERROR: InexactError() - in convert at int.jl:209 + in convert(::Type{Int64}, ::Float64) at ./int.jl:239 + ... ``` If `T` is a [`AbstractFloat`](:obj:`AbstractFloat`) or [`Rational`](:obj:`Rational`) type, @@ -9120,10 +9122,7 @@ on the `permute` and `scale` keyword arguments. The eigenvectors are returned co ```jldoctest julia> eig([1.0 0.0 0.0; 0.0 3.0 0.0; 0.0 0.0 18.0]) ([1.0,3.0,18.0], -3×3 Array{Float64,2}: - 1.0 0.0 0.0 - 0.0 1.0 0.0 - 0.0 0.0 1.0) +[1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0]) ``` `eig` is a wrapper around [`eigfact`](:func:`eigfact`), extracting all parts of the diff --git a/base/reflection.jl b/base/reflection.jl index 9e1e27a517d96..36b8ad34a2314 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -126,7 +126,7 @@ use it in the following manner to summarize information about a struct type: julia> structinfo(T) = [(fieldoffset(T,i), fieldname(T,i), fieldtype(T,i)) for i = 1:nfields(T)]; julia> structinfo(Base.Filesystem.StatStruct) -12-element Array{Tuple{UInt64,Symbol,Type{_}},1}: +12-element Array{Tuple{UInt64,Union{Int64,Symbol},Type{_}},1}: (0x0000000000000000,:device,UInt64) (0x0000000000000008,:inode,UInt64) (0x0000000000000010,:mode,UInt64) diff --git a/base/test.jl b/base/test.jl index b0382f3284f5c..2681d48ee573a 100644 --- a/base/test.jl +++ b/base/test.jl @@ -893,24 +893,19 @@ julia> typeof(f(1,2,3)) Int64 julia> @code_warntype f(1,2,3) -Variables: - #self#::#f - a::Int64 - b::Int64 - c::Int64 - +... Body: - begin # REPL[2], line 1: - unless (Base.slt_int)(1,b::Int64)::Bool goto 4 + begin + unless (Base.slt_int)(1,b::Int64)::Bool goto 3 return 1 - 4: + 3: return 1.0 - end::Union{Float64,Int64} + end::UNION{FLOAT64,INT64} julia> @inferred f(1,2,3) ERROR: return type Int64 does not match inferred return type Union{Float64,Int64} in error(::String) at ./error.jl:21 - in eval(::Module, ::Any) at ./boot.jl:226 + ... julia> @inferred max(1,2) 2 diff --git a/doc/devdocs/reflection.rst b/doc/devdocs/reflection.rst index 2f3ace38417db..185016495c732 100644 --- a/doc/devdocs/reflection.rst +++ b/doc/devdocs/reflection.rst @@ -92,7 +92,7 @@ the macro will be evaluated and the result will be passed instead!). For example .. doctest:: julia> macroexpand( :(@edit println("")) ) - :(Base.edit(println,(Base.typesof)(""))) + :((Base.edit)(println,(Base.typesof)(""))) The functions :func:`Base.Meta.show_sexpr` and :func:`dump` are used to display S-expr style views and depth-nested detail views for any expression. @@ -104,9 +104,14 @@ variable assignments: .. doctest:: julia> expand( :(f() = 1) ) - :($(Expr(:method, :f, :((top(svec))((top(apply_type))(Tuple),(top(svec))())), AST(:($(Expr(:lambda, Any[], Any[Any[],Any[],0,Any[]], :(begin # none, line 1: + :(begin + $(Expr(:method, :f)) + $(Expr(:method, :f, :((Core.svec)((Core.apply_type)(Tuple,(Core.Typeof)(f)),(Core.svec)())), Toplevel LambdaInfo thunk + :(begin # none, line 1: return 1 - end))))), false))) + end), false)) + return f + end) .. rubric:: Intermediate and compiled representations diff --git a/doc/devdocs/types.rst b/doc/devdocs/types.rst index a75f1830f1fbd..7f9c089eafa25 100644 --- a/doc/devdocs/types.rst +++ b/doc/devdocs/types.rst @@ -91,7 +91,7 @@ Let's look at these types a little more closely: Array{T,N} julia> dump(Array) - Array{T,N}::DataType <: DenseArray{T,N} + Array{T,N} <: DenseArray{T,N} This indicates that :obj:`Array` is a shorthand for ``Array{T,N}``. If you type this at the REPL prompt---on its own, not while defining @@ -108,7 +108,7 @@ parameters: TypeVar name: Symbol T lb: Union{} - ub: Any::DataType <: Any + ub: Any bound: Bool false A :obj:`TypeVar` is one of Julia's built-in types---it's defined in @@ -130,9 +130,9 @@ one can extract the underlying :obj:`TypeVar`: .. testcode:: s g{S<:Integer}(x::S) = 0 - m = start(methods(g)) + m = first(methods(g)) p = m.sig.parameters - tv = p[1] + tv = p[2] dump(tv) .. testoutput:: s @@ -140,7 +140,7 @@ one can extract the underlying :obj:`TypeVar`: TypeVar name: Symbol S lb: Union{} - ub: Integer::DataType <: Real + ub: Integer <: Real bound: Bool true Here ``ub`` is ``Integer``, as specified in the function definition. @@ -160,27 +160,27 @@ parameters. For example: julia> h3{T<:Real}(A::Array{T}, b::T) = 1 h3 (generic function with 1 method) - julia> p1 = start(methods(h1)).sig.parameters - svec(Array{T,N},Real) + julia> p1 = first(methods(h1)).sig.parameters + svec(#h1,Array{T,N},Real) - julia> p2 = start(methods(h2)).sig.parameters - svec(Array{T,N},T<:Real) + julia> p2 = first(methods(h2)).sig.parameters + svec(#h2,Array{T,N},T<:Real) - julia> p3 = start(methods(h3)).sig.parameters - svec(Array{T<:Real,N},T<:Real) + julia> p3 = first(methods(h3)).sig.parameters + svec(#h3,Array{T<:Real,N},T<:Real) - julia> dump(p1[1].parameters[1]) + julia> dump(p1[2].parameters[1]) TypeVar name: Symbol T lb: Union{} - ub: Any::DataType <: Any + ub: Any bound: Bool false - julia> dump(p3[1].parameters[1]) + julia> dump(p3[2].parameters[1]) TypeVar name: Symbol T lb: Union{} - ub: Real::DataType <: Number + ub: Real <: Number bound: Bool true Note that ``p2`` shows two objects called ``T``, but only one of them @@ -215,20 +215,21 @@ a lot about how Julia does dispatch: julia> methods(candid) # 1 method for generic function "candid": - candid{T}(A::Array{T,N}, x::T) at none:1 + candid{T}(A::Array{T,N<:Any}, x::T) at none:1 julia> methods(sneaky) # 1 method for generic function "sneaky": - sneaky{T}(A::Array{T,N}, x::T) at none:1 + sneaky{T}(A::Array{T,N<:Any}, x::T<:Any) at none:1 These therefore print identically, but they have very different behavior: .. doctest:: julia> candid([1],3.2) - ERROR: MethodError: `candid` has no method matching candid(::Array{Int64,1}, ::Float64) + ERROR: MethodError: no method matching candid(::Array{Int64,1}, ::Float64) Closest candidates are: candid{T}(::Array{T,N}, !Matched::T) + ... julia> sneaky([1],3.2) 1 @@ -244,11 +245,11 @@ bound :obj:`TypeVar` objects with a hash (``#T`` instead of ``T``): .. doctest:: - julia> jl_(start(methods(candid))) - Method(sig=Tuple{Array{#T<:Any, N<:Any}, #T<:Any}, va=false, isstaged=false, tvars=#T<:Any, func=#, invokes=nothing, next=nothing) + julia> jl_(first(methods(candid))) + Method(sig=Tuple{Main.#candid, Array{#T<:Any, N<:Any}, #T<:Any}, va=false, isstaged=false, tvars=#T<:Any, func=Main.candid(?), invokes=nothing, next=nothing) - julia> jl_(start(methods(sneaky))) - Method(sig=Tuple{Array{#T<:Any, N<:Any}, T<:Any}, va=false, isstaged=false, tvars=#T<:Any, func=#, invokes=nothing, next=nothing) + julia> jl_(first(methods(sneaky))) + Method(sig=Tuple{Main.#sneaky, Array{#T<:Any, N<:Any}, T<:Any}, va=false, isstaged=false, tvars=#T<:Any, func=Main.sneaky(?), invokes=nothing, next=nothing) Even though both print as ``T``, in ``sneaky`` the second ``T`` is not bound, and hence it isn't constrained to be the same type as the @@ -314,14 +315,22 @@ the type, which is an object of type :obj:`TypeName`: TypeName name: Symbol Array module: Module Core - names: SimpleVector - length: Int64 0 - primary: Array{T,N}::DataType <: DenseArray{T,N} + names: empty SimpleVector + primary: Array{T,N} <: DenseArray{T,N} cache: SimpleVector - length: Int64 135 + ... linearcache: SimpleVector - length: Int64 18 - uid: Int64 37 + ... + uid: Int64 47 + mt: MethodTable + name: Symbol Array + defs: Void nothing + cache: Void nothing + max_args: Int64 0 + kwsorter: #undef + module: Module Core + : Int64 0 + : Int64 0 In this case, the relevant field is ``primary``, which holds a reference to the "primary" instance of the type:: @@ -357,20 +366,10 @@ type: MyType{Float32,5} julia> MyType.name.cache - svec(MyType{Float32,5},MyType{Int64,2},Evaluation succeeded, but an error occurred while showing value of type SimpleVector: - ERROR: UndefRefError: access to undefined reference - in getindex at ./essentials.jl:211 - in show_delim_array at show.jl:229 - in show at show.jl:257 - in anonymous at show.jl:1278 - in with_output_limit at ./show.jl:1255 - in showlimited at show.jl:1277 - in display at multimedia.jl:120 - [inlined code] from multimedia.jl:151 - in display at multimedia.jl:162 - -(The error is triggered because the cache is pre-allocated to have -length 8, but only the first two entries are populated.) + svec(MyType{Float32,5},MyType{Int64,2},#undef,#undef,#undef,#undef,#undef,#undef) + +(The cache is pre-allocated to have length 8, but only the first two entries +are populated.) Consequently, when you instantiate a parametric type, each concrete type gets saved in a type-cache. However, instances with :obj:`TypeVar` parameters are not cached. @@ -388,7 +387,7 @@ able to accommodate any tuple. Let's check the parameters: Tuple julia> Tuple.parameters - svec(Vararg{Any}) + svec(Vararg{Any,N}) It's worth noting that the parameter is a type, ``Any``, rather than a ``TypeVar T<:Any``: compare @@ -396,7 +395,7 @@ It's worth noting that the parameter is a type, ``Any``, rather than a .. doctest:: julia> jl_(Tuple.parameters) - svec(Vararg{Any}) + svec(Vararg{Any, N<:Any}) julia> jl_(Array.parameters) svec(T<:Any, N<:Any) diff --git a/doc/manual/arrays.rst b/doc/manual/arrays.rst index 007483ae3c8db..fe1431eb6a9b6 100644 --- a/doc/manual/arrays.rst +++ b/doc/manual/arrays.rst @@ -307,7 +307,7 @@ Example: .. doctest:: julia> x = reshape(1:16, 4, 4) - 4×4 Array{Int64,2}: + 4×4 Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}: 1 5 9 13 2 6 10 14 3 7 11 15 @@ -327,7 +327,7 @@ Example: 16 julia> x[1, [2 3; 4 1]] - 2x2 Array{Int64,2}: + 2×2 Array{Int64,2}: 5 9 13 1 @@ -376,7 +376,7 @@ Example: .. doctest:: - julia> x = reshape(1:9, 3, 3) + julia> x = collect(reshape(1:9, 3, 3)) 3×3 Array{Int64,2}: 1 4 7 2 5 8 @@ -411,7 +411,7 @@ The first construct is used when you need the value, but not index, of each elem type with fast linear indexing; otherwise, it will be a ``CartesianIndex``:: A = rand(4,3) - B = sub(A, 1:3, 2:3) + B = view(A, 1:3, 2:3) julia> for i in eachindex(B) @show i end @@ -497,9 +497,9 @@ the name of the function to vectorize. Here is a simple example: julia> methods(square) # 4 methods for generic function "square": - square{T<:Number}(::AbstractArray{T<:Number,1}) at operators.jl:374 - square{T<:Number}(::AbstractArray{T<:Number,2}) at operators.jl:375 - square{T<:Number}(::AbstractArray{T<:Number,N}) at operators.jl:377 + square{T<:Number}(x::AbstractArray{T,1}) at operators.jl:... + square{T<:Number}(x::AbstractArray{T,2}) at operators.jl:... + square{T<:Number}(x::AbstractArray{T,N<:Any}) at operators.jl:... square(x) at none:1 julia> square([1 2 4; 5 6 7]) @@ -599,10 +599,10 @@ library can be implemented in a generic manner. :obj:`SubArray` is a specialization of :obj:`AbstractArray` that performs indexing by reference rather than by copying. A :obj:`SubArray` is created -with the :func:`sub` function, which is called the same way as :func:`getindex` (with -an array and a series of index arguments). The result of :func:`sub` looks +with the :func:`view` function, which is called the same way as :func:`getindex` +(with an array and a series of index arguments). The result of :func:`view` looks the same as the result of :func:`getindex`, except the data is left in place. -:func:`sub` stores the input index vectors in a :obj:`SubArray` object, which +:func:`view` stores the input index vectors in a :obj:`SubArray` object, which can later be used to index the original array indirectly. :obj:`StridedVector` and :obj:`StridedMatrix` are convenient aliases defined @@ -630,8 +630,8 @@ stride parameters. 0.890947 0.168877 0.32002 0.486136 0.096078 0.172048 0.77672 0.507762 0.573567 0.220124 0.165816 0.211049 0.433277 0.539476 - julia> b = sub(a, 2:2:8,2:2:4) - 4×2 SubArray{Float64,2,Array{Float64,2},Tuple{StepRange{Int64,Int64},StepRange{Int64,Int64}},1}: + julia> b = view(a, 2:2:8,2:2:4) + 4×2 SubArray{Float64,2,Array{Float64,2},Tuple{StepRange{Int64,Int64},StepRange{Int64,Int64}},false}: 0.537192 0.996234 0.736979 0.228787 0.991511 0.74485 @@ -716,7 +716,7 @@ you can use the same names with an ``sp`` prefix: .. doctest:: julia> spzeros(3,5) - 3×5 sparse matrix with 0 Float64 nonzero entries: + 3×5 sparse matrix with 0 Float64 nonzero entries julia> speye(3,5) 3×5 sparse matrix with 3 Float64 nonzero entries: diff --git a/doc/manual/complex-and-rational-numbers.rst b/doc/manual/complex-and-rational-numbers.rst index 87712d917bb92..4a102e31407f8 100644 --- a/doc/manual/complex-and-rational-numbers.rst +++ b/doc/manual/complex-and-rational-numbers.rst @@ -159,7 +159,8 @@ versus ``-1 + 0im`` even though ``-1 == -1 + 0im``: julia> sqrt(-1) ERROR: DomainError: sqrt will only return a complex result if called with a complex argument. Try sqrt(complex(x)). - in sqrt at math.jl:146 + in sqrt(::Int64) at ./math.jl:149 + ... julia> sqrt(-1 + 0im) 0.0 + 1.0im @@ -305,6 +306,7 @@ Trying to construct a :const:`NaN` rational value, however, is not: ERROR: ArgumentError: invalid rational: zero(Int64)//zero(Int64) in Rational{Int64}(::Int64, ::Int64) at ./rational.jl:8 in //(::Int64, ::Int64) at ./rational.jl:22 + ... As usual, the promotion system makes interactions with other numeric types effortless: diff --git a/doc/manual/constructors.rst b/doc/manual/constructors.rst index 9207a19c42a7b..aef8a8f437a76 100644 --- a/doc/manual/constructors.rst +++ b/doc/manual/constructors.rst @@ -121,7 +121,8 @@ Now ``OrderedPair`` objects can only be constructed such that julia> OrderedPair(2,1) ERROR: out of order - in call at none:5 + in OrderedPair(::Int64, ::Int64) at ./none:5 + ... You can still reach in and directly change the field values to violate this invariant, but messing around with an object's internals uninvited is @@ -266,6 +267,7 @@ access to an uninitialized reference is an immediate error: julia> z.xx ERROR: UndefRefError: access to undefined reference + ... This avoids the need to continually check for ``null`` values. However, not all object fields are references. Julia considers some @@ -323,9 +325,11 @@ types of the arguments given to the constructor. Here are some examples: Point{Float64}(1.0,2.5) julia> Point(1,2.5) - ERROR: MethodError: `convert` has no method matching convert(::Type{Point{T<:Real}}, ::Int64, ::Float64) - This may have arisen from a call to the constructor Point{T<:Real}(...), - since type constructors fall back to convert methods. + ERROR: MethodError: no method matching Point{T<:Real}(::Int64, ::Float64) + Closest candidates are: + Point{T<:Real}{T<:Real}(::T<:Real, !Matched::T<:Real) + Point{T<:Real}{T}(::Any) + ... ## explicit T ## @@ -334,7 +338,8 @@ types of the arguments given to the constructor. Here are some examples: julia> Point{Int64}(1.0,2.5) ERROR: InexactError() - in call at none:2 + in Point{Int64}(::Float64, ::Float64) at ./none:2 + ... julia> Point{Float64}(1.0,2.5) Point{Float64}(1.0,2.5) @@ -419,9 +424,11 @@ However, other similar calls still don't work: .. doctest:: julia> Point(1.5,2) - ERROR: MethodError: `convert` has no method matching convert(::Type{Point{T<:Real}}, ::Float64, ::Int64) - This may have arisen from a call to the constructor Point{T<:Real}(...), - since type constructors fall back to convert methods. + ERROR: MethodError: no method matching Point{T<:Real}(::Float64, ::Int64) + Closest candidates are: + Point{T<:Real}{T<:Real}(::T<:Real, !Matched::T<:Real) + Point{T<:Real}{T}(::Any) + ... For a much more general way of making all such calls work sensibly, see :ref:`man-conversion-and-promotion`. At the risk diff --git a/doc/manual/control-flow.rst b/doc/manual/control-flow.rst index 98ff5413e13dd..eb430778eb2ed 100644 --- a/doc/manual/control-flow.rst +++ b/doc/manual/control-flow.rst @@ -126,7 +126,7 @@ This means that new variables defined inside the ``ìf`` clauses can be used after the ``if`` block, even if they weren't defined before. So, we could have defined the ``test`` function above as -.. doctest:: +.. doctest:: leaky julia> function test(x,y) if x < y @@ -145,7 +145,7 @@ outside. However, when depending on this behavior, make sure all possible code paths define a value for the variable. The following change to the above function results in a runtime error -.. doctest:: +.. doctest:: bad-leaky julia> function test(x,y) if x < y @@ -162,7 +162,8 @@ the above function results in a runtime error julia> test(2,1) ERROR: UndefVarError: relation not defined - in test at none:7 + in test(::Int64, ::Int64) at ./none:7 + ... ``if`` blocks also return a value, which may seem unintuitive to users coming from many other languages. This value is simply the return value @@ -193,6 +194,7 @@ conditional expression is anything but ``true`` or ``false``: println("true") end ERROR: TypeError: non-boolean (Int64) used in boolean context + ... This error indicates that the conditional was of the wrong type: :obj:`Int64` rather than the required :obj:`Bool`. @@ -234,7 +236,7 @@ evaluates to the string ``"not less than"``. The original three-way example requires chaining multiple uses of the ternary operator together: -.. doctest:: +.. doctest:: ternary-operator julia> test(x, y) = println(x < y ? "x is less than y" : x > y ? "x is greater than y" : "x is equal to y") @@ -365,7 +367,8 @@ For example, a recursive factorial routine could be defined like this: julia> fact(-1) ERROR: n must be non-negative - in fact at none:2 + in fact(::Int64) at ./none:2 + ... Boolean operations *without* short-circuit evaluation can be done with the @@ -394,6 +397,7 @@ except for the last entry in a conditional chain is an error: julia> 1 && true ERROR: TypeError: non-boolean (Int64) used in boolean context + ... On the other hand, any type of expression can be used at the end of a conditional chain. It will be evaluated and returned depending on the preceding conditionals: @@ -478,6 +482,7 @@ different variable name to test this: julia> j ERROR: UndefVarError: j not defined + ... See :ref:`man-variables-and-scoping` for a detailed explanation of variable scope and how it works in Julia. @@ -661,7 +666,8 @@ negative real value: julia> sqrt(-1) ERROR: DomainError: sqrt will only return a complex result if called with a complex argument. Try sqrt(complex(x)). - in sqrt at math.jl:146 + in sqrt(::Int64) at ./math.jl:149 + ... You may define your own exceptions in the following way: @@ -676,7 +682,7 @@ Exceptions can be created explicitly with :func:`throw`. For example, a function defined only for nonnegative numbers could be written to :func:`throw` a :exc:`DomainError` if the argument is negative: -.. doctest:: +.. doctest:: domain-error julia> f(x) = x>=0 ? exp(-x) : throw(DomainError()) f (generic function with 1 method) @@ -686,12 +692,13 @@ if the argument is negative: julia> f(-1) ERROR: DomainError: - in f at none:1 + in f(::Int64) at ./none:1 + ... Note that :exc:`DomainError` without parentheses is not an exception, but a type of exception. It needs to be called to obtain an :exc:`Exception` object: -.. doctest:: +.. doctest:: throw-function julia> typeof(DomainError()) <: Exception true @@ -706,6 +713,7 @@ error reporting: julia> throw(UndefVarError(:x)) ERROR: UndefVarError: x not defined + ... This mechanism can be implemented easily by custom exception types following the way :exc:`UndefVarError` is written: @@ -737,7 +745,8 @@ the :func:`sqrt` function that raises an error if its argument is negative: julia> fussy_sqrt(-1) ERROR: negative x not allowed - in fussy_sqrt at none:1 + in fussy_sqrt(::Int64) at ./none:1 + ... If ``fussy_sqrt`` is called with a negative value from another function, instead of trying to continue execution of the calling function, it @@ -762,7 +771,9 @@ session: julia> verbose_fussy_sqrt(-1) before fussy_sqrt ERROR: negative x not allowed - in verbose_fussy_sqrt at none:3 + in fussy_sqrt at ./none:1 [inlined] + in verbose_fussy_sqrt(::Int64) at ./none:3 + ... Warnings and informational messages ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -783,7 +794,8 @@ execution: julia> error("Hi"); 1+1 ERROR: Hi - in error at ./error.jl:21 + in error(::String) at ./error.jl:21 + ... The ``try/catch`` statement @@ -794,7 +806,7 @@ example, a customized square root function can be written to automatically call either the real or complex square root method on demand using :exc:`Exception`\ s : -.. doctest:: +.. doctest:: try-catch julia> f(x) = try sqrt(x) @@ -842,7 +854,8 @@ assumes ``x`` is a real number and returns its square root: julia> sqrt_second(-9) ERROR: DomainError: - in sqrt_second at none:7 + in sqrt_second(::Int64) at ./none:7 + ... Note that the symbol following ``catch`` will always be interpreted as a name for the exception, so care is needed when writing ``try/catch`` expressions diff --git a/doc/manual/conversion-and-promotion.rst b/doc/manual/conversion-and-promotion.rst index 1166c92866677..6c64950d0c3ee 100644 --- a/doc/manual/conversion-and-promotion.rst +++ b/doc/manual/conversion-and-promotion.rst @@ -100,11 +100,7 @@ requested conversion: ERROR: MethodError: Cannot `convert` an object of type String to an object of type AbstractFloat This may have arisen from a call to the constructor AbstractFloat(...), since type constructors fall back to convert methods. - Closest candidates are: - convert(::Type{AbstractFloat}, ::Bool) - convert(::Type{AbstractFloat}, ::Int8) - convert(::Type{AbstractFloat}, ::Int16) - ... + ... Some languages consider parsing strings as numbers or formatting numbers as strings to be conversions (many dynamic languages will even @@ -146,7 +142,8 @@ to one and zero: julia> convert(Bool, 1im) ERROR: InexactError() - in convert at complex.jl:18 + in convert(::Type{Bool}, ::Complex{Int64}) at ./complex.jl:18 + ... julia> convert(Bool, 0im) false @@ -161,7 +158,8 @@ This is the actual implementation in Julia:: julia> convert(Bool, 1im) ERROR: InexactError() - in convert at complex.jl:18 + in convert(::Type{Bool}, ::Complex{Int64}) at ./complex.jl:18 + ... Case Study: Rational Conversions diff --git a/doc/manual/documentation.rst b/doc/manual/documentation.rst index 305137d358431..7b6d8945e097c 100644 --- a/doc/manual/documentation.rst +++ b/doc/manual/documentation.rst @@ -30,7 +30,7 @@ macros and pass them to the ``@doc`` macro just as well. Here is a more complex example, still using Markdown: -.. doctest:: +.. code-block:: julia """ bar(x[, y]) diff --git a/doc/manual/functions.rst b/doc/manual/functions.rst index 7bd58491e71e3..ea6eff24eabf9 100644 --- a/doc/manual/functions.rst +++ b/doc/manual/functions.rst @@ -204,12 +204,12 @@ without being given a name, using either of these syntaxes: .. doctest:: julia> x -> x^2 + 2x - 1 - #1 (generic function with 1 method) + (::#1) (generic function with 1 method) julia> function (x) x^2 + 2x - 1 end - #2 (generic function with 1 method) + (::#3) (generic function with 1 method) This creates a function taking one argument *x* and returning the value of the polynomial *x*\ ^2 + 2\ *x* - 1 at that value. diff --git a/doc/manual/integers-and-floating-point-numbers.rst b/doc/manual/integers-and-floating-point-numbers.rst index c5e60a71e738c..9b37bff26eb08 100644 --- a/doc/manual/integers-and-floating-point-numbers.rst +++ b/doc/manual/integers-and-floating-point-numbers.rst @@ -421,7 +421,6 @@ types: julia> (typemin(Float64),typemax(Float64)) (-Inf,Inf) - Machine epsilon ~~~~~~~~~~~~~~~ @@ -698,9 +697,11 @@ imply multiplication: julia> (x-1)(x+1) ERROR: MethodError: objects of type Int64 are not callable + ... julia> x(x+1) ERROR: MethodError: objects of type Int64 are not callable + ... Both expressions are interpreted as function application: any expression that is not a numeric literal, when immediately followed by a diff --git a/doc/manual/mathematical-operations.rst b/doc/manual/mathematical-operations.rst index d6f27627df9bb..c08c8b115003d 100644 --- a/doc/manual/mathematical-operations.rst +++ b/doc/manual/mathematical-operations.rst @@ -400,21 +400,21 @@ The following examples show the different forms. julia> Int8(128) ERROR: InexactError() - in call at ./essentials.jl:58 - in eval at ./boot.jl:263 + in Int8(::Int64) at ./sysimg.jl:53 + ... julia> Int8(127.0) 127 julia> Int8(3.14) ERROR: InexactError() - in call at ./essentials.jl:58 - in eval at ./boot.jl:263 + in Int8(::Float64) at ./sysimg.jl:53 + ... julia> Int8(128.0) ERROR: InexactError() - in call at ./essentials.jl:58 - in eval at ./boot.jl:263 + in Int8(::Float64) at ./sysimg.jl:53 + ... julia> 127 % Int8 127 @@ -427,9 +427,9 @@ The following examples show the different forms. julia> round(Int8,127.6) ERROR: InexactError() - in trunc at ./float.jl:357 - in round at ./float.jl:177 - in eval at ./boot.jl:263 + in trunc(::Type{Int8}, ::Float64) at ./float.jl:425 + in round(::Type{Int8}, ::Float64) at ./float.jl:180 + ... See :ref:`man-conversion-and-promotion` for how to define your own conversions and promotions. diff --git a/doc/manual/metaprogramming.rst b/doc/manual/metaprogramming.rst index bc32d8c0a9019..a2fca9211a7e2 100644 --- a/doc/manual/metaprogramming.rst +++ b/doc/manual/metaprogramming.rst @@ -257,6 +257,7 @@ cause a compile-time error: julia> $a + b ERROR: unsupported or misplaced expression $ + ... In this example, the tuple ``(1,2,3)`` is interpolated as an expression into a conditional test: @@ -264,7 +265,7 @@ expression into a conditional test: .. doctest:: julia> ex = :(a in $:((1,2,3)) ) - :($(Expr(:in, :a, :((1,2,3))))) + :(a in (1,2,3)) Interpolating symbols into a nested expression requires enclosing each symbol in an enclosing quote block:: @@ -297,6 +298,7 @@ at global scope using :func:`eval`: julia> eval(ex) ERROR: UndefVarError: b not defined + ... julia> a = 1; b = 2; @@ -316,6 +318,7 @@ module's environment: julia> x ERROR: UndefVarError: x not defined + ... julia> eval(ex) 1 @@ -415,11 +418,16 @@ Basics Here is an extraordinarily simple macro: -.. doctest:: +.. testcode:: - julia> macro sayhello() - return :( println("Hello, world!") ) - end + macro sayhello() + return :( println("Hello, world!") ) + end + +.. testoutput:: + :hide: + + @sayhello (macro with 1 method) Macros have a dedicated character in Julia's syntax: the ``@`` (at-sign), followed by the unique name declared in a ``macro NAME ... end`` block. @@ -545,6 +553,7 @@ This macro can be used like this: julia> @assert 1==0 ERROR: AssertionError: 1 == 0 + ... In place of the written syntax, the macro call is expanded at parse time to its returned result. This is equivalent to writing:: @@ -589,14 +598,14 @@ function: :(if a == b nothing else - Base.throw(Base.Main.Base.AssertionError("a == b")) + (Base.throw)(Base.Main.Base.AssertionError("a == b")) end) julia> macroexpand(:(@assert a==b "a should equal b!")) :(if a == b nothing else - Base.throw(Base.Main.Base.AssertionError("a should equal b!")) + (Base.throw)(Base.Main.Base.AssertionError("a should equal b!")) end) There is yet another case that the actual :obj:`@assert` macro handles: what @@ -620,11 +629,14 @@ Compare: Expr head: Symbol string args: Array{Any}((5,)) - 1: String "a (" + 1: String + data: Array{UInt8}((3,)) UInt8[0x61,0x20,0x28] 2: Symbol a - 3: String ") should equal b (" + 3: String + data: Array{UInt8}((18,)) UInt8[0x29,0x20,0x73,0x68,0x6f,0x75,0x6c,0x64,0x20,0x65,0x71,0x75,0x61,0x6c,0x20,0x62,0x20,0x28] 4: Symbol b - 5: String ")!" + 5: String + data: Array{UInt8}((2,)) UInt8[0x29,0x21] typ: Any So now instead of getting a plain string in ``msg_body``, the macro is diff --git a/doc/manual/methods.rst b/doc/manual/methods.rst index 2a21398f824e3..55a2870fdb008 100644 --- a/doc/manual/methods.rst +++ b/doc/manual/methods.rst @@ -93,22 +93,26 @@ Applying it to any other types of arguments will result in a :exc:`MethodError`: .. doctest:: julia> f(2.0, 3) - ERROR: MethodError: `f` has no method matching f(::Float64, ::Int64) + ERROR: MethodError: no method matching f(::Float64, ::Int64) Closest candidates are: f(::Float64, !Matched::Float64) + ... julia> f(Float32(2.0), 3.0) - ERROR: MethodError: `f` has no method matching f(::Float32, ::Float64) + ERROR: MethodError: no method matching f(::Float32, ::Float64) Closest candidates are: f(!Matched::Float64, ::Float64) + ... julia> f(2.0, "3.0") - ERROR: MethodError: `f` has no method matching f(::Float64, ::String) + ERROR: MethodError: no method matching f(::Float64, ::String) Closest candidates are: f(::Float64, !Matched::Float64) + ... julia> f("2.0", "3.0") - ERROR: MethodError: `f` has no method matching f(::String, ::String) + ERROR: MethodError: no method matching f(::String, ::String) + ... As you can see, the arguments must be precisely of type :obj:`Float64`. Other numeric types, such as integers or 32-bit floating-point values, @@ -173,12 +177,17 @@ function ``f`` remains undefined, and applying it will still result in a .. doctest:: julia> f("foo", 3) - ERROR: MethodError: `f` has no method matching f(::String, ::Int64) + ERROR: MethodError: no method matching f(::String, ::Int64) Closest candidates are: f(!Matched::Number, ::Number) + ... julia> f() - ERROR: MethodError: `f` has no method matching f() + ERROR: MethodError: no method matching f() + Closest candidates are: + f(!Matched::Float64, !Matched::Float64) + f(!Matched::Number, !Matched::Number) + ... You can easily see which methods exist for a function by entering the function object itself in an interactive session: @@ -226,148 +235,29 @@ values is perhaps the single most powerful and central feature of the Julia language. Core operations typically have dozens of methods: .. doctest:: + :options: +SKIP julia> methods(+) - # 139 methods for generic function "+": - +(x::Bool) at bool.jl:33 - +(x::Bool,y::Bool) at bool.jl:36 - +(y::AbstractFloat,x::Bool) at bool.jl:46 - +(x::Int64,y::Int64) at int.jl:14 - +(x::Int8,y::Int8) at int.jl:14 - +(x::UInt8,y::UInt8) at int.jl:14 - +(x::Int16,y::Int16) at int.jl:14 - +(x::UInt16,y::UInt16) at int.jl:14 - +(x::Int32,y::Int32) at int.jl:14 - +(x::UInt32,y::UInt32) at int.jl:14 - +(x::UInt64,y::UInt64) at int.jl:14 - +(x::Int128,y::Int128) at int.jl:14 - +(x::UInt128,y::UInt128) at int.jl:14 - +(x::Float32,y::Float32) at float.jl:192 - +(x::Float64,y::Float64) at float.jl:193 - +(z::Complex{T<:Real},w::Complex{T<:Real}) at complex.jl:96 - +(x::Real,z::Complex{T<:Real}) at complex.jl:106 - +(z::Complex{T<:Real},x::Real) at complex.jl:107 - +(x::Rational{T<:Integer},y::Rational{T<:Integer}) at rational.jl:167 - +(a::Float16,b::Float16) at float16.jl:136 - +(x::Base.GMP.BigInt,y::Base.GMP.BigInt) at gmp.jl:243 - +(a::Base.GMP.BigInt,b::Base.GMP.BigInt,c::Base.GMP.BigInt) at gmp.jl:266 - +(a::Base.GMP.BigInt,b::Base.GMP.BigInt,c::Base.GMP.BigInt,d::Base.GMP.BigInt) at gmp.jl:272 - +(a::Base.GMP.BigInt,b::Base.GMP.BigInt,c::Base.GMP.BigInt,d::Base.GMP.BigInt,e::Base.GMP.BigInt) at gmp.jl:279 - +(x::Base.GMP.BigInt,c::Union{UInt32,UInt16,UInt8,UInt64}) at gmp.jl:291 - +(c::Union{UInt32,UInt16,UInt8,UInt64},x::Base.GMP.BigInt) at gmp.jl:295 - +(x::Base.GMP.BigInt,c::Union{Int16,Int32,Int8,Int64}) at gmp.jl:307 - +(c::Union{Int16,Int32,Int8,Int64},x::Base.GMP.BigInt) at gmp.jl:308 - +(x::Base.MPFR.BigFloat,y::Base.MPFR.BigFloat) at mpfr.jl:206 - +(x::Base.MPFR.BigFloat,c::Union{UInt32,UInt16,UInt8,UInt64}) at mpfr.jl:213 - +(c::Union{UInt32,UInt16,UInt8,UInt64},x::Base.MPFR.BigFloat) at mpfr.jl:217 - +(x::Base.MPFR.BigFloat,c::Union{Int16,Int32,Int8,Int64}) at mpfr.jl:221 - +(c::Union{Int16,Int32,Int8,Int64},x::Base.MPFR.BigFloat) at mpfr.jl:225 - +(x::Base.MPFR.BigFloat,c::Union{Float16,Float64,Float32}) at mpfr.jl:229 - +(c::Union{Float16,Float64,Float32},x::Base.MPFR.BigFloat) at mpfr.jl:233 - +(x::Base.MPFR.BigFloat,c::Base.GMP.BigInt) at mpfr.jl:237 - +(c::Base.GMP.BigInt,x::Base.MPFR.BigFloat) at mpfr.jl:241 - +(a::Base.MPFR.BigFloat,b::Base.MPFR.BigFloat,c::Base.MPFR.BigFloat) at mpfr.jl:318 - +(a::Base.MPFR.BigFloat,b::Base.MPFR.BigFloat,c::Base.MPFR.BigFloat,d::Base.MPFR.BigFloat) at mpfr.jl:324 - +(a::Base.MPFR.BigFloat,b::Base.MPFR.BigFloat,c::Base.MPFR.BigFloat,d::Base.MPFR.BigFloat,e::Base.MPFR.BigFloat) at mpfr.jl:331 - +(x::Irrational{sym},y::Irrational{sym}) at constants.jl:71 - +{T<:Number}(x::T<:Number,y::T<:Number) at promotion.jl:205 - +{T<:AbstractFloat}(x::Bool,y::T<:AbstractFloat) at bool.jl:43 - +(x::Number,y::Number) at promotion.jl:167 - +(x::Integer,y::Ptr{T}) at pointer.jl:70 - +(x::Bool,A::AbstractArray{Bool,N}) at array.jl:829 - +(x::Integer,y::Char) at char.jl:41 - +(x::Number) at operators.jl:72 - +(r1::OrdinalRange{T,S},r2::OrdinalRange{T,S}) at operators.jl:325 - +{T<:AbstractFloat}(r1::FloatRange{T<:AbstractFloat},r2::FloatRange{T<:AbstractFloat}) at operators.jl:331 - +(r1::FloatRange{T<:AbstractFloat},r2::FloatRange{T<:AbstractFloat}) at operators.jl:348 - +(r1::FloatRange{T<:AbstractFloat},r2::OrdinalRange{T,S}) at operators.jl:349 - +(r1::OrdinalRange{T,S},r2::FloatRange{T<:AbstractFloat}) at operators.jl:350 - +(x::Ptr{T},y::Integer) at pointer.jl:68 - +{S,T}(A::Range{S},B::Range{T}) at array.jl:773 - +{S,T}(A::Range{S},B::AbstractArray{T,N}) at array.jl:791 - +(A::AbstractArray{Bool,N},x::Bool) at array.jl:828 - +(A::BitArray{N},B::BitArray{N}) at bitarray.jl:926 - +(A::Union{DenseArray{Bool,N},SubArray{Bool,N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Range{Int64},Int64}}},LD}},B::Union{DenseArray{Bool,N},SubArray{Bool,N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Range{Int64},Int64}}},LD}}) at array.jl:859 - +(A::Base.LinAlg.SymTridiagonal{T},B::Base.LinAlg.SymTridiagonal{T}) at linalg/tridiag.jl:59 - +(A::Base.LinAlg.Tridiagonal{T},B::Base.LinAlg.Tridiagonal{T}) at linalg/tridiag.jl:254 - +(A::Base.LinAlg.Tridiagonal{T},B::Base.LinAlg.SymTridiagonal{T}) at linalg/special.jl:113 - +(A::Base.LinAlg.SymTridiagonal{T},B::Base.LinAlg.Tridiagonal{T}) at linalg/special.jl:112 - +(A::Base.LinAlg.UpperTriangular{T,S<:AbstractArray{T,2}},B::Base.LinAlg.UpperTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:164 - +(A::Base.LinAlg.LowerTriangular{T,S<:AbstractArray{T,2}},B::Base.LinAlg.LowerTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:165 - +(A::Base.LinAlg.UpperTriangular{T,S<:AbstractArray{T,2}},B::Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:166 - +(A::Base.LinAlg.LowerTriangular{T,S<:AbstractArray{T,2}},B::Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:167 - +(A::Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}},B::Base.LinAlg.UpperTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:168 - +(A::Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}},B::Base.LinAlg.LowerTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:169 - +(A::Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}},B::Base.LinAlg.UnitUpperTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:170 - +(A::Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}},B::Base.LinAlg.UnitLowerTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:171 - +(A::Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}},B::Base.LinAlg.AbstractTriangular{T,S<:AbstractArray{T,2}}) at linalg/triangular.jl:172 - +(Da::Base.LinAlg.Diagonal{T},Db::Base.LinAlg.Diagonal{T}) at linalg/diagonal.jl:50 - +(A::Base.LinAlg.Bidiagonal{T},B::Base.LinAlg.Bidiagonal{T}) at linalg/bidiag.jl:111 - +{T}(B::BitArray{2},J::Base.LinAlg.UniformScaling{T}) at linalg/uniformscaling.jl:28 - +(A::Base.LinAlg.Diagonal{T},B::Base.LinAlg.Bidiagonal{T}) at linalg/special.jl:103 - +(A::Base.LinAlg.Bidiagonal{T},B::Base.LinAlg.Diagonal{T}) at linalg/special.jl:104 - +(A::Base.LinAlg.Diagonal{T},B::Base.LinAlg.Tridiagonal{T}) at linalg/special.jl:103 - +(A::Base.LinAlg.Tridiagonal{T},B::Base.LinAlg.Diagonal{T}) at linalg/special.jl:104 - +(A::Base.LinAlg.Diagonal{T},B::Array{T,2}) at linalg/special.jl:103 - +(A::Array{T,2},B::Base.LinAlg.Diagonal{T}) at linalg/special.jl:104 - +(A::Base.LinAlg.Bidiagonal{T},B::Base.LinAlg.Tridiagonal{T}) at linalg/special.jl:103 - +(A::Base.LinAlg.Tridiagonal{T},B::Base.LinAlg.Bidiagonal{T}) at linalg/special.jl:104 - +(A::Base.LinAlg.Bidiagonal{T},B::Array{T,2}) at linalg/special.jl:103 - +(A::Array{T,2},B::Base.LinAlg.Bidiagonal{T}) at linalg/special.jl:104 - +(A::Base.LinAlg.Tridiagonal{T},B::Array{T,2}) at linalg/special.jl:103 - +(A::Array{T,2},B::Base.LinAlg.Tridiagonal{T}) at linalg/special.jl:104 - +(A::Base.LinAlg.SymTridiagonal{T},B::Array{T,2}) at linalg/special.jl:112 - +(A::Array{T,2},B::Base.LinAlg.SymTridiagonal{T}) at linalg/special.jl:113 - +(A::Base.LinAlg.Diagonal{T},B::Base.LinAlg.SymTridiagonal{T}) at linalg/special.jl:121 - +(A::Base.LinAlg.SymTridiagonal{T},B::Base.LinAlg.Diagonal{T}) at linalg/special.jl:122 - +(A::Base.LinAlg.Bidiagonal{T},B::Base.LinAlg.SymTridiagonal{T}) at linalg/special.jl:121 - +(A::Base.LinAlg.SymTridiagonal{T},B::Base.LinAlg.Bidiagonal{T}) at linalg/special.jl:122 - +{Tv1,Ti1,Tv2,Ti2}(A_1::Base.SparseArrays.SparseMatrixCSC{Tv1,Ti1},A_2::Base.SparseMatrix.SparseMatrixCSC{Tv2,Ti2}) at sparse/sparsematrix.jl:873 - +(A::Base.SparseArrays.SparseMatrixCSC{Tv,Ti<:Integer},B::Array{T,N}) at sparse/sparsematrix.jl:885 - +(A::Array{T,N},B::Base.SparseArrays.SparseMatrixCSC{Tv,Ti<:Integer}) at sparse/sparsematrix.jl:887 - +{P<:Base.Dates.Period}(Y::Union{SubArray{P<:Base.Dates.Period,N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Range{Int64},Int64}}},LD},DenseArray{P<:Base.Dates.Period,N}},x::P<:Base.Dates.Period) at dates/periods.jl:50 - +{T<:Base.Dates.TimeType}(r::Range{T<:Base.Dates.TimeType},x::Base.Dates.Period) at dates/ranges.jl:39 - +{T<:Number}(x::AbstractArray{T<:Number,N}) at abstractarray.jl:442 - +{S,T}(A::AbstractArray{S,N},B::Range{T}) at array.jl:782 - +{S,T}(A::AbstractArray{S,N},B::AbstractArray{T,N}) at array.jl:800 - +(A::AbstractArray{T,N},x::Number) at array.jl:832 - +(x::Number,A::AbstractArray{T,N}) at array.jl:833 - +(x::Char,y::Integer) at char.jl:40 - +{N}(index1::Base.IteratorsMD.CartesianIndex{N},index2::Base.IteratorsMD.CartesianIndex{N}) at multidimensional.jl:121 - +(J1::Base.LinAlg.UniformScaling{T<:Number},J2::Base.LinAlg.UniformScaling{T<:Number}) at linalg/uniformscaling.jl:27 - +(J::Base.LinAlg.UniformScaling{T<:Number},B::BitArray{2}) at linalg/uniformscaling.jl:29 - +(J::Base.LinAlg.UniformScaling{T<:Number},A::AbstractArray{T,2}) at linalg/uniformscaling.jl:30 - +(J::Base.LinAlg.UniformScaling{T<:Number},x::Number) at linalg/uniformscaling.jl:31 - +(x::Number,J::Base.LinAlg.UniformScaling{T<:Number}) at linalg/uniformscaling.jl:32 - +{TA,TJ}(A::AbstractArray{TA,2},J::Base.LinAlg.UniformScaling{TJ}) at linalg/uniformscaling.jl:35 - +{T}(a::Base.Pkg.Resolve.VersionWeights.HierarchicalValue{T},b::Base.Pkg.Resolve.VersionWeights.HierarchicalValue{T}) at pkg/resolve/versionweight.jl:21 - +(a::Base.Pkg.Resolve.VersionWeights.VWPreBuildItem,b::Base.Pkg.Resolve.VersionWeights.VWPreBuildItem) at pkg/resolve/versionweight.jl:83 - +(a::Base.Pkg.Resolve.VersionWeights.VWPreBuild,b::Base.Pkg.Resolve.VersionWeights.VWPreBuild) at pkg/resolve/versionweight.jl:129 - +(a::Base.Pkg.Resolve.VersionWeights.VersionWeight,b::Base.Pkg.Resolve.VersionWeights.VersionWeight) at pkg/resolve/versionweight.jl:183 - +(a::Base.Pkg.Resolve.MaxSum.FieldValues.FieldValue,b::Base.Pkg.Resolve.MaxSum.FieldValues.FieldValue) at pkg/resolve/fieldvalue.jl:43 - +{P<:Base.Dates.Period}(x::P<:Base.Dates.Period,y::P<:Base.Dates.Period) at dates/periods.jl:43 - +{P<:Base.Dates.Period}(x::P<:Base.Dates.Period,Y::Union{SubArray{P<:Base.Dates.Period,N,A<:DenseArray{T,N},I<:Tuple{Vararg{Union{Colon,Range{Int64},Int64}}},LD},DenseArray{P<:Base.Dates.Period,N}}) at dates/periods.jl:49 - +(x::Base.Dates.Period,y::Base.Dates.Period) at dates/periods.jl:196 - +(x::Base.Dates.CompoundPeriod,y::Base.Dates.Period) at dates/periods.jl:197 - +(y::Base.Dates.Period,x::Base.Dates.CompoundPeriod) at dates/periods.jl:198 - +(x::Base.Dates.CompoundPeriod,y::Base.Dates.CompoundPeriod) at dates/periods.jl:199 - +(dt::Base.Dates.DateTime,y::Base.Dates.Year) at dates/arithmetic.jl:13 - +(dt::Base.Dates.Date,y::Base.Dates.Year) at dates/arithmetic.jl:17 - +(dt::Base.Dates.DateTime,z::Base.Dates.Month) at dates/arithmetic.jl:37 - +(dt::Base.Dates.Date,z::Base.Dates.Month) at dates/arithmetic.jl:43 - +(x::Base.Dates.Date,y::Base.Dates.Week) at dates/arithmetic.jl:60 - +(x::Base.Dates.Date,y::Base.Dates.Day) at dates/arithmetic.jl:62 - +(x::Base.Dates.DateTime,y::Base.Dates.Period) at dates/arithmetic.jl:64 - +(a::Base.Dates.TimeType,b::Base.Dates.Period,c::Base.Dates.Period) at dates/periods.jl:210 - +(a::Base.Dates.TimeType,b::Base.Dates.Period,c::Base.Dates.Period,d::Base.Dates.Period...) at dates/periods.jl:212 - +(x::Base.Dates.TimeType,y::Base.Dates.CompoundPeriod) at dates/periods.jl:216 - +(x::Base.Dates.CompoundPeriod,y::Base.Dates.TimeType) at dates/periods.jl:221 - +(x::Base.Dates.Instant) at dates/arithmetic.jl:4 - +(x::Base.Dates.TimeType) at dates/arithmetic.jl:8 - +(y::Base.Dates.Period,x::Base.Dates.TimeType) at dates/arithmetic.jl:66 - +{T<:Base.Dates.TimeType}(x::Base.Dates.Period,r::Range{T<:Base.Dates.TimeType}) at dates/ranges.jl:40 - +(a,b,c) at operators.jl:83 - +(a,b,c,xs...) at operators.jl:84 + # 166 methods for generic function "+": + +(a::Float16, b::Float16) at float16.jl:136 + +(x::Float32, y::Float32) at float.jl:206 + +(x::Float64, y::Float64) at float.jl:207 + +(x::Bool, z::Complex{Bool}) at complex.jl:126 + +(x::Bool, y::Bool) at bool.jl:48 + +(x::Bool) at bool.jl:45 + +{T<:AbstractFloat}(x::Bool, y::T) at bool.jl:55 + +(x::Bool, z::Complex) at complex.jl:133 + +(x::Bool, A::AbstractArray{Bool,N<:Any}) at arraymath.jl:105 + +(x::Char, y::Integer) at char.jl:40 + +{T<:Union{Int128,Int16,Int32,Int64,Int8,UInt128,UInt16,UInt32,UInt64,UInt8}}(x::T, y::T) at int.jl:32 + +(z::Complex, w::Complex) at complex.jl:115 + +(z::Complex, x::Bool) at complex.jl:134 + +(x::Real, z::Complex{Bool}) at complex.jl:140 + +(x::Real, z::Complex) at complex.jl:152 + +(z::Complex, x::Real) at complex.jl:153 + +(x::Rational, y::Rational) at rational.jl:179 + ... + +(a, b, c, xs...) at operators.jl:119 Multiple dispatch together with the flexible parametric type system give Julia its ability to abstractly express high-level algorithms decoupled @@ -386,13 +276,6 @@ arguments: julia> g(x::Float64, y) = 2x + y; julia> g(x, y::Float64) = x + 2y; - WARNING: New definition - g(Any, Float64) at none:1 - is ambiguous with: - g(Float64, Any) at none:1. - To fix, define - g(Float64, Float64) - before the new definition. julia> g(2.0, 3) 7.0 @@ -401,16 +284,18 @@ arguments: 8.0 julia> g(2.0, 3.0) - 7.0 + ERROR: MethodError: g(::Float64, ::Float64) is ambiguous. Candidates: + g(x, y::Float64) at none:1 + g(x::Float64, y) at none:1 + ... Here the call ``g(2.0, 3.0)`` could be handled by either the ``g(Float64, Any)`` or the ``g(Any, Float64)`` method, and neither is -more specific than the other. In such cases, Julia warns you about this -ambiguity, but allows you to proceed, arbitrarily picking a method. You -should avoid method ambiguities by specifying an appropriate method for -the intersection case: +more specific than the other. In such cases, Julia raises a ``MethodError`` +rather than arbitrarily picking a method. You can avoid method ambiguities +by specifying an appropriate method for the intersection case: -.. doctest:: +.. doctest:: unambiguous julia> g(x::Float64, y::Float64) = 2x + 2y; @@ -427,9 +312,9 @@ the intersection case: julia> g(2.0, 3.0) 10.0 -To suppress Julia's warning, the disambiguating method must be defined -first, since otherwise the ambiguity exists, if transiently, until the -more specific method is defined. +It is recommended that the disambiguating method be defined first, +since otherwise the ambiguity exists, if transiently, until the more +specific method is defined. .. _man-parametric-methods: @@ -492,9 +377,10 @@ signature: 4 julia> myappend([1,2,3],2.5) - ERROR: MethodError: `myappend` has no method matching myappend(::Array{Int64,1}, ::Float64) + ERROR: MethodError: no method matching myappend(::Array{Int64,1}, ::Float64) Closest candidates are: myappend{T}(::Array{T,1}, !Matched::T) + ... julia> myappend([1.0,2.0,3.0],4.0) 4-element Array{Float64,1}: @@ -504,9 +390,10 @@ signature: 4.0 julia> myappend([1.0,2.0,3.0],4) - ERROR: MethodError: `myappend` has no method matching myappend(::Array{Float64,1}, ::Int64) + ERROR: MethodError: no method matching myappend(::Array{Float64,1}, ::Int64) Closest candidates are: myappend{T}(::Array{T,1}, !Matched::T) + ... As you can see, the type of the appended element must match the element type of the vector it is appended to, or else a :exc:`MethodError` is raised. @@ -561,16 +448,18 @@ Function parameters can also be used to constrain the number of arguments that m .. doctest:: - julia> bar(a,b,x::Vararg{Any,2}) = (a,b,x) + julia> bar(a,b,x::Vararg{Any,2}) = (a,b,x); julia> bar(1,2,3) - ERROR: MethodError: `bar` has no matching method bar(::Int, ::Int, ::Int) + ERROR: MethodError: no method matching bar(::Int64, ::Int64, ::Int64) + ... julia> bar(1,2,3,4) (1,2,(3,4)) julia> bar(1,2,3,4,5) - ERROR: MethodError: `bar` has no method matching bar(::Int, ::Int, ::Int, ::Int, ::Int) + ERROR: MethodError: no method matching bar(::Int64, ::Int64, ::Int64, ::Int64, ::Int64) + ... More usefully, it is possible to constrain varargs methods by a parameter. For example:: diff --git a/doc/manual/performance-tips.rst b/doc/manual/performance-tips.rst index c44dd59a47a30..2c88ae20a0703 100644 --- a/doc/manual/performance-tips.rst +++ b/doc/manual/performance-tips.rst @@ -279,7 +279,7 @@ change: .. doctest:: julia> m.a = 4.5f0 - 4.5 + 4.5f0 julia> typeof(m.a) Float64 diff --git a/doc/manual/stacktraces.rst b/doc/manual/stacktraces.rst index 570737a43fec0..3886cb0f8b0da 100644 --- a/doc/manual/stacktraces.rst +++ b/doc/manual/stacktraces.rst @@ -30,10 +30,13 @@ alias :obj:`StackTrace` can be used in place of ``Vector{StackFrame}``. (Example example (generic function with 1 method) julia> example() - ...-element Array{StackFrame,1}: - example at none:1 - eval at boot.jl:265 - ... + 6-element Array{StackFrame,1}: + in example() at none:1 + in eval(::Module, ::Any) at boot.jl:234 + in eval_user_input(::Any, ::Bool) at client.jl:117 + in eval(::Module, ::Any) at boot.jl:234 + in eval_user_input(::Any, ::Bool) at client.jl:117 + in _start() at client.jl:359 julia> @noinline child() = stacktrace() child (generic function with 1 method) @@ -45,39 +48,36 @@ alias :obj:`StackTrace` can be used in place of ``Vector{StackFrame}``. (Example grandparent (generic function with 1 method) julia> grandparent() - ...-element Array{StackFrame,1}: - child at none:1 - parent at none:1 - grandparent at none:1 - eval at boot.jl:265 - ... + 8-element Array{StackFrame,1}: + in child() at none:1 + in parent() at none:1 + in grandparent() at none:1 + ... Note that when calling :func:`stacktrace` you'll typically see a frame with -``eval at boot.jl``. When calling :func:`stacktrace` from the REPL you'll also have a few +``eval(...) at boot.jl``. When calling :func:`stacktrace` from the REPL you'll also have a few extra frames in the stack from ``REPL.jl``, usually looking something like this:: julia> example() = stacktrace() example (generic function with 1 method) julia> example() - 4-element Array{StackFrame,1}: - example at none:1 - eval at boot.jl:265 - [inlined code from REPL.jl:3] eval_user_input at REPL.jl:62 - [inlined code from REPL.jl:92] anonymous at task.jl:63 + 5-element Array{StackFrame,1}: + in example() at REPL[1]:1 + in eval(::Module, ::Any) at boot.jl:234 + in eval_user_input(::Any, ::Base.REPL.REPLBackend) at REPL.jl:62 + in macro expansion at REPL.jl:92 [inlined] + in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at event.jl:46 Extracting useful information ----------------------------- -Each :obj:`StackFrame` contains the function name, file name, line number, file and line -information for inlined functions, a flag indicating whether it is a C function (by default -C functions do not appear in the stack trace), and an integer representation of the pointer -returned by :func:`backtrace`: +Each :obj:`StackFrame` contains the function name, file name, line number, lambda info, a flag indicating whether the frame has been inlined, a flag indicating whether it is a C function (by default C functions do not appear in the stack trace), and an integer representation of the pointer returned by :func:`backtrace`: .. doctest:: julia> top_frame = stacktrace()[1] - eval at boot.jl:265 + in eval(::Module, ::Any) at boot.jl:234 julia> top_frame.func :eval @@ -86,13 +86,14 @@ returned by :func:`backtrace`: Symbol("./boot.jl") julia> top_frame.line - 265 + 234 - julia> top_frame.inlined_file - Symbol("") + julia> top_frame.linfo + Nullable{LambdaInfo}(LambdaInfo for eval(::Module, ::Any) + ... - julia> top_frame.inlined_line - -1 + julia> top_frame.inlined + false julia> top_frame.from_c false @@ -111,7 +112,7 @@ Error handling While having easy access to information about the current state of the callstack can be helpful in many places, the most obvious application is in error handling and debugging. -.. doctest:: +.. doctest:: error-handling julia> @noinline bad_function() = undeclared_variable bad_function (generic function with 1 method) @@ -124,10 +125,10 @@ helpful in many places, the most obvious application is in error handling and de example (generic function with 1 method) julia> example() - ...-element Array{StackFrame,1}: - example at none:4 - eval at boot.jl:265 - ... + 6-element Array{StackFrame,1}: + in example() at none:4 + in eval(::Module, ::Any) at boot.jl:234 + ... You may notice that in the example above the first stack frame points points at line 4, where :func:`stacktrace` is called, rather than line 2, where `bad_function` is called, and @@ -140,7 +141,7 @@ This can be remedied by calling :func:`catch_stacktrace` instead of :func:`stack Instead of returning callstack information for the current context, :func:`catch_stacktrace` returns stack information for the context of the most recent exception: -.. doctest:: +.. doctest:: catch-stacktrace julia> @noinline bad_function() = undeclared_variable bad_function (generic function with 1 method) @@ -153,15 +154,14 @@ returns stack information for the context of the most recent exception: example (generic function with 1 method) julia> example() - ...-element Array{StackFrame,1}: - bad_function at none:1 - example at none:2 - eval at boot.jl:265 - ... + 7-element Array{StackFrame,1}: + in bad_function() at none:1 + in example() at none:2 + ... Notice that the stack trace now indicates the appropriate line number and the missing frame. -.. doctest:: +.. doctest:: catch-stacktrace-demo julia> @noinline child() = error("Whoops!") child (generic function with 1 method) @@ -181,12 +181,11 @@ Notice that the stack trace now indicates the appropriate line number and the mi julia> grandparent() ERROR: Whoops! - ...-element Array{StackFrame,1}: - child at none:1 - parent at none:1 - grandparent at none:3 - eval at boot.jl:265 - ... + 8-element Array{StackFrame,1}: + in child() at none:1 + in parent() at none:1 + in grandparent() at none:3 + ... Comparison with :func:`backtrace` --------------------------------- @@ -195,60 +194,77 @@ A call to :func:`backtrace` returns a vector of ``Ptr{Void}``, which may then be :func:`stacktrace` for translation:: julia> trace = backtrace() - 15-element Array{Ptr{Void},1}: - Ptr{Void} @0x000000010527895e - Ptr{Void} @0x0000000309bf6220 - Ptr{Void} @0x0000000309bf61a0 - Ptr{Void} @0x00000001052733b4 - Ptr{Void} @0x0000000105271a0e - Ptr{Void} @0x000000010527189d - Ptr{Void} @0x0000000105272e6d - Ptr{Void} @0x0000000105272cef - Ptr{Void} @0x0000000105285b88 - Ptr{Void} @0x000000010526b50e - Ptr{Void} @0x000000010663cc28 - Ptr{Void} @0x0000000309bbc20f - Ptr{Void} @0x0000000309bbbde7 - Ptr{Void} @0x0000000309bb0262 - Ptr{Void} @0x000000010527980e + 20-element Array{Ptr{Void},1}: + Ptr{Void} @0x0000000100a26fc2 + Ptr{Void} @0x00000001029435df + Ptr{Void} @0x0000000102943635 + Ptr{Void} @0x00000001009e9620 + Ptr{Void} @0x00000001009fe1e8 + Ptr{Void} @0x00000001009fc7b6 + Ptr{Void} @0x00000001009fdae3 + Ptr{Void} @0x00000001009fe0d2 + Ptr{Void} @0x0000000100a1321b + Ptr{Void} @0x00000001009f64e7 + Ptr{Void} @0x000000010265ac5d + Ptr{Void} @0x000000010265acc1 + Ptr{Void} @0x00000001009e9620 + Ptr{Void} @0x000000031007744b + Ptr{Void} @0x0000000310077537 + Ptr{Void} @0x00000001009e9620 + Ptr{Void} @0x000000031006feec + Ptr{Void} @0x00000003100701b0 + Ptr{Void} @0x00000001009e9635 + Ptr{Void} @0x0000000100a06418 julia> stacktrace(trace) - 4-element Array{StackFrame,1}: - backtrace at error.jl:26 - eval at boot.jl:265 - [inlined code from REPL.jl:3] eval_user_input at REPL.jl:62 - [inlined code from REPL.jl:92] anonymous at task.jl:63 + 5-element Array{StackFrame,1}: + in backtrace() at error.jl:26 + in eval(::Module, ::Any) at boot.jl:231 + in eval_user_input(::Any, ::Base.REPL.REPLBackend) at REPL.jl:62 + in macro expansion at REPL.jl:92 [inlined] + in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at event.jl:46 Notice that the vector returned by :func:`backtrace` had 15 pointers, while the vector returned by :func:`stacktrace` only has 4. This is because, by default, :func:`stacktrace` removes any lower-level C functions from the stack. If you want to include stack frames from C calls, you can do it like this:: - julia> stacktrace(stack, true) - 15-element Array{StackFrame,1}: - [inlined code from task.c:651] rec_backtrace at task.c:711 - backtrace at error.jl:26 - jlcall_backtrace_23146 at :-1 - [inlined code from interpreter.c:55] jl_apply at interpreter.c:65 - eval at interpreter.c:214 - eval at interpreter.c:220 - eval_body at interpreter.c:601 - jl_toplevel_eval_body at interpreter.c:534 - jl_toplevel_eval_flex at toplevel.c:525 - jl_toplevel_eval_in_warn at builtins.c:590 - eval at boot.jl:265 - [inlined code from REPL.jl:3] eval_user_input at REPL.jl:62 - jlcall_eval_user_input_22658 at :-1 - [inlined code from REPL.jl:92] anonymous at task.jl:63 - [inlined code from julia.h:1352] jl_apply at task.c:246 + julia> stacktrace(trace, true) + 26-element Array{StackFrame,1}: + in jl_backtrace_from_here at stackwalk.c:104 + in backtrace() at error.jl:26 + in ip:0x102943635 + in jl_call_method_internal at julia_internal.h:86 [inlined] + in jl_apply_generic at gf.c:1805 + in do_call at interpreter.c:65 + in eval at interpreter.c:188 + in eval_body at interpreter.c:469 + in jl_interpret_call at interpreter.c:573 + in jl_toplevel_eval_flex at toplevel.c:543 + in jl_toplevel_eval_in_warn at builtins.c:571 + in eval(::Module, ::Any) at boot.jl:231 + in ip:0x10265acc1 + in jl_call_method_internal at julia_internal.h:86 [inlined] + in jl_apply_generic at gf.c:1805 + in eval_user_input(::Any, ::Base.REPL.REPLBackend) at REPL.jl:62 + in ip:0x310077537 + in jl_call_method_internal at julia_internal.h:86 [inlined] + in jl_apply_generic at gf.c:1805 + in macro expansion at REPL.jl:92 [inlined] + in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at event.jl:46 + in ip:0x3100701b0 + in jl_call_method_internal at julia_internal.h:86 [inlined] + in jl_apply_generic at gf.c:1795 + in jl_apply at julia.h:1388 [inlined] + in start_task at task.c:247 Individual pointers returned by :func:`backtrace` can be translated into :obj:`StackFrame` s by passing them into :func:`StackTraces.lookup`: .. doctest:: - julia> pointer = backtrace()[1] - Ptr{Void} @0x... + julia> pointer = backtrace()[1]; julia> frame = StackTraces.lookup(pointer) - [inlined code from task.c:663] rec_backtrace at task.c:723 + 1-element Array{StackFrame,1}: + in jl_backtrace_from_here at stackwalk.c:105 - julia> println("The top frame is from $(frame.func)!") - The top frame is from rec_backtrace! + julia> println("The top frame is from $(frame[1].func)!") + The top frame is from jl_backtrace_from_here! diff --git a/doc/manual/strings.rst b/doc/manual/strings.rst index a5a89f554425c..4adec34080742 100644 --- a/doc/manual/strings.rst +++ b/doc/manual/strings.rst @@ -288,13 +288,17 @@ such an invalid byte index, an error is thrown: julia> s[2] ERROR: UnicodeError: invalid character index - in next at ./unicode/utf8.jl:65 - in getindex at strings/basic.jl:37 + in slow_utf8_next(::Array{UInt8,1}, ::UInt8, ::Int64) at ./strings/string.jl:69 + in next at ./strings/string.jl:94 [inlined] + in getindex(::String, ::Int64) at ./strings/basic.jl:70 + ... julia> s[3] ERROR: UnicodeError: invalid character index - in next at ./unicode/utf8.jl:65 - in getindex at strings/basic.jl:37 + in slow_utf8_next(::Array{UInt8,1}, ::UInt8, ::Int64) at ./strings/string.jl:69 + in next at ./strings/string.jl:94 [inlined] + in getindex(::String, ::Int64) at ./strings/basic.jl:70 + ... julia> s[4] ' ' @@ -545,10 +549,11 @@ contained in a string: false julia> contains("Xylophon", 'o') - ERROR: MethodError: `contains` has no method matching contains(::String, ::Char) + ERROR: MethodError: no method matching contains(::String, ::Char) Closest candidates are: contains(!Matched::Function, ::Any, !Matched::Any) contains(::AbstractString, !Matched::AbstractString) + ... The last error is because ``'o'`` is a character literal, and :func:`contains` is a generic function that looks for subsequences. To look for an element in a @@ -870,6 +875,7 @@ error: julia> "DATA\xff\u2200" ERROR: syntax: invalid UTF-8 sequence + ... Also observe the significant distinction between ``\xff`` and ``\uff``: the former escape sequence encodes the *byte 255*, whereas the latter diff --git a/doc/manual/types.rst b/doc/manual/types.rst index 9215c075537f6..a193c1a7c3809 100644 --- a/doc/manual/types.rst +++ b/doc/manual/types.rst @@ -102,6 +102,7 @@ exception is thrown, otherwise, the left-hand value is returned: julia> (1+2)::AbstractFloat ERROR: TypeError: typeassert: expected AbstractFloat, got Int64 + ... julia> (1+2)::Int 3 @@ -411,7 +412,8 @@ However, the value for ``baz`` must be convertible to :class:`Int`: julia> Foo((), 23.5, 1) ERROR: InexactError() - in call at none:2 + in Foo(::Tuple{}, ::Float64, ::Int64) at ./none:2 + ... You may find a list of field names using the ``fieldnames`` function. @@ -442,7 +444,7 @@ You can also change the values as one would expect: .. doctest:: julia> foo.qux = 2 - 2.0 + 2 julia> foo.bar = 1//2 1//2 @@ -765,9 +767,15 @@ each field: ERROR: MethodError: Cannot `convert` an object of type Float64 to an object of type Point{Float64} This may have arisen from a call to the constructor Point{Float64}(...), since type constructors fall back to convert methods. + in Point{Float64}(::Float64) at ./sysimg.jl:53 + ... julia> Point{Float64}(1.0,2.0,3.0) ERROR: MethodError: no method matching Point{Float64}(::Float64, ::Float64, ::Float64) + Closest candidates are: + Point{Float64}{T}(::Any, ::Any) + Point{Float64}{T}(::Any) + ... Only one default constructor is generated for parametric types, since overriding it is not possible. This constructor accepts any arguments @@ -801,6 +809,7 @@ isn't the case, the constructor will fail with a :exc:`MethodError`: julia> Point(1,2.5) ERROR: MethodError: no method matching Point{T}(::Int64, ::Float64) + ... Constructor methods to appropriately handle such mixed cases can be defined, but that will not be discussed until later on in @@ -909,9 +918,11 @@ subtypes of :obj:`Real`: julia> Pointy{AbstractString} ERROR: TypeError: Pointy: in T, expected T<:Real, got Type{AbstractString} + ... julia> Pointy{1} ERROR: TypeError: Pointy: in T, expected T<:Real, got Int64 + ... Type parameters for parametric composite types can be restricted in the same manner:: @@ -1277,16 +1288,21 @@ functions in Julia's standard library accept ``Val`` types as arguments, and you can also use it to write your own functions. For example: -.. doctest:: +.. testsetup:: value-types + + firstlast(::Type{Val{true}}) = "First"; + firstlast(::Type{Val{false}}) = "Last"; + +.. doctest:: value-types firstlast(::Type{Val{true}}) = "First" firstlast(::Type{Val{false}}) = "Last" - julia> println(firstlast(Val{true})) - First + julia> firstlast(Val{true}) + "First" - julia> println(firstlast(Val{false})) - Last + julia> firstlast(Val{false}) + "Last" For consistency across Julia, the call site should always pass a ``Val`` *type* rather than creating an *instance*, i.e., use @@ -1342,13 +1358,13 @@ To construct an object representing a non-missing value of type ``T``, use the .. doctest:: julia> x1 = Nullable(1) - Nullable(1) + Nullable{Int64}(1) julia> x2 = Nullable(1.0) - Nullable(1.0) + Nullable{Float64}(1.0) julia> x3 = Nullable([1, 2, 3]) - Nullable([1,2,3]) + Nullable{Array{Int64,1}}([1,2,3]) Note the core distinction between these two ways of constructing a :obj:`Nullable` object: in one style, you provide a type, ``T``, as a function parameter; in @@ -1376,7 +1392,8 @@ You can safely access the value of a :obj:`Nullable` object using :func:`get`: julia> get(Nullable{Float64}()) ERROR: NullException() - in get(::Nullable{Float64}) at ./nullable.jl:45 + in get(::Nullable{Float64}) at ./nullable.jl:62 + ... julia> get(Nullable(1.0)) 1.0 @@ -1392,10 +1409,10 @@ default value as a second argument to :func:`get`: .. doctest:: - julia> get(Nullable{Float64}(), 0) + julia> get(Nullable{Float64}(), 0.0) 0.0 - julia> get(Nullable(1.0), 0) + julia> get(Nullable(1.0), 0.0) 1.0 Note that this default value will automatically be converted to the type of diff --git a/doc/manual/variables-and-scoping.rst b/doc/manual/variables-and-scoping.rst index 7840eb03ae636..0124026da392a 100644 --- a/doc/manual/variables-and-scoping.rst +++ b/doc/manual/variables-and-scoping.rst @@ -306,11 +306,12 @@ macro definition need not come before its inner usage: .. doctest:: julia> f = y -> x + y - (anonymous function) + (::#1) (generic function with 1 method) julia> f(3) ERROR: UndefVarError: x not defined - in anonymous at none:1 + in (::##1#2)(::Int64) at ./none:1 + ... julia> x = 1 1 diff --git a/doc/manual/variables.rst b/doc/manual/variables.rst index c4a251fc76a9f..039972004a4db 100644 --- a/doc/manual/variables.rst +++ b/doc/manual/variables.rst @@ -128,9 +128,11 @@ statements: julia> else = false ERROR: syntax: unexpected "else" + ... julia> try = "No" ERROR: syntax: unexpected "=" + ... Stylistic Conventions diff --git a/doc/requirements.txt b/doc/requirements.txt index c2765491f318a..e4a55f02db4bd 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,2 +1,2 @@ --e git+https://github.com/JuliaLang/JuliaDoc.git@c87dbaa47f49ecc2b70c2e9cb029b9d3541160aa#egg=JuliaDoc +-e git+https://github.com/JuliaLang/JuliaDoc.git@8dbccf7a4cec7097f005314b7b08f5bb0d3817bc#egg=JuliaDoc -e git+https://github.com/snide/sphinx_rtd_theme.git@21e875d3a53ce897089ad690d897252f6063349d#egg=sphinx_rtd_theme diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index daa5b1ec2ce8d..0492ef81c268c 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -367,7 +367,8 @@ All Objects julia> convert(Int, 3.5) ERROR: InexactError() - in convert at int.jl:209 + in convert(::Type{Int64}, ::Float64) at ./int.jl:239 + ... If ``T`` is a :obj:`AbstractFloat` or :obj:`Rational` type, then it will return the closest value to ``x`` representable by ``T``\ . @@ -533,7 +534,7 @@ Types julia> structinfo(T) = [(fieldoffset(T,i), fieldname(T,i), fieldtype(T,i)) for i = 1:nfields(T)]; julia> structinfo(Base.Filesystem.StatStruct) - 12-element Array{Tuple{UInt64,Symbol,Type{_}},1}: + 12-element Array{Tuple{UInt64,Union{Int64,Symbol},Type{_}},1}: (0x0000000000000000,:device,UInt64) (0x0000000000000008,:inode,UInt64) (0x0000000000000010,:mode,UInt64) diff --git a/doc/stdlib/collections.rst b/doc/stdlib/collections.rst index 095277f615441..54482d0e4136c 100644 --- a/doc/stdlib/collections.rst +++ b/doc/stdlib/collections.rst @@ -1134,7 +1134,8 @@ Dequeues julia> deleteat!([6, 5, 4, 3, 2, 1], (2, 2)) ERROR: ArgumentError: indices must be unique and sorted - in deleteat! at array.jl:543 + in deleteat!(::Array{Int64,1}, ::Tuple{Int64,Int64}) at ./array.jl:511 + ... .. function:: splice!(collection, index, [replacement]) -> item diff --git a/doc/stdlib/linalg.rst b/doc/stdlib/linalg.rst index 30d5dd320531b..813e48e9a5091 100644 --- a/doc/stdlib/linalg.rst +++ b/doc/stdlib/linalg.rst @@ -584,10 +584,7 @@ Linear algebra functions in Julia are largely implemented by calling functions f julia> eig([1.0 0.0 0.0; 0.0 3.0 0.0; 0.0 0.0 18.0]) ([1.0,3.0,18.0], - 3×3 Array{Float64,2}: - 1.0 0.0 0.0 - 0.0 1.0 0.0 - 0.0 0.0 1.0) + [1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0]) ``eig`` is a wrapper around :func:`eigfact`\ , extracting all parts of the factorization to a tuple; where possible, using :func:`eigfact` is recommended. @@ -1479,7 +1476,7 @@ according to the usual Julia convention. Compute ``A B`` in-place and store the result in ``Y``\ , returning the result. If only two arguments are passed, then ``A_ldiv_B!(A, B)`` overwrites ``B`` with the result. - The argument ``A`` should *not* be a matrix. Rather, instead of matrices it should be a factorization object (e.g. produced by :func:`factorize` or :func:`cholfact`\ ). The reason for this is that factorization itself is both expensive and typically allocates memory (although it can also be done in-place via, e.g., :func:`lufact`\ ), and performance-critical situations requiring ``A_ldiv_B!`` usually also require fine-grained control over the factorization of ``A``\ . + The argument ``A`` should *not* be a matrix. Rather, instead of matrices it should be a factorization object (e.g. produced by :func:`factorize` or :func:`cholfact`\ ). The reason for this is that factorization itself is both expensive and typically allocates memory (although it can also be done in-place via, e.g., :func:`lufact!`\ ), and performance-critical situations requiring ``A_ldiv_B!`` usually also require fine-grained control over the factorization of ``A``\ . .. function:: A_ldiv_Bc(A, B) @@ -2525,3 +2522,4 @@ set of functions in future releases. Solves the Sylvester matrix equation ``A * X +/- X * B = scale*C`` where ``A`` and ``B`` are both quasi-upper triangular. If ``transa = N``\ , ``A`` is not modified. If ``transa = T``\ , ``A`` is transposed. If ``transa = C``\ , ``A`` is conjugate transposed. Similarly for ``transb`` and ``B``\ . If ``isgn = 1``\ , the equation ``A * X + X * B = scale * C`` is solved. If ``isgn = -1``\ , the equation ``A * X - X * B = scale * C`` is solved. Returns ``X`` (overwriting ``C``\ ) and ``scale``\ . + diff --git a/doc/stdlib/strings.rst b/doc/stdlib/strings.rst index 40ec3e2d69347..e1ce2a06ed73d 100644 --- a/doc/stdlib/strings.rst +++ b/doc/stdlib/strings.rst @@ -472,3 +472,4 @@ .. Docstring generated from Julia source General unescaping of traditional C and Unicode escape sequences. Reverse of :func:`escape_string`\ . See also :func:`unescape_string`\ . + diff --git a/doc/stdlib/test.rst b/doc/stdlib/test.rst index 05ea608d300ac..4cbc2a0f9057c 100644 --- a/doc/stdlib/test.rst +++ b/doc/stdlib/test.rst @@ -263,24 +263,19 @@ writing new tests. Int64 julia> @code_warntype f(1,2,3) - Variables: - #self#::#f - a::Int64 - b::Int64 - c::Int64 - + ... Body: - begin # REPL[2], line 1: - unless (Base.slt_int)(1,b::Int64)::Bool goto 4 + begin + unless (Base.slt_int)(1,b::Int64)::Bool goto 3 return 1 - 4: + 3: return 1.0 - end::Union{Float64,Int64} + end::UNION{FLOAT64,INT64} julia> @inferred f(1,2,3) ERROR: return type Int64 does not match inferred return type Union{Float64,Int64} in error(::String) at ./error.jl:21 - in eval(::Module, ::Any) at ./boot.jl:226 + ... julia> @inferred max(1,2) 2