diff options
author | Martin Odersky <odersky@gmail.com> | 2004-03-15 14:01:05 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2004-03-15 14:01:05 +0000 |
commit | 435fe5da695f35581f03b5a739d2ed5e8f58842c (patch) | |
tree | 0ffa8e7ebc0ea2062dbaac459e7f26c7ace00936 /doc/reference/ExamplesPart.tex | |
parent | 0bdcdc7c9f714575f5d3f4882108dc377f9819dd (diff) | |
download | scala-435fe5da695f35581f03b5a739d2ed5e8f58842c.tar.gz scala-435fe5da695f35581f03b5a739d2ed5e8f58842c.tar.bz2 scala-435fe5da695f35581f03b5a739d2ed5e8f58842c.zip |
*** empty log message ***
Diffstat (limited to 'doc/reference/ExamplesPart.tex')
-rw-r--r-- | doc/reference/ExamplesPart.tex | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/doc/reference/ExamplesPart.tex b/doc/reference/ExamplesPart.tex index 30ea725cfd..483a56f74b 100644 --- a/doc/reference/ExamplesPart.tex +++ b/doc/reference/ExamplesPart.tex @@ -75,10 +75,10 @@ functional style. def sort(xs: List[int]): List[int] = if (xs.length <= 1) xs else { - val pivot = a(a.length / 2); - sort(a.filter(x => x < pivot)) - ::: a.filter(x => x == pivot) - ::: sort(a.filter(x => x > pivot)) + val pivot = xs(xs.length / 2); + sort(xs.filter(x => x < pivot)) + ::: xs.filter(x => x == pivot) + ::: sort(xs.filter(x => x > pivot)) } \end{lstlisting} @@ -1605,7 +1605,7 @@ a more streamlined alternative definition of the empty set: \begin{lstlisting} object EmptySet extends IntSet { def contains(x: int): boolean = false; - def incl(x: int): IntSet = new NonEmptySet(x, empty, empty); + def incl(x: int): IntSet = new NonEmptySet(x, EmptySet, EmptySet); } \end{lstlisting} The syntax of an object definition follows the syntax of a class @@ -2761,7 +2761,7 @@ A list containing the elements \code{x}$_1$, \ldots, \code{x}$_n$ is written \begin{lstlisting} val fruit = List("apples", "oranges", "pears"); val nums = List(1, 2, 3, 4); -val diag3 = List(List(1, 0, 0), List(0, 1, 0)); +val diag3 = List(List(1, 0, 0), List(0, 1, 0), List(0, 0, 1)); val empty = List(); \end{lstlisting} Lists are similar to arrays in languages such as C or Java, but there @@ -2779,7 +2779,7 @@ list all have the same type. The type of a list with elements of type \begin{lstlisting} val fruit: List[String] = List("apples", "oranges", "pears"); val nums : List[int] = List(1, 2, 3, 4); -val diag3: List[List[int]] = List(List(1, 0, 0), List(0, 1, 0)); +val diag3: List[List[int]] = List(List(1, 0, 0), List(0, 1, 0), List(0, 0, 1)); val empty: List[int] = List(); \end{lstlisting} |