Skip to content

Commit 48967d2

Browse files
committed
comprehension NEWS and doc updates
1 parent 6ab60ba commit 48967d2

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

NEWS.md

+7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ Language changes
3737
Instead of adding methods to `call`, methods are added by type using the syntax
3838
`(::ftype)(...) = ...`. `call` is deprecated ([#13412]).
3939

40+
* The type of array returned by a comprehension now depends only on the types of
41+
the computed elements.
42+
Previously, type inference was used to determine the result type ([#7258]).
43+
44+
* Comprehensions preserve the shape of their iteration space. For example,
45+
`[ 2x for x in A ]` will have the same shape as array `A`.
46+
4047
* `using` and `import` are now case-sensitive even on case-insensitive filesystems (common on Mac and Windows) ([#13542]).
4148

4249
* Relational symbols are now allowed as infix operators ([#8036]).

doc/manual/arrays.rst

+4-9
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ and its left and right neighbor along a 1-d grid. :
183183

184184
.. doctest:: array-rand
185185

186-
julia> const x = rand(8)
186+
julia> x = rand(8)
187187
8-element Array{Float64,1}:
188188
0.843025
189189
0.869052
@@ -203,14 +203,9 @@ and its left and right neighbor along a 1-d grid. :
203203
0.8446
204204
0.656511
205205

206-
.. note:: In the above example, ``x`` is declared as constant because type
207-
inference in Julia does not work as well on non-constant global
208-
variables.
209-
210-
The resulting array type is inferred from the expression; in order to control
211-
the type explicitly, the type can be prepended to the comprehension. For example,
212-
in the above example we could have avoided declaring ``x`` as constant, and ensured
213-
that the result is of type ``Float64`` by writing::
206+
The resulting array type depends on the types of the values computed.
207+
In order to control the type explicitly, the type can be prepended to the comprehension.
208+
For example, in the above example we could ensure that the result is of type ``Float64`` by writing::
214209

215210
Float64[ 0.25*x[i-1] + 0.5*x[i] + 0.25*x[i+1] for i=2:length(x)-1 ]
216211

doc/manual/variables-and-scoping.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ introducing scope blocks are:
3131
+================================+==================================================================================+
3232
| :ref:`global <man-global>` | module, baremodule, at interactive prompt (REPL) |
3333
+--------------------------------+------------------------------+---------------------------------------------------+
34-
| :ref:`local <man-local-scope>` | :ref:`soft <man-soft-scope>` | for, while, list-comprehensions, |
34+
| :ref:`local <man-local-scope>` | :ref:`soft <man-soft-scope>` | for, while, comprehensions, |
3535
| | | try-catch-finally, let |
3636
| +------------------------------+---------------------------------------------------+
3737
| | :ref:`hard <man-hard-scope>` | functions (either syntax, anonymous & do-blocks), |
@@ -187,10 +187,10 @@ Soft Local Scope
187187
scope unless a variable is specifically marked with the keyword
188188
``local``.
189189

190-
Soft local scopes are introduced by for-loops, while-loops,
191-
list-comprehensions, try-catch-finally-blocks, and let-blocks. There
192-
are some extra rules for :ref:`let-blocks <man-let-blocks>` and for
193-
:ref:`for-loops and list-comprehensions <man-for-loops-scope>`.
190+
Soft local scopes are introduced by for loops, while loops,
191+
comprehensions, try-catch-finally blocks, and let blocks. There
192+
are some extra rules for :ref:`let blocks <man-let-blocks>` and for
193+
:ref:`for loops and comprehensions <man-for-loops-scope>`.
194194

195195
In the following example the ``x`` and ``y`` refer always to the same
196196
variables as the soft local scope inherits both read and write

0 commit comments

Comments
 (0)