summaryrefslogtreecommitdiff
path: root/sources/examples/fors.scala
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-07-06 16:05:02 +0000
committerburaq <buraq@epfl.ch>2004-07-06 16:05:02 +0000
commit50b1b01c8e67008d6d51d06154b68cd2c8d1583f (patch)
tree2381c5216c1dbbc1878da7d517bea1fd98bb105e /sources/examples/fors.scala
parent40db5ce7419683e7d336dbd3f3fe793bf7ae4d65 (diff)
downloadscala-50b1b01c8e67008d6d51d06154b68cd2c8d1583f.tar.gz
scala-50b1b01c8e67008d6d51d06154b68cd2c8d1583f.tar.bz2
scala-50b1b01c8e67008d6d51d06154b68cd2c8d1583f.zip
new elem
Diffstat (limited to 'sources/examples/fors.scala')
-rw-r--r--sources/examples/fors.scala44
1 files changed, 23 insertions, 21 deletions
diff --git a/sources/examples/fors.scala b/sources/examples/fors.scala
index 9ae9f17cf1..dc7b8094b2 100644
--- a/sources/examples/fors.scala
+++ b/sources/examples/fors.scala
@@ -5,6 +5,8 @@ import scala.xml._;
object fors {
+ val e = Node.NoAttributes ;
+
class Person(_name: String, _age: Int) {
val name = _name;
val age = _age;
@@ -40,44 +42,44 @@ object fors {
type Lst = List[Any];
val books = List(
- Elem("book",
- Elem("title",
+ Elem("", "book", e,
+ Elem("", "title", e,
Text("Structure and Interpretation of Computer Programs")),
- Elem("author",
+ Elem("", "author", e,
Text("Abelson, Harald")),
- Elem("author",
+ Elem("", "author", e,
Text("Sussman, Gerald J."))),
- Elem("book",
- Elem("title",
+ Elem("", "book", e,
+ Elem("", "title", e,
Text("Principles of Compiler Design")),
- Elem("author",
+ Elem("", "author", e,
Text("Aho, Alfred")),
- Elem("author",
+ Elem("", "author", e,
Text("Ullman, Jeffrey"))),
- Elem("book",
- Elem("title",
+ Elem("", "book", e,
+ Elem("", "title", e,
Text("Programming in Modula-2")),
- Elem("author",
+ Elem("", "author", e,
Text("Wirth, Niklaus")))
);
def findAuthor(books: Lst) =
- for (val Elem("book",book @ _*) <- books;
- val Elem("title",Text( title )) <- book;
+ for (val Elem(_, "book",_,book @ _*) <- books;
+ val Elem(_, "title",_,Text( title )) <- book;
(title indexOf "Program") >= 0;
- val Elem("author",Text( author )) <- book) yield author;
+ val Elem(_, "author",_,Text( author )) <- book) yield author;
- for (val Elem("book", b @ _*) <- books;
- val Elem("author", Text( author )) <- b;
+ for (val Elem(_, "book", _, b @ _*) <- books;
+ val Elem(_, "author", _, Text( author )) <- b;
author startsWith "Ullman";
- val Elem("title",Text( title )) <- b) yield title;
+ val Elem(_, "title", _,Text( title )) <- b) yield title;
removeDuplicates(
- for (val Elem("book", b1 @ _* ) <- books;
- val Elem("book", b2 @ _*) <- books;
+ for (val Elem(_, "book", _, b1 @ _* ) <- books;
+ val Elem(_, "book", _, b2 @ _*) <- books;
b1 != b2;
- val Elem("author",Text( a1 )) <- b1;
- val Elem("author",Text( a2 )) <- b2;
+ val Elem(_, "author",_, Text( a1 )) <- b1;
+ val Elem(_, "author",_, Text( a2 )) <- b2;
a1 == a2) yield Pair(a1, a2));
def removeDuplicates[a](xs: List[a]): List[a] =