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 \usepackage[T1]{fontenc} | 8 \usepackage[T1]{fontenc} |
9 \newcommand{\code}[1]{{\sf #1}} | 9 \newcommand{\code}[1]{{\sf #1}} |
10 \title{Dart Programming Language Specification \\ | 10 \title{Dart Programming Language Specification \\ |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 . | 607 . |
608 | 608 |
609 \end{grammar} | 609 \end{grammar} |
610 | 610 |
611 \LMHash{} | 611 \LMHash{} |
612 Functions include function declarations (\ref{functionDeclarations}), methods ( \ref{instanceMethods}, \ref{staticMethods}), getters (\ref{getters}), setters (\ref{setters}), constructors (\ref{constructors}) and function literals (\re f{functionExpressions}). | 612 Functions include function declarations (\ref{functionDeclarations}), methods ( \ref{instanceMethods}, \ref{staticMethods}), getters (\ref{getters}), setters (\ref{setters}), constructors (\ref{constructors}) and function literals (\re f{functionExpressions}). |
613 | 613 |
614 \LMHash{} | 614 \LMHash{} |
615 All functions have a signature and a body. The signature describes the formal pa rameters of the function, and possibly its name and return type. A function bod y is either: | 615 All functions have a signature and a body. The signature describes the formal pa rameters of the function, and possibly its name and return type. A function bod y is either: |
616 \begin{itemize} | 616 \begin{itemize} |
617 \item A block statement (\ref{blocks}) containing the statements (\ref{stateme nts}) executed by the function, optionally marked with one of the modifiers: \AS YNC, \ASYNC* or \SYNC*. In this case, if the last statement of a function is not a return statement (\ref{return}), the statement \code{\RETURN{};} is implicitl y appended to the function body. | 617 \item A block statement (\ref{blocks}) containing the statements (\ref{statemen ts}) executed by the function, optionally marked with one of the modifiers: \ASY NC, \ASYNC* or \SYNC*. |
eernst
2017/05/19 09:48:14
Might as well fix all the stray double spaces (the
Lasse Reichstein Nielsen
2017/05/22 14:18:49
Indeed, I wrote that into the specification of met
eernst
2017/05/22 16:06:40
Acknowledged.
| |
618 | 618 |
619 \rationale{ | 619 \commentary{ |
eernst
2017/05/19 09:48:14
We haven't been re-categorizing rationale/commenta
Lasse Reichstein Nielsen
2017/05/22 14:18:49
My reason for changing this is that this is really
eernst
2017/05/22 16:06:40
Acknowledged.
| |
620 Because Dart is optionally typed, we cannot guarantee that a function that does not return a value will not be used in the context of an expression. Therefore, every function must return a value. A \RETURN{} without an expression returns \N ULL{}. For generator functions, the situation is more subtle. See further discus sion in section \ref{return}. | 620 Because Dart is optionally typed, we cannot guarantee that a function that does not return a value will not be used in the context of an expression. Therefore, every function must return a value. A function body that ends without doing a th row or return will cause the function to return \NULL{}, as will a \RETURN{} wit hout an expression. For generator functions, the situation is more subtle. See f urther discussion in section \ref{return}. |
621 } | 621 } |
622 | 622 |
623 OR | 623 OR |
624 \item of the form \code{=> $e$} which is equivalent to a body of the form \cod e{\{\RETURN{} $e$;\}} or the form \code{\ASYNC{} => $e$} which is equivalent to a body of the form \code{\ASYNC{} \{\RETURN{} $e$;\}}. \rationale{The other modi fiers do not apply here, because they apply only to generators, discussed below, and generators do not allow the form \code{\RETURN{} $e$}; values are added to the generated stream or iterable using \YIELD{} instead.} | 624 \item of the form \code{async => $e$} or the form \code{\ASYNC{} => $e$}, which both return the value of the expression $e$ as if by a \code{return $e$}. \ratio nale{The other modifiers do not apply here, because they apply only to generator s, discussed below, and generators do not allow returning a value, values are ad ded to the generated stream or iterable using \YIELD{} instead.} |
eernst
2017/05/19 09:48:14
I believe it's a typo to have `async` in the first
Lasse Reichstein Nielsen
2017/05/22 14:18:49
Yes on typo. Fixed.
Changed to commentary.
I'm n
eernst
2017/05/22 16:06:40
Acknowledged.
| |
625 } | |
626 Let $R$ be the static type of $e$ | |
627 and let $T$ be the actual return type (\ref{actualTypeOfADeclaration}) | |
628 of the function that has this body. | |
629 It is a static warning if $T$ is not \VOID{} and either | |
630 the function is synchronous and the static type of $R$ is not assignable to $T$, | |
631 or the function is asynchronous and \code{Future<flatten{$R$}>} | |
eernst
2017/05/19 09:48:14
`\code{Future<$flatten$($R$)>}`, for consistency w
Lasse Reichstein Nielsen
2017/05/22 14:18:49
Flatten fixed, both three places. The other ones c
eernst
2017/05/22 16:06:40
Oops, there's still one typo: '{..}' should be cha
| |
632 is not assignable to $T$. | |
625 | 633 |
626 \end{itemize} | 634 \end{itemize} |
627 | 635 |
628 \LMHash{} | 636 \LMHash{} |
629 A function is {\em asynchronous} if its body is marked with the \ASYNC{} or \ASY NC* modifier. Otherwise the function is {\em synchronous}. A function is a {\em generator} if its body is marked with the \SYNC* or \ASYNC* modifier. | 637 A function is {\em asynchronous} if its body is marked with the \ASYNC{} or \ASY NC* modifier. Otherwise the function is {\em synchronous}. A function is a {\em generator} if its body is marked with the \SYNC* or \ASYNC* modifier. |
630 | 638 |
631 \commentary{ | 639 \commentary{ |
632 Whether a function is synchronous or asynchronous is orthogonal to whether it is a generator or not. Generator functions are a sugar for functions that produce collections in a systematic way, by lazily applying a function that {\em generat es} individual elements of a collection. Dart provides such a sugar in both the synchronous case, where one returns an iterable, and in the asynchronous case, w here one returns a stream. Dart also allows both synchronous and asynchronous fu nctions that produce a single value. | 640 Whether a function is synchronous or asynchronous is orthogonal to whether it is a generator or not. Generator functions are a sugar for functions that produce collections in a systematic way, by lazily applying a function that {\em generat es} individual elements of a collection. Dart provides such a sugar in both the synchronous case, where one returns an iterable, and in the asynchronous case, w here one returns a stream. Dart also allows both synchronous and asynchronous fu nctions that produce a single value. |
633 } | 641 } |
634 | 642 |
(...skipping 3066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3701 | 3709 |
3702 | 3710 |
3703 | 3711 |
3704 \subsection{ Function Invocation} | 3712 \subsection{ Function Invocation} |
3705 \LMLabel{functionInvocation} | 3713 \LMLabel{functionInvocation} |
3706 | 3714 |
3707 \LMHash{} | 3715 \LMHash{} |
3708 Function invocation occurs in the following cases: when a function expression ( \ref{functionExpressions}) is invoked (\ref{functionExpressionInvocation}), when a method (\ref{methodInvocation}), getter (\ref{topLevelGetterInvocation}, \ref {propertyExtraction}) or setter (\ref{assignment}) is invoked or when a construc tor is invoked (either via instance creation (\ref{instanceCreation}), construct or redirection (\ref{redirectingConstructors}) or super initialization). The var ious kinds of function invocation differ as to how the function to be invoked, $ f$, is determined, as well as whether \THIS{} (\ref{this}) is bound. Once $f$ h as been determined, the formal parameters of $f$ are bound to corresponding actu al arguments. When the body of $f$ is executed it will be executed with the afor ementioned bindings. | 3716 Function invocation occurs in the following cases: when a function expression ( \ref{functionExpressions}) is invoked (\ref{functionExpressionInvocation}), when a method (\ref{methodInvocation}), getter (\ref{topLevelGetterInvocation}, \ref {propertyExtraction}) or setter (\ref{assignment}) is invoked or when a construc tor is invoked (either via instance creation (\ref{instanceCreation}), construct or redirection (\ref{redirectingConstructors}) or super initialization). The var ious kinds of function invocation differ as to how the function to be invoked, $ f$, is determined, as well as whether \THIS{} (\ref{this}) is bound. Once $f$ h as been determined, the formal parameters of $f$ are bound to corresponding actu al arguments. When the body of $f$ is executed it will be executed with the afor ementioned bindings. |
3709 | 3717 |
3710 \LMHash{} | 3718 \LMHash{} |
3719 Executing a body of the form \code{=> $e$} is equivalent to executing a body of the form \code{\{ return $e$; \}}. | |
3720 Execution a body of the form \code{async => $e$} is equivalent to executing a bo dy of the form \code{async \{ return $e$; \}}. | |
eernst
2017/05/19 09:48:14
I think we should use `\ASYNC{}` to get the right
| |
3721 | |
3722 \LMHash{} | |
3711 If $f$ is synchronous and is not a generator (\ref{functions}) then execution of the body of $f$ begins immediately. | 3723 If $f$ is synchronous and is not a generator (\ref{functions}) then execution of the body of $f$ begins immediately. |
3712 If the execution of the body of $f$ returns a value, $v$, (\ref{completion}), th e invocation evaluates to $v$. | 3724 If the execution of the body of $f$ returns a value, $v$, (\ref{completion}), th e invocation evaluates to $v$. |
3713 If the execution completes normally or it returns without a value, the invocatio n evaluates to \NULL (\ref{null}). | 3725 If the execution completes normally or it returns without a value, the invocatio n evaluates to \NULL (\ref{null}). |
3714 If the execution throws an exception object and stack trace, the invocation thro ws the same exception object and stack trace (\ref{evaluation}). | 3726 If the execution throws an exception object and stack trace, the invocation thro ws the same exception object and stack trace (\ref{evaluation}). |
3715 | 3727 |
3716 \commentary{ | 3728 \commentary{ |
3717 A complete function body can never break or contine (\ref{completion}) | 3729 A complete function body can never break or contine (\ref{completion}) |
3718 because a \BREAK{} or \CONTINUE{} statement must always occur inside the stateme nt that is the target of the \BREAK{} or \CONTINUE{}. | 3730 because a \BREAK{} or \CONTINUE{} statement must always occur inside the stateme nt that is the target of the \BREAK{} or \CONTINUE{}. |
3719 This means that a function body can only either complete normally, throw, or ret urn. Completing normally or returning without a value is treated the same as ret urning \NULL, so the result of executing a function body can always be used as t he result of evaluating an expression, either by evaluating to a value or by the evaluation throwing. | 3731 This means that a function body can only either complete normally, throw, or ret urn. Completing normally or returning without a value is treated the same as ret urning \NULL, so the result of executing a function body can always be used as t he result of evaluating an expression, either by evaluating to a value or by the evaluation throwing. |
3720 } | 3732 } |
(...skipping 4437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8158 | 8170 |
8159 The invariant that each normative paragraph is associated with a line | 8171 The invariant that each normative paragraph is associated with a line |
8160 containing the text \LMHash{} should be maintained. Extra occurrences | 8172 containing the text \LMHash{} should be maintained. Extra occurrences |
8161 of \LMHash{} can be added if needed, e.g., in order to make | 8173 of \LMHash{} can be added if needed, e.g., in order to make |
8162 individual \item{}s in itemized lists addressable. Each \LM.. command | 8174 individual \item{}s in itemized lists addressable. Each \LM.. command |
8163 must occur on a separate line. \LMHash{} must occur immediately | 8175 must occur on a separate line. \LMHash{} must occur immediately |
8164 before the associated paragraph, and \LMLabel must occur immediately | 8176 before the associated paragraph, and \LMLabel must occur immediately |
8165 after the associated \section{}, \subsection{} etc. | 8177 after the associated \section{}, \subsection{} etc. |
8166 | 8178 |
8167 ---------------------------------------------------------------------- | 8179 ---------------------------------------------------------------------- |
OLD | NEW |