Skip to content

Commit

Permalink
comprehension NEWS and doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jun 3, 2016
1 parent 6ab60ba commit 48967d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down
13 changes: 4 additions & 9 deletions doc/manual/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ]

Expand Down
10 changes: 5 additions & 5 deletions doc/manual/variables-and-scoping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ introducing scope blocks are:
+================================+==================================================================================+
| :ref:`global <man-global>` | module, baremodule, at interactive prompt (REPL) |
+--------------------------------+------------------------------+---------------------------------------------------+
| :ref:`local <man-local-scope>` | :ref:`soft <man-soft-scope>` | for, while, list-comprehensions, |
| :ref:`local <man-local-scope>` | :ref:`soft <man-soft-scope>` | for, while, comprehensions, |
| | | try-catch-finally, let |
| +------------------------------+---------------------------------------------------+
| | :ref:`hard <man-hard-scope>` | functions (either syntax, anonymous & do-blocks), |
Expand Down Expand Up @@ -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 <man-let-blocks>` and for
:ref:`for-loops and list-comprehensions <man-for-loops-scope>`.
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 <man-let-blocks>` and for
:ref:`for loops and comprehensions <man-for-loops-scope>`.

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

0 comments on commit 48967d2

Please sign in to comment.