Permalink
Browse files

new section about dynamic type checking

  • Loading branch information...
1 parent 6016209 commit 6a2a4ffbf9279a842eda122c1aa6dfd641253080 @gavinking gavinking committed Aug 11, 2013
View
26 en/modules/declarations.xml
@@ -1789,11 +1789,11 @@ shared class Branch<Element>(String name, Node<Element> left, Node<Element> righ
<programlisting>shared Integer add(Integer x, Integer y) => x + y;</programlisting>
<programlisting>shared void addEntry(Key->Item entry) => map.put(entry.key,entry.item);</programlisting>
-
+
<programlisting><![CDATA[shared Set<Element> singleton<Element>(Element element)
given Element satisfies Comparable<Element>
=> TreeSet { element };]]></programlisting>
-
+
</section>
<section id="returntypeinference">
@@ -2139,8 +2139,6 @@ case (hexadecimal) {
<synopsis>ValueHeader: (Type | "value") MemberName</synopsis>
- <para>If a reference is a parameter, it must not specify a persistent value.</para>
-
<comment><para>Note: syntactically a value declaration looks like a function
declaration with zero parameter lists. It is often helpful, in thinking about the
syntax and semantics of Ceylon, to take the perspective that a value is a function
@@ -2172,6 +2170,16 @@ case (hexadecimal) {
<programlisting>shared Integer[] evenDigits = [0,2,4,6,8];</programlisting>
+ <para>A reference may have a specifier which specifies its persistent value or, in the
+ case of a variable reference, its initial persistent value. The type of the specified
+ expression must be assignable to the type of the reference.</para>
+
+ <para>If the specified expression has no type, and occurs within a
+ <literal>dynamic</literal> block, then the specification is not type-checked
+ at compile time.</para>
+
+ <para>If a reference is a parameter, it must not specify a persistent value.</para>
+
<para>A reference declared directly inside the body of a class represents a persistent
value associated with every instance of the class, as defined by
<xref linkend="sequentialexecutionandclosure"/>. Repeated evaluation of the attribute
@@ -2181,10 +2189,6 @@ case (hexadecimal) {
<para>A block-local reference represents state associated with a frame, that is, with
a particular execution of the containing block of code, as defined in
<xref linkend="sequentialexecutionandclosure"/>.</para>
-
- <para>If a class declares or inherits a <literal>variable</literal> reference, it
- must (directly or indirectly) extend the class <literal>Basic</literal> defined in
- <literal>ceylon.language</literal>.</para>
<!--itemizedlist>
<listitem>
@@ -2210,7 +2214,11 @@ case (hexadecimal) {
value. Furthermore, a self-reference to an instance being initialized may be
assigned to the reference. If the reference is evaluated before it is initialized,
or before its value has been completely initialized, an exception is thrown.</para>
-
+
+ <para>If a class declares or inherits a <literal>variable</literal> reference, it
+ must (directly or indirectly) extend the class <literal>Basic</literal> defined in
+ <literal>ceylon.language</literal>.</para>
+
</section>
<section id="getterswithblocks">
View
28 en/modules/execution.xml
@@ -719,6 +719,34 @@ String result = middleObject.string;</programlisting>
</section>
+ <section id="dynamictypechecking">
+ <title>Dynamic type checking</title>
+
+ <para>Inside a <literal>dynamic</literal> block, a situation might occur that
+ requires dynamic type checking, as specified in <xref linkend="dynamicblocks"/>.
+ It is possible that:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>the value to which an expression with no type evaluates at
+ execution time is not an instance of the type required were the
+ expression occurs, or</para>
+ </listitem>
+ <listitem>
+ <para>a qualified or unqualified reference which does not refer to
+ a statically typed declaration does not resolve to any declaration
+ at all.</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>Whenever such a condition is encountered at runtime, an
+ <literal>AssertionException</literal> is immediately thrown.</para>
+
+ <comment><para>Note: in Ceylon 1.0, dynamic type checking is only supported
+ on JavaScript virtual machines.</para></comment>
+
+ </section>
+
</section>
<section id="evaluationinvocationandassignment">
View
58 en/modules/statementblocks.xml
@@ -971,6 +971,10 @@ Integer f(Integer n) => n+package.n;</programlisting>
<synopsis>Return: "return" Expression?</synopsis>
+ <para>If the specified expression has no type, and occurs within a
+ <literal>dynamic</literal> block, then directive is not type-checked at compile
+ time.</para>
+
<para>The <literal>break</literal> directive must sequentially occur in the body
of a loop.</para>
@@ -989,6 +993,10 @@ Integer f(Integer n) => n+package.n;</programlisting>
<synopsis>Throw: "throw" Expression?</synopsis>
+ <para>If the specified expression has no type, and occurs within a
+ <literal>dynamic</literal> block, then directive is not type-checked at compile
+ time.</para>
+
</section>
<section id="specificationstatements">
@@ -1012,6 +1020,10 @@ Integer f(Integer n) => n+package.n;</programlisting>
<para>The type of the specified expression must be assignable to the type of
the reference, or to the callable type of the function.</para>
+ <para>If the specified expression has no type, and occurs within a
+ <literal>dynamic</literal> block, then the specification is not type-checked
+ at compile time.</para>
+
<programlisting>String greeting;
if (exists name) {
greeting = "hello ``name``";
@@ -2125,12 +2137,46 @@ else "total must be less than ``bound``";</programlisting>
<synopsis>Dynamic: "dynamic" Block</synopsis>
- <para>Inside a <literal>dynamic</literal> block, a value reference
- or qualified or unqualified reference occurring in an expression that
- does not resolve to any statically typed program element is assumed
- to be a reference to something defined in dynamically typed native
- code. Then the qualified or unqualified reference is not assigned a
- type, but does not result in a compile-time error.</para>
+ <para>Inside a <literal>dynamic</literal> block an expression may have
+ no type, as specified in <xref linkend="expressions"/>.</para>
+
+ <para>An expression with no type:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>may be specified or assigned to a typed value,</para>
+ </listitem>
+ <listitem>
+ <para>may be passed as the argument of a typed parameter in an
+ invocation expression,</para>
+ </listitem>
+ <listitem>
+ <para>may be the invoked expression of an invocation,</para>
+ </listitem>
+ <listitem>
+ <para>may be returned by a typed function or getter, or
+ thrown as an exception,</para>
+ </listitem>
+ <listitem>
+ <para>may be the operand of an operator expression, or</para>
+ </listitem>
+ <listitem>
+ <para>may be the subject of a control structure condition,
+ <literal>switch</literal>, or <literal>for</literal> iterator.</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>Furthermore:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>a qualified or unqualified reference may not refer to a
+ statically typed declaration.</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>These situations result in <emphasis>dynamic type checking</emphasis>,
+ as defined in <xref linkend="dynamictypechecking"/>.</para>
</section>
View
2 support/docbook-xsl/common/en.xml
@@ -412,7 +412,7 @@
<l:template name="answer" text="A:&#160;%n"/>
<l:template name="appendix" text="Appendix&#160;%n"/>
<l:template name="bridgehead" text="Section&#160;%n"/>
- <l:template name="chapter" text="Chapter&#160;%n"/>
+ <l:template name="chapter" text="&#167;&#160;%n"/>
<l:template name="equation" text="Equation&#160;%n"/>
<l:template name="example" text="Example&#160;%n"/>
<l:template name="figure" text="Figure&#160;%n"/>
View
3 support/docbook-xsl/fo/xref.xsl
@@ -254,12 +254,13 @@
<xsl:template match="dedication|preface|chapter|appendix" mode="xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
-
+ <fo:inline text-decoration="underline" color="blue">
<xsl:apply-templates select="." mode="object.xref.markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
</xsl:apply-templates>
+ </fo:inline>
</xsl:template>
<xsl:template match="bibliography" mode="xref-to">

0 comments on commit 6a2a4ff

Please sign in to comment.