From 83d695848943bad5acb5d7a95f057e401ee8f810 Mon Sep 17 00:00:00 2001 From: Daan Huybrechs Date: Wed, 8 Apr 2015 16:45:44 +0200 Subject: [PATCH 1/6] Update methods.rst The change mentions a possible side-effect of the implementation of optional arguments that was discussed on julia-users: https://groups.google.com/forum/#!topic/julia-users/gNMILY7s95c --- doc/manual/methods.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/manual/methods.rst b/doc/manual/methods.rst index 6baf6b522e6ee..f30084ed7e84d 100644 --- a/doc/manual/methods.rst +++ b/doc/manual/methods.rst @@ -538,6 +538,15 @@ translates to the following three methods:: f(a) = f(a,2) f() = f(1,2) +The first method is the original definition of ``f``. The second and third methods +call ``f`` using the default values of ``a`` and ``b``. It should be noted that +these function calls are subject to method dispatch as usual, and so they may also +call different methods of ``f``. For example, if you have also defined + + f(a::Int,b::Int) = a-2b + +then the result of ``f()`` will be ``1 - 4 = -3`` instead of ``1 + 4 = 5``. + Keyword arguments behave quite differently from ordinary positional arguments. In particular, they do not participate in method dispatch. Methods are dispatched based only on positional arguments, with keyword arguments processed From c21ace26bca8844252285d782f3b2487fa5d9b8e Mon Sep 17 00:00:00 2001 From: Daan Date: Tue, 21 Apr 2015 11:00:52 +0200 Subject: [PATCH 2/6] Update notes on optional arguments [av skip] --- doc/manual/functions.rst | 2 +- doc/manual/methods.rst | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/manual/functions.rst b/doc/manual/functions.rst index a433e3070b4ce..ca3fa15e1ce6a 100644 --- a/doc/manual/functions.rst +++ b/doc/manual/functions.rst @@ -448,7 +448,7 @@ specified: Optional arguments are actually just a convenient syntax for writing multiple method definitions with different numbers of arguments -(see :ref:`man-methods`). +(see :ref:`man-note-on-optinal-and-keyword-arguments`). Keyword Arguments diff --git a/doc/manual/methods.rst b/doc/manual/methods.rst index f30084ed7e84d..496198ed33f11 100644 --- a/doc/manual/methods.rst +++ b/doc/manual/methods.rst @@ -523,6 +523,8 @@ can also constrain type parameters of methods:: The ``same_type_numeric`` function behaves much like the ``same_type`` function defined above, but is only defined for pairs of numbers. +.. _man-Note-on-optional-and-keyword-arguments: + Note on Optional and keyword Arguments -------------------------------------- @@ -538,14 +540,20 @@ translates to the following three methods:: f(a) = f(a,2) f() = f(1,2) -The first method is the original definition of ``f``. The second and third methods -call ``f`` using the default values of ``a`` and ``b``. It should be noted that -these function calls are subject to method dispatch as usual, and so they may also -call different methods of ``f``. For example, if you have also defined +This means that calling ``f()`` is equivalent to calling ``f(1,2)``. In +this case the result would be ``5``, because ``f(1,2)`` invokes the first +method of ``f`` above. + +However, this need not always be the case. If you define a fourth +method:: f(a::Int,b::Int) = a-2b - -then the result of ``f()`` will be ``1 - 4 = -3`` instead of ``1 + 4 = 5``. + +then the result of both ``f()`` and ``f(1,2)`` is ``-3``. In other words, +optional arguments are tied to a function, not to any specific method of +that function. It depends on the types of the optional arguments which +method is called. When optional arguments are defined in terms of a global +variable, the type of the optional argument may even change at run-time. Keyword arguments behave quite differently from ordinary positional arguments. In particular, they do not participate in method dispatch. Methods are From ca0082ebbff6aeeb1a3bae8da1992a085507d102 Mon Sep 17 00:00:00 2001 From: Daan Date: Tue, 21 Apr 2015 11:13:22 +0200 Subject: [PATCH 3/6] Update notes on optional arguments [av skip] --- doc/manual/methods.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/doc/manual/methods.rst b/doc/manual/methods.rst index 496198ed33f11..a8701e47ef872 100644 --- a/doc/manual/methods.rst +++ b/doc/manual/methods.rst @@ -541,18 +541,16 @@ translates to the following three methods:: f() = f(1,2) This means that calling ``f()`` is equivalent to calling ``f(1,2)``. In -this case the result would be ``5``, because ``f(1,2)`` invokes the first -method of ``f`` above. - -However, this need not always be the case. If you define a fourth -method:: +this case the result is ``5``, because ``f(1,2)`` invokes the first +method of ``f`` above. However, this need not always be the case. If you +define a fourth method that is more specialized for integers:: f(a::Int,b::Int) = a-2b then the result of both ``f()`` and ``f(1,2)`` is ``-3``. In other words, optional arguments are tied to a function, not to any specific method of that function. It depends on the types of the optional arguments which -method is called. When optional arguments are defined in terms of a global +method is invoked. When optional arguments are defined in terms of a global variable, the type of the optional argument may even change at run-time. Keyword arguments behave quite differently from ordinary positional arguments. From 9351cc0cf4281691fba98ca600cc0dbd36c8eac5 Mon Sep 17 00:00:00 2001 From: Daan Date: Tue, 21 Apr 2015 11:18:58 +0200 Subject: [PATCH 4/6] Update notes on optional arguments [av skip] --- doc/manual/functions.rst | 2 +- doc/manual/methods.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/manual/functions.rst b/doc/manual/functions.rst index ca3fa15e1ce6a..59e2feb0306c1 100644 --- a/doc/manual/functions.rst +++ b/doc/manual/functions.rst @@ -448,7 +448,7 @@ specified: Optional arguments are actually just a convenient syntax for writing multiple method definitions with different numbers of arguments -(see :ref:`man-note-on-optinal-and-keyword-arguments`). +(see :ref:`man-note-on-optional-and-keyword-arguments`). Keyword Arguments diff --git a/doc/manual/methods.rst b/doc/manual/methods.rst index a8701e47ef872..db28ab83b546e 100644 --- a/doc/manual/methods.rst +++ b/doc/manual/methods.rst @@ -523,7 +523,7 @@ can also constrain type parameters of methods:: The ``same_type_numeric`` function behaves much like the ``same_type`` function defined above, but is only defined for pairs of numbers. -.. _man-Note-on-optional-and-keyword-arguments: +.. _man-note-on-optional-and-keyword-arguments: Note on Optional and keyword Arguments -------------------------------------- From d39b4756eb71dc20d43f442a2c858c1b88d74c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jiahao=20Chen=20=28=E9=99=88=E5=AE=B6=E8=B1=AA=29?= Date: Sun, 26 Apr 2015 16:41:04 -0400 Subject: [PATCH 5/6] Fix ReST formatting errors in docs Introduced by recent updates to the documentation. Ref: 7ae6f166 809cc821 f96e33b1 --- doc/manual/arrays.rst | 1 + doc/manual/types.rst | 2 +- doc/stdlib/arrays.rst | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/manual/arrays.rst b/doc/manual/arrays.rst index 34ea01380dfa1..62272edbd1652 100644 --- a/doc/manual/arrays.rst +++ b/doc/manual/arrays.rst @@ -239,6 +239,7 @@ innermost array being indexed. Alternatively, single elements of a multidimensional array can be indexed as :: + x = A[I] where ``I`` is a ``CartesianIndex``, effectively an ``n``-tuple of integers. diff --git a/doc/manual/types.rst b/doc/manual/types.rst index 7e5d50a3836a8..d315381e5b096 100644 --- a/doc/manual/types.rst +++ b/doc/manual/types.rst @@ -917,7 +917,7 @@ function itself. The salient aspects of a function's arguments are their order and their types. Therefore a tuple type is similar to a parameterized immutable type where each parameter is the type of one field. For example, a 2-element tuple type resembles the following -immutable type: +immutable type:: immutable Tuple2{A,B} a::A diff --git a/doc/stdlib/arrays.rst b/doc/stdlib/arrays.rst index 20d3d702c6a2d..9479407574983 100644 --- a/doc/stdlib/arrays.rst +++ b/doc/stdlib/arrays.rst @@ -65,7 +65,7 @@ Basic functions An abstract array subtype ``MyArray`` that wishes to opt into fast linear indexing behaviors should define ``linearindexing`` in the type-domain:: - Base.linearindexing{T<:MyArray}(::Type{T}) = Base.LinearFast() + Base.linearindexing{T<:MyArray}(::Type{T}) = Base.LinearFast() .. function:: countnz(A) From c9ac270be2678363c4899efe3876ebecf579bf11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jiahao=20Chen=20=28=E9=99=88=E5=AE=B6=E8=B1=AA=29?= Date: Sun, 26 Apr 2015 16:41:42 -0400 Subject: [PATCH 6/6] Regenerate helpdb with fewer ReST errors --- doc/helpdb.jl | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/doc/helpdb.jl b/doc/helpdb.jl index aac90438399e1..727737894500e 100644 --- a/doc/helpdb.jl +++ b/doc/helpdb.jl @@ -90,7 +90,7 @@ Any[ linear indexing behaviors should define \"linearindexing\" in the type-domain: - Base.linearindexing{T<:MyArray}(::Type{T}) = Base.LinearFast() + Base.linearindexing{T<:MyArray}(::Type{T}) = Base.LinearFast() "), @@ -1368,11 +1368,20 @@ Any[ "), +("Base","which","which(symbol) + + Return the module in which the binding for the variable referenced + by \"symbol\" was created. + +"), + ("Base","@which","@which() - Evaluates the arguments to the specified function call, and returns - the \"Method\" object for the method that would be called for those - arguments. + Applied to a function call, it evaluates the arguments to the + specified function call, and returns the \"Method\" object for the + method that would be called for those arguments. Applied to a + variable, it returns the module in which the variable was bound. It + calls out to the \"which\" function. "), @@ -5175,11 +5184,12 @@ Millisecond(v) ("Base","cp","cp(src::AbstractString, dst::AbstractString; remove_destination::Bool=false, follow_symlinks::Bool=false) Copy the file, link, or directory from *src* to *dest*. - \"remove_destination=true\" will first remove an existing `dst`. + \"remove_destination=true\" will first remove an existing *dst*. - If `follow_symlinks=false`, and src is a symbolic link, dst will be created as a symbolic link. - If `follow_symlinks=true` and src is a symbolic link, dst will be a copy of the file or directory - `src` refers to. + If *follow_symlinks=false*, and src is a symbolic link, dst will be + created as a symbolic link. If *follow_symlinks=true* and src is a + symbolic link, dst will be a copy of the file or directory *src* + refers to. "),