diff --git a/NEWS.md b/NEWS.md index 0347d3fed9f9d..f43352727ca0e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -37,6 +37,13 @@ Language changes Instead of adding methods to `call`, methods are added by type using the syntax `(::ftype)(...) = ...`. `call` is deprecated ([#13412]). + * The type of array returned by a comprehension now depends only on the types of + the computed elements. + Previously, type inference was used to determine the result type ([#7258]). + + * Comprehensions preserve the shape of their iteration space. For example, + `[ 2x for x in A ]` will have the same shape as array `A`. + * `using` and `import` are now case-sensitive even on case-insensitive filesystems (common on Mac and Windows) ([#13542]). * Relational symbols are now allowed as infix operators ([#8036]). diff --git a/doc/manual/arrays.rst b/doc/manual/arrays.rst index 8dea6274d3a6f..bf8a906c7322d 100644 --- a/doc/manual/arrays.rst +++ b/doc/manual/arrays.rst @@ -183,7 +183,7 @@ and its left and right neighbor along a 1-d grid. : .. doctest:: array-rand - julia> const x = rand(8) + julia> x = rand(8) 8-element Array{Float64,1}: 0.843025 0.869052 @@ -203,14 +203,9 @@ and its left and right neighbor along a 1-d grid. : 0.8446 0.656511 -.. note:: In the above example, ``x`` is declared as constant because type - inference in Julia does not work as well on non-constant global - variables. - -The resulting array type is inferred from the expression; in order to control -the type explicitly, the type can be prepended to the comprehension. For example, -in the above example we could have avoided declaring ``x`` as constant, and ensured -that the result is of type ``Float64`` by writing:: +The resulting array type depends on the types of the values computed. +In order to control the type explicitly, the type can be prepended to the comprehension. +For example, in the above example we could ensure that the result is of type ``Float64`` by writing:: Float64[ 0.25*x[i-1] + 0.5*x[i] + 0.25*x[i+1] for i=2:length(x)-1 ] diff --git a/doc/manual/variables-and-scoping.rst b/doc/manual/variables-and-scoping.rst index 480e836bf9a82..b22ade65991f0 100644 --- a/doc/manual/variables-and-scoping.rst +++ b/doc/manual/variables-and-scoping.rst @@ -31,7 +31,7 @@ introducing scope blocks are: +================================+==================================================================================+ | :ref:`global ` | module, baremodule, at interactive prompt (REPL) | +--------------------------------+------------------------------+---------------------------------------------------+ -| :ref:`local ` | :ref:`soft ` | for, while, list-comprehensions, | +| :ref:`local ` | :ref:`soft ` | for, while, comprehensions, | | | | try-catch-finally, let | | +------------------------------+---------------------------------------------------+ | | :ref:`hard ` | functions (either syntax, anonymous & do-blocks), | @@ -187,10 +187,10 @@ Soft Local Scope scope unless a variable is specifically marked with the keyword ``local``. -Soft local scopes are introduced by for-loops, while-loops, -list-comprehensions, try-catch-finally-blocks, and let-blocks. There -are some extra rules for :ref:`let-blocks ` and for -:ref:`for-loops and list-comprehensions `. +Soft local scopes are introduced by for loops, while loops, +comprehensions, try-catch-finally blocks, and let blocks. There +are some extra rules for :ref:`let blocks ` and for +:ref:`for loops and comprehensions `. In the following example the ``x`` and ``y`` refer always to the same variables as the soft local scope inherits both read and write