Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(559)

Side by Side Diff: docs/language/dartLangSpec.tex

Issue 858063002: Clarify behavior of iterables and iterators with sync*. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 th e \code{IterableBase} class in the \code{dart:core} library.
Lasse Reichstein Nielsen 2015/01/22 15:23:45 Still doesn't *really* say anything (it's unspecif
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 \rationale{
3515 Ideally, it would suffice to state that an implementation of \code{utterable} mu st be provided, and we would not refer to a specific implementation. However, th e contract for \code{Iterable} is not as precise as we would like.
3516 }
3517
3518
3519 \LMHash{}
3520 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.
3521
3522 Each iterator starts a separate computation. If the \SYNC* function is impure, t he sequence of values yielded by each iterator may differ.
3523
3524 \commentary{
3525 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
3526 writing an \code{Iterator} class. In particular, it should handle multiple
3527 simultaneous iterators gracefully. If the iterator depends on external state
3528 that might change, it should check that the state is still valid after every
3529 yield (and maybe throw a \code{ConcurrentModificationError} if it isn't).
3530 }
3531
3532 \LMHash{}
3533 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.
3534 \commentary{
3535 Two executions of an iterator interact only via state outside the function.
3536 }
3537 % 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.
3538
3513 3539
3514 \LMHash{} 3540 \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. 3541 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 3542
3517 3543
3518 \LMHash{} 3544 \LMHash{}
3519 Execution of $f$ terminates when the first of the following occurs: 3545 Execution of $f$ terminates when the first of the following occurs:
3520 \begin{itemize} 3546 \begin{itemize}
3521 \item An exception is thrown and not caught within the current function activati on. 3547 \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. 3548 \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
7351 7377
7352 The invariant that each normative paragraph is associated with a line 7378 The invariant that each normative paragraph is associated with a line
7353 containing the text \LMHash{} should be maintained. Extra occurrences 7379 containing the text \LMHash{} should be maintained. Extra occurrences
7354 of \LMHash{} can be added if needed, e.g., in order to make 7380 of \LMHash{} can be added if needed, e.g., in order to make
7355 individual \item{}s in itemized lists addressable. Each \LM.. command 7381 individual \item{}s in itemized lists addressable. Each \LM.. command
7356 must occur on a separate line. \LMHash{} must occur immediately 7382 must occur on a separate line. \LMHash{} must occur immediately
7357 before the associated paragraph, and \LMLabel must occur immediately 7383 before the associated paragraph, and \LMLabel must occur immediately
7358 after the associated \section{}, \subsection{} etc. 7384 after the associated \section{}, \subsection{} etc.
7359 7385
7360 ---------------------------------------------------------------------- 7386 ----------------------------------------------------------------------
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698