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. The behavior of the \code{Iterable} must be compatible with an extension of the \code{IterableBase} class in the \code{dart:core} library. |
Lasse Reichstein Nielsen
2015/01/21 10:19:21
No need to mention `IterableBase` in normative tex
gbracha
2015/01/21 19:19:19
I used IterableBase because I don't find the speci
| |
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 \commentary{ |
3511 % I also assume we extend the IterableBase implementation; otherwise one can pre -compute | 3511 A Dart implementation will need to provide a specific implementation of \code{It erable} that will be returned by \SYNC* methods. The only method that needs to b e added by the Dart implementation is \code{iterator}. In all other respects, t he behavior of the \code{Iterable} is dictated by the use of \code{IterableBase} . |
3512 % it all | 3512 } |
3513 | |
3514 \LMHash{} | |
3515 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. | |
3516 | |
3517 Each iterator starts a separate computation. If the \SYNC* function is impure, t he sequence of values yielded by each iterator may differ. | |
3518 | |
3519 \commentary{ | |
3520 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. Unless the underlying \SYNC* function is a mathematically pu re function, it is probably best not to create multiple iterators on the result of a \SYNC* function, either directly or indirectly. | |
Lasse Reichstein Nielsen
2015/01/21 10:19:21
I wouldn't discourage creating multiple iterators.
gbracha
2015/01/21 19:19:19
Done.
| |
3521 } | |
3522 | |
3523 Each iterator runs with its own copies of all local variables; in particular, ea ch iterator has the same initial arguments, even if their bindings are modified by the function. | |
Lasse Reichstein Nielsen
2015/01/21 10:19:21
Good catch! There really is one invocation of the
hausner
2015/01/21 17:33:03
What does "its own copies of all local variables"
gbracha
2015/01/21 19:19:18
Shallow copy.
| |
3524 \commentary{ | |
3525 Two executions of an iterator interact only via state outside the function. | |
3526 } | |
3527 % 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. | |
3528 | |
3513 | 3529 |
3514 \LMHash{} | 3530 \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. | 3531 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 | 3532 |
3517 | 3533 |
3518 \LMHash{} | 3534 \LMHash{} |
3519 Execution of $f$ terminates when the first of the following occurs: | 3535 Execution of $f$ terminates when the first of the following occurs: |
3520 \begin{itemize} | 3536 \begin{itemize} |
3521 \item An exception is thrown and not caught within the current function activati on. | 3537 \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. | 3538 \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 | 7367 |
7352 The invariant that each normative paragraph is associated with a line | 7368 The invariant that each normative paragraph is associated with a line |
7353 containing the text \LMHash{} should be maintained. Extra occurrences | 7369 containing the text \LMHash{} should be maintained. Extra occurrences |
7354 of \LMHash{} can be added if needed, e.g., in order to make | 7370 of \LMHash{} can be added if needed, e.g., in order to make |
7355 individual \item{}s in itemized lists addressable. Each \LM.. command | 7371 individual \item{}s in itemized lists addressable. Each \LM.. command |
7356 must occur on a separate line. \LMHash{} must occur immediately | 7372 must occur on a separate line. \LMHash{} must occur immediately |
7357 before the associated paragraph, and \LMLabel must occur immediately | 7373 before the associated paragraph, and \LMLabel must occur immediately |
7358 after the associated \section{}, \subsection{} etc. | 7374 after the associated \section{}, \subsection{} etc. |
7359 | 7375 |
7360 ---------------------------------------------------------------------- | 7376 ---------------------------------------------------------------------- |
OLD | NEW |