OLD | NEW |
---|---|
1 \documentclass{article} | 1 \documentclass{article} |
2 \usepackage{epsfig} | 2 \usepackage{epsfig} |
3 \usepackage{dart} | 3 \usepackage{dart} |
4 \usepackage{bnf} | 4 \usepackage{bnf} |
5 \usepackage{hyperref} | 5 \usepackage{hyperref} |
6 \newcommand{\code}[1]{{\sf #1}} | 6 \newcommand{\code}[1]{{\sf #1}} |
7 \title{Dart Programming Language Specification \\ | 7 \title{Dart Programming Language Specification \\ |
8 {\large Draft Version 0.71}} | 8 {\large Draft Version 0.71}} |
9 \author{The Dart Team} | 9 \author{The Dart Team} |
10 \begin{document} | 10 \begin{document} |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
808 | 808 |
809 We say that a variable $v$ is {\em potentially mutated} in some scope $s$ if $v$ is not final or constant and an assignment to $v$ occurs in $s$. | 809 We say that a variable $v$ is {\em potentially mutated} in some scope $s$ if $v$ is not final or constant and an assignment to $v$ occurs in $s$. |
810 | 810 |
811 If a variable declaration does not explicitly specify a type, the type of the de clared variable(s) is \DYNAMIC{}, the unknown type (\ref{typeDynamic}). | 811 If a variable declaration does not explicitly specify a type, the type of the de clared variable(s) is \DYNAMIC{}, the unknown type (\ref{typeDynamic}). |
812 | 812 |
813 Static and instance variable declarations always induce implicit getters and set ters. | 813 Static and instance variable declarations always induce implicit getters and set ters. |
814 The scope into which the implicit getters and setters are introduced depends on the kind of variable declaration involved. | 814 The scope into which the implicit getters and setters are introduced depends on the kind of variable declaration involved. |
815 | 815 |
816 A library variable introduces a getter and a setter into the top level scope of the enclosing library. A static class variable introduces a static getter and a static setter into the immediately enclosing class. An instance variable introdu ces an instance getter and an instance setter into the immediately enclosing cla ss. | 816 A library variable introduces a getter and a setter into the top level scope of the enclosing library. A static class variable introduces a static getter and a static setter into the immediately enclosing class. An instance variable introdu ces an instance getter and an instance setter into the immediately enclosing cla ss. |
817 | 817 |
818 Local variables are added to the innermost enclosing scope. They do not induce getters and setters. A local variable may only be referenced at a source code l ocation that is after its initializer, if any, is complete, or a a compile-time error occurs. | 818 Local variables are added to the innermost enclosing scope. They do not induce getters and setters. A local variable may only be referenced at a source code l ocation that is after its initializer, if any, is complete, or a compile-time er ror occurs. The error may be reported either at the point where the premature r eference occurs, or at the variable declaration. |
819 | |
820 \rationale { | |
821 We allow the error to be reported at the declaration to allow implementations to avoid an extra processing phase. | |
hausner
2013/10/18 23:09:23
True. But it is more important that the error is a
| |
822 } | |
819 | 823 |
820 \commentary{ | 824 \commentary{ |
821 The example below illustrates the expected behavior. A variable $x$ is declared at the library level, and another $x$ is declared inside the function $f$. | 825 The example below illustrates the expected behavior. A variable $x$ is declared at the library level, and another $x$ is declared inside the function $f$. |
822 } | 826 } |
823 | 827 |
824 \begin{dartCode} | 828 \begin{dartCode} |
825 \VAR{} x = 0; | 829 \VAR{} x = 0; |
826 | 830 |
827 f(y) \{ | 831 f(y) \{ |
828 \VAR{} z = x; // compile-time error | 832 \VAR{} z = x; // compile-time error |
829 if (y) \{ | 833 if (y) \{ |
830 x = x + 1; // two compile time errors | 834 x = x + 1; // two compile time errors |
831 print(x); // compile time error | 835 print(x); // compile time error |
832 \} | 836 \} |
833 \VAR{} x = x++; // compile time error | 837 \VAR{} x = x++; // compile time error |
834 print(x); | 838 print(x); |
835 \} | 839 \} |
836 \end{dartCode} | 840 \end{dartCode} |
837 | 841 |
838 \commentary{ | 842 \commentary{ |
839 The declaration inside $f$ hides the enclosing one. So all references to $x$ in side $f$ refer to the inner declaration of $x$. However, many of these reference s are illegal, because they appear before the declaration. The assignment to $z$ is one such case. The assignment to $x$ in the \IF{} statement suffers from mul tiple problems. The right hand side reads $x$ before its declaration, and the le ft hand side assigns to $x$ before its declaration. Each of these are, independe ntly, compile time errors. The print statement inside the \IF{} is also illegal . | 843 The declaration inside $f$ hides the enclosing one. So all references to $x$ in side $f$ refer to the inner declaration of $x$. However, many of these reference s are illegal, because they appear before the declaration. The assignment to $z$ is one such case. The assignment to $x$ in the \IF{} statement suffers from mul tiple problems. The right hand side reads $x$ before its declaration, and the le ft hand side assigns to $x$ before its declaration. Each of these are, independe ntly, compile time errors. The print statement inside the \IF{} is also illegal . |
840 | 844 |
841 The inner declaration of $x$ is itself erroneous because its right hand side att empts to read $x$ before the declaration has terminated. The left hand side is not, technically, a reference or an assignment but a declaration and so is legal . The last print statement is perfectly legal as well. | 845 The inner declaration of $x$ is itself erroneous because its right hand side att empts to read $x$ before the declaration has terminated. The left hand side is not, technically, a reference or an assignment but a declaration and so is legal . The last print statement is perfectly legal as well. |
842 } | 846 } |
843 | 847 |
844 \commentary { | 848 \commentary { |
845 As another example \code{var x = 3, y = x;} is legal, because \code{x} is refer enced after its initializer. | 849 As another example \code{\VAR{} x = 3, y = x;} is legal, because \code{x} is re ferenced after its initializer. |
846 | 850 |
851 A particularly perverse example involves a local variable name shadowing a type. This is possible because Dart has a single namespace for types, functions and v ariables. | |
847 } | 852 } |
848 | 853 |
854 \begin{dartCode} | |
855 \CLASS{} C \{\} | |
856 perverse() \{ | |
857 \VAR{} v = \NEW{} C(); // compile-time error | |
858 \C aC; // compile-time error | |
859 \VAR{} C = 10; | |
860 \} | |
861 | |
862 \commentary { | |
863 Inside \cd{perverse()} \cd{C} denotes a local variable. The type \cd{C} is hidd en by the variable of the same name. The attempt to instantiate \cd{C} causes a compile-time error because it references a local variable prior to its declarati on. Similarly, for the declaration of \cd{aC} (even though it is only a type ann otation). | |
864 } | |
865 | |
866 \end{dartCode} | |
867 | |
849 % the grammar does not support local getters and setters. The local var discussi on does not seem to mention getters and setters based semantics. It simply discu sses the creation of the variable, not its access. Access is either assignment o r identifiers. Identifiers ignore the getter story. | 868 % the grammar does not support local getters and setters. The local var discussi on does not seem to mention getters and setters based semantics. It simply discu sses the creation of the variable, not its access. Access is either assignment o r identifiers. Identifiers ignore the getter story. |
850 | 869 |
851 The following rules apply to all static and instance variables. | 870 The following rules apply to all static and instance variables. |
852 | 871 |
853 A variable declaration of one of the forms \code{$T$ $v$;}, \code{$T$ $v$ = $ e$;} , \code{\CONST{} $T$ $v$ = $e$;}, \code{\FINAL{} $T$ $v$;} or \code{\FINA L{} $T$ $v$ = $e$;} always induces an implicit getter function (\ref{getters}) with signature | 872 A variable declaration of one of the forms \code{$T$ $v$;}, \code{$T$ $v$ = $ e$;} , \code{\CONST{} $T$ $v$ = $e$;}, \code{\FINAL{} $T$ $v$;} or \code{\FINA L{} $T$ $v$ = $e$;} always induces an implicit getter function (\ref{getters}) with signature |
854 | 873 |
855 $T$ \GET{} $v$ | 874 $T$ \GET{} $v$ |
856 | 875 |
857 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariable Getters}). | 876 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariable Getters}). |
858 | 877 |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1461 %\VOID{} \SET{} $v=(T$ $x)$ | 1480 %\VOID{} \SET{} $v=(T$ $x)$ |
1462 | 1481 |
1463 %whose execution sets the value of $v$ to the incoming argument $x$. | 1482 %whose execution sets the value of $v$ to the incoming argument $x$. |
1464 | 1483 |
1465 %A non-final instance variable declaration of the form \code{\VAR{} $v$;} or th e form \code{\VAR{} $v$ = $e$;} always induces an implicit setter function wi th signature | 1484 %A non-final instance variable declaration of the form \code{\VAR{} $v$;} or th e form \code{\VAR{} $v$ = $e$;} always induces an implicit setter function wi th signature |
1466 | 1485 |
1467 %\SET{} $v=(x)$ | 1486 %\SET{} $v=(x)$ |
1468 | 1487 |
1469 %whose execution sets the value of $v$ to the incoming argument $x$. | 1488 %whose execution sets the value of $v$ to the incoming argument $x$. |
1470 | 1489 |
1471 % It is a compile-time error/warning if a a class $C$ declares a final instance variable $v$ and $C$ inherits a setter $v=$. | 1490 % It is a compile-time error/warning if a class $C$ declares a final instance va riable $v$ and $C$ inherits a setter $v=$. |
1472 | 1491 |
1473 | 1492 |
1474 \subsection{Constructors} | 1493 \subsection{Constructors} |
1475 \label{constructors} | 1494 \label{constructors} |
1476 | 1495 |
1477 A {\em constructor} is a special function that is used in instance creation expr essions (\ref{instanceCreation}) to produce objects. Constructors may be generat ive (\ref{generativeConstructors}) or they may be factories (\ref{factories}). | 1496 A {\em constructor} is a special function that is used in instance creation expr essions (\ref{instanceCreation}) to produce objects. Constructors may be generat ive (\ref{generativeConstructors}) or they may be factories (\ref{factories}). |
1478 | 1497 |
1479 A {\em constructor name} always begins with the name of its immediately enclosin g class, and may optionally be followed by a dot and an identifier $id$. It is a compile-time error if $id$ is the name of a member declared in the immediately enclosing class. It is a compile-time error if the name of a constructor is no t a constructor name. | 1498 A {\em constructor name} always begins with the name of its immediately enclosin g class, and may optionally be followed by a dot and an identifier $id$. It is a compile-time error if $id$ is the name of a member declared in the immediately enclosing class. It is a compile-time error if the name of a constructor is no t a constructor name. |
1480 | 1499 |
1481 | 1500 |
(...skipping 4649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6131 \item The names of compile time constant variables never use lower case letters. If they consist of multiple words, those words are separated by underscores. Ex amples: PI, I\_AM\_A\_CONSTANT. | 6150 \item The names of compile time constant variables never use lower case letters. If they consist of multiple words, those words are separated by underscores. Ex amples: PI, I\_AM\_A\_CONSTANT. |
6132 \item The names of functions (including getters, setters, methods and local or l ibrary functions) and non-constant variables begin with a lowercase letter. If t he name consists of multiple words, each word (except the first) begins with an uppercase letter. No other uppercase letters are used. Examples: camlCase, dar t4TheWorld | 6151 \item The names of functions (including getters, setters, methods and local or l ibrary functions) and non-constant variables begin with a lowercase letter. If t he name consists of multiple words, each word (except the first) begins with an uppercase letter. No other uppercase letters are used. Examples: camlCase, dar t4TheWorld |
6133 \item The names of types (including classes and type aliases) begin with an uppe r case letter. If the name consists of multiple words, each word begins with an uppercase letter. No other uppercase letters are used. Examples: CamlCase, D art4TheWorld. | 6152 \item The names of types (including classes and type aliases) begin with an uppe r case letter. If the name consists of multiple words, each word begins with an uppercase letter. No other uppercase letters are used. Examples: CamlCase, D art4TheWorld. |
6134 \item The names of type variables are short (preferably single letter). Examples : T, S, K, V , E. | 6153 \item The names of type variables are short (preferably single letter). Examples : T, S, K, V , E. |
6135 \item The names of libraries or library prefixes never use upper case letters. I f they consist of multiple words, those words are separated by underscores. Exam ple: my\_favorite\_library. | 6154 \item The names of libraries or library prefixes never use upper case letters. I f they consist of multiple words, those words are separated by underscores. Exam ple: my\_favorite\_library. |
6136 \end{itemize} | 6155 \end{itemize} |
6137 } | 6156 } |
6138 | 6157 |
6139 | 6158 |
6140 \end{document} | 6159 \end{document} |
OLD | NEW |