summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2004-06-03 12:33:10 +0000
committerMartin Odersky <odersky@gmail.com>2004-06-03 12:33:10 +0000
commit682856e0623ddc61442f644e4935ce449480a958 (patch)
treecff46c30cb93f91230cb24713013d3d80ecb1509 /doc
parentd94a30d34746ddbe4274c00231734e2bbc3e9ff5 (diff)
downloadscala-682856e0623ddc61442f644e4935ce449480a958.tar.gz
scala-682856e0623ddc61442f644e4935ce449480a958.tar.bz2
scala-682856e0623ddc61442f644e4935ce449480a958.zip
*** empty log message ***
Diffstat (limited to 'doc')
-rw-r--r--doc/reference/ExamplesPart.tex27
-rw-r--r--doc/reference/ReferencePart.tex25
2 files changed, 26 insertions, 26 deletions
diff --git a/doc/reference/ExamplesPart.tex b/doc/reference/ExamplesPart.tex
index 140544745d..a335b1d739 100644
--- a/doc/reference/ExamplesPart.tex
+++ b/doc/reference/ExamplesPart.tex
@@ -201,20 +201,19 @@ Of course, a compiler is free (if it is moderately smart, even expected)
to recognize the special case of calling the \code{+} method over
integer arguments and to generate efficient inline code for it.
-Control constructs such as \code{while} are also not primitive but are
-predefined functions in the standard Scala library. Here is the
-definition of \code{while} in Scala.
+For efficiency and better error diagnostics the \code{while} loop is a
+primitive construct in Scala. But in principle, it could have just as
+well been a predefined function. Here is a possible implementation of it:
\begin{lstlisting}
-def while (def p: boolean) (def s: unit): unit =
- if (p) { s ; while(p)(s) }
+def While (def p: boolean) (def s: unit): unit =
+ if (p) { s ; While(p)(s) }
\end{lstlisting}
-The \code{while} function takes as first parameter a test function,
+The \code{While} function takes as first parameter a test function,
which takes no parameters and yields a boolean value. As second
parameter it takes a command function which also takes no parameters
-and yields a trivial result. \code{while} invokes the command function
-as long as the test function yields true. Again, compilers are free to
-pick specialized implementations of \code{while} that have the same
-behavior as the invocation of the function given above.
+and yields a trivial result. \code{While} invokes the command function
+as long as the test function yields true.
+
\chapter{Programming with Actors and Messages}
\label{chap:example-auction}
@@ -260,7 +259,7 @@ are defined in Figure~\ref{fig:simple-auction-msgs}.
class Auction(seller: Actor, minBid: int, closing: Date) extends Actor {
val timeToShutdown = 36000000; // msec
val bidIncrement = 10;
- def run() = {
+ override def run() = {
var maxBid = minBid - bidIncrement;
var maxBidder: Actor = _;
var running = true;
@@ -6546,7 +6545,7 @@ messages. A {\em message} in this context is an arbitrary object.
There is a special message \code{TIMEOUT} which is used to signal a
time-out.
\begin{lstlisting}
-case class TIMEOUT;
+case object TIMEOUT;
\end{lstlisting}
Mailboxes implement the following signature.
\begin{lstlisting}
@@ -6737,7 +6736,7 @@ class Auction(seller: Process, minBid: int, closing: Date)
val delta = 10 // bid increment
\end{lstlisting}
\begin{lstlisting}
- def run = {
+ override def run = {
var askedBid = minBid
var maxBidder: Process = null
while (true) {
@@ -6850,7 +6849,7 @@ class Bidder (auction: Process, minBid: int, maxBid: int)
}
\end{lstlisting}
\begin{lstlisting}
- def run = {
+ override def run = {
getAuctionStatus
if (nextBid != Unknown) bid
}
diff --git a/doc/reference/ReferencePart.tex b/doc/reference/ReferencePart.tex
index 85902029f6..4c29bd1a74 100644
--- a/doc/reference/ReferencePart.tex
+++ b/doc/reference/ReferencePart.tex
@@ -762,12 +762,12 @@ transitive relation that satisfies the following conditions.
binding of $x$ in $T$ subsuming it, then $T$ conforms to the
compound type ~\lstinline@$T_1$ with $\ldots$ with $T_n$ {$R\,$}@.
\item If
- $T'_i$ conforms to $T_i$ for $i = 1 \commadots n$ and $U$ conforms to $U'$
+ $T_i \equiv T'_i$ for $i = 1 \commadots n$ and $U$ conforms to $U'$
then the method type $(T_1 \commadots T_n) U$ conforms to
$(T'_1 \commadots T'_n) U'$.
\item If, assuming
$L'_1 \conforms a_1 \conforms U'_1 \commadots L'_n \conforms a_n \conforms U'_n$
-one has $L_i \conforms L'_i$ and $U'_i \conforms U_i$
+one has $L'_i \equiv L'_i$ and $U_i \equiv U'_i$
for $i = 1 \commadots n$, as well as $T \conforms T'$ then the polymorphic type
$[a_1 >: L_1 <: U_1 \commadots a_n >: L_n <: U_n] T$ conforms to the polymorphic type
$[a_1 >: L'_1 <: U'_1 \commadots a_n >: L'_n <: U'_n] T'$.
@@ -3776,7 +3776,9 @@ inserted by the compiler.
A view definition is a normal function definition with one value
parameter where the name of the defined function is \code{view}.
-\example
+\example
+The following defines an implicit coercion function from strings to lists of
+characters.
\begin{lstlisting}
def view(xs: String): List[char] =
@@ -3784,9 +3786,6 @@ def view(xs: String): List[char] =
else xs.charAt(0) :: xs.substring(1);
\end{lstlisting}
-This defines an implicit coercion function from strings to lists of
-characters.
-
\section{View Application}
View applications are inserted implicitly in two situations.
@@ -3814,7 +3813,7 @@ Searching a view which is applicable to an expression $e$ of type $T$
is a three-step process.
\begin{enumerate}
\item
-First, the set $\VV$ of available views is determined. $\VV$ is the
+First, the set $\AA$ of available views is determined. $\AA$ is the
smallest set such that:
\begin{enumerate}
\item
@@ -3849,7 +3848,7 @@ further view conversion of $e$ to the view's formal parameter type.
Likewise, a view's result type must conform to a given prototype
directly, no second view conversion is allowed.
\item
-It is an error is the set of applicable views $\BB$ is empty. For
+It is an error if the set of applicable views $\BB$ is empty. For
non-empty $\BB$, the view method which is most specific
(\sref{sec:overloaded-refs}) in $\BB$ is selected. It is an error if
no most specific view exists, or if it is not unique.
@@ -3920,16 +3919,16 @@ Implicit view parameters of a method or class are then taken as
available view methods in its body.
\example Consider the following definition of a trait
-\code{Comparable} and a view from strings to that trait..
+\code{Comparable} and a view from strings to that trait.
\begin{lstlisting}
trait Comparable[a] {
- def less (x: a): boolean
+ def less(x: a): boolean
}
object StringsAreComparable {
def view(x: String): Comparable[String] = new Comparable[String] {
- def less (y: String) = x.compareTo(y) < 0
+ def less(y: String) = x.compareTo(y) < 0
}
}
\end{lstlisting}
@@ -4039,7 +4038,7 @@ allows the definition of conditional views.
list element type is also comparable.
\begin{lstlisting}
-def view[a <% Comparable[a]](x: List[a]): Comparable[List[a]] =
+def view[a <% Comparable[a]](xs: List[a]): Comparable[List[a]] =
new Comparable[List[a]] {
def less (ys: List[a]): boolean =
!ys.isEmpty
@@ -4057,6 +4056,7 @@ type parameters are translated to implicit \code{view} arguments. In
this case, the \code{view} method over lists would receive the
\code{view} method over list elements as implicit parameter.
+\comment{
This opens up the risk of infinite instantiations because view methods
are be passed to themselves as parameters. For instance, one might try
to define the following ``magic'' universal converter:
@@ -4086,6 +4086,7 @@ argument, either directly or indirectly. On the other hand,
contractive view methods may be passed to themselves as arguments. In the
examples above this case arises if a list of lists of strings is seen
as a \code{Comparable}.
+}
\chapter{Top-Level Definitions}
\label{sec:topdefs}