OLD | NEW |
1 \documentclass{article} | 1 \documentclass{article} |
2 \usepackage{epsfig} | 2 \usepackage{epsfig} |
3 \usepackage{color} | 3 \usepackage{color} |
4 \usepackage{dart} | 4 \usepackage{dart} |
5 \usepackage{bnf} | 5 \usepackage{bnf} |
6 \usepackage{hyperref} | 6 \usepackage{hyperref} |
7 \usepackage{lmodern} | 7 \usepackage{lmodern} |
8 \newcommand{\code}[1]{{\sf #1}} | 8 \newcommand{\code}[1]{{\sf #1}} |
9 \title{Dart Programming Language Specification \\ | 9 \title{Dart Programming Language Specification \\ |
10 {\large Version 1.9}} | 10 {\large Version 1.9}} |
(...skipping 3487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3498 When an asynchronous generator's stream has been canceled, cleanup will occur in
the \FINALLY{} clauses (\ref{try}) inside the generator. We choose to direct an
y exceptions that occur at this time to the cancellation future rather than have
them be lost. | 3498 When an asynchronous generator's stream has been canceled, cleanup will occur in
the \FINALLY{} clauses (\ref{try}) inside the generator. We choose to direct an
y exceptions that occur at this time to the cancellation future rather than have
them be lost. |
3499 } | 3499 } |
3500 | 3500 |
3501 \LMHash{} | 3501 \LMHash{} |
3502 If $f$ is asynchronous then, when $f$ terminates, any open stream subscriptions
associated with any asynchronous for loops (\ref{asynchronousFor-in}) or yield-
each statements (\ref{yieldEach}) executing within $f$ are canceled. | 3502 If $f$ is asynchronous then, when $f$ terminates, any open stream subscriptions
associated with any asynchronous for loops (\ref{asynchronousFor-in}) or yield-
each statements (\ref{yieldEach}) executing within $f$ are canceled. |
3503 | 3503 |
3504 \rationale{Such streams may be left open by for loops that were escaped when an
exception was thrown within them for example. | 3504 \rationale{Such streams may be left open by for loops that were escaped when an
exception was thrown within them for example. |
3505 } | 3505 } |
3506 | 3506 |
3507 \LMHash{} | 3507 \LMHash{} |
3508 If $f$ is marked \SYNC* (\ref{functions}), then a fresh instance $i$ implementin
g the built-in class \code{Iterable} is associated with the invocation and immed
iately returned. When iteration over the iterable is started, by getting an iter
ator $j$ from the iterable and calling \code{moveNext()} on it, execution of the
body of $f$ will begin. When $f$ terminates, $j$ is positioned after its last e
lement, so that its current value is \NULL{} and the current call to \code{moveN
ext()} on $j$ returns false, as will all further calls. | 3508 If $f$ is marked \SYNC* (\ref{functions}), then a fresh instance $i$ implementin
g the built-in class \code{Iterable} is associated with the invocation and immed
iately returned. |
3509 | 3509 |
3510 % Can we get more than one iterator from this Iterable? I'd say yes. And if so,
do they restart the computation or do they iterate over previously computed resu
lts. My guess is the latter. | 3510 |
3511 % I also assume we extend the IterableBase implementation; otherwise one can pre
-compute | 3511 \commentary{ |
3512 % it all | 3512 A Dart implementation will need to provide a specific implementation of \code{It
erable} that will be returned by \SYNC* methods. A typical strategy would be to
produce an instance of a subclass of class \code{IterableBase} defined in \code{
dart:core}. The only method that needs to be added by the Dart implementation in
that case is \code{iterator}. |
| 3513 } |
| 3514 |
| 3515 \LMHash{} |
| 3516 The iterable implementation must comply with the contract of \code{Iterable} and
should not take any steps identified as exceptionally efficient in that contrac
t. |
| 3517 |
| 3518 \commentary { |
| 3519 The contract explicitly mentions a number of situations where certain iterables
could be more efficient than normal. For example, by precomputing their length.
Normal iterables must iterate over their elements to determine their length. Thi
s is certainly true in the case of a synchronous generator, where each element i
s computed by a function. It would not be acceptable to pre-compute the results
of the generator and cache them, for example. |
| 3520 } |
| 3521 |
| 3522 \LMHash{} |
| 3523 When iteration over the iterable is started, by getting an iterator $j$ from the
iterable and calling \code{moveNext()} on it, execution of the body of $f$ will
begin. When $f$ terminates, $j$ is positioned after its last element, so that i
ts current value is \NULL{} and the current call to \code{moveNext()} on $j$ ret
urns false, as will all further calls. |
| 3524 |
| 3525 Each iterator starts a separate computation. If the \SYNC* function is impure, t
he sequence of values yielded by each iterator may differ. |
| 3526 |
| 3527 \commentary{ |
| 3528 One can derive more than one iterator from a given iterable. Note that operati
ons on the iterable itself can create distinct iterators. An example would be \c
ode{length}. It is conceivable that different iterators might yield sequences o
f different length. The same care needs to be taken when writing \SYNC* function
s as when |
| 3529 writing an \code{Iterator} class. In particular, it should handle multiple |
| 3530 simultaneous iterators gracefully. If the iterator depends on external state |
| 3531 that might change, it should check that the state is still valid after every |
| 3532 yield (and maybe throw a \code{ConcurrentModificationError} if it isn't). |
| 3533 } |
| 3534 |
| 3535 \LMHash{} |
| 3536 Each iterator runs with its own shallow copies of all local variables; in partic
ular, each iterator has the same initial arguments, even if their bindings are m
odified by the function. |
| 3537 \commentary{ |
| 3538 Two executions of an iterator interact only via state outside the function. |
| 3539 } |
| 3540 % The alternative would be to cache the results of an iterator in the iterable,
and check the cache at each \YIELD{}. This would have strange issues as well. T
he yielded value might differ from the expression in the yield. And it is a pote
ntial memory leak as the cache is kept alive by any iterator. |
| 3541 |
3513 | 3542 |
3514 \LMHash{} | 3543 \LMHash{} |
3515 If $f$ is synchronous and is not a generator (\ref{functions}) then execution of
the body of $f$ begins immediately. When $f$ terminates the current return val
ue is returned to the caller. | 3544 If $f$ is synchronous and is not a generator (\ref{functions}) then execution of
the body of $f$ begins immediately. When $f$ terminates the current return val
ue is returned to the caller. |
3516 | 3545 |
3517 | 3546 |
3518 \LMHash{} | 3547 \LMHash{} |
3519 Execution of $f$ terminates when the first of the following occurs: | 3548 Execution of $f$ terminates when the first of the following occurs: |
3520 \begin{itemize} | 3549 \begin{itemize} |
3521 \item An exception is thrown and not caught within the current function activati
on. | 3550 \item An exception is thrown and not caught within the current function activati
on. |
3522 \item A return statement (\ref{return}) immediately nested in the body of $f$ is
executed and not intercepted in a \FINALLY{} (\ref{try}) clause. | 3551 \item A return statement (\ref{return}) immediately nested in the body of $f$ is
executed and not intercepted in a \FINALLY{} (\ref{try}) clause. |
(...skipping 3828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7351 | 7380 |
7352 The invariant that each normative paragraph is associated with a line | 7381 The invariant that each normative paragraph is associated with a line |
7353 containing the text \LMHash{} should be maintained. Extra occurrences | 7382 containing the text \LMHash{} should be maintained. Extra occurrences |
7354 of \LMHash{} can be added if needed, e.g., in order to make | 7383 of \LMHash{} can be added if needed, e.g., in order to make |
7355 individual \item{}s in itemized lists addressable. Each \LM.. command | 7384 individual \item{}s in itemized lists addressable. Each \LM.. command |
7356 must occur on a separate line. \LMHash{} must occur immediately | 7385 must occur on a separate line. \LMHash{} must occur immediately |
7357 before the associated paragraph, and \LMLabel must occur immediately | 7386 before the associated paragraph, and \LMLabel must occur immediately |
7358 after the associated \section{}, \subsection{} etc. | 7387 after the associated \section{}, \subsection{} etc. |
7359 | 7388 |
7360 ---------------------------------------------------------------------- | 7389 ---------------------------------------------------------------------- |
OLD | NEW |