Browse Source

Improved scala syntax

Martin Thoma 11 years ago
parent
commit
0bae80d4b5

BIN
documents/Programmierparadigmen/Programmierparadigmen.pdf


+ 2 - 0
documents/Programmierparadigmen/Prolog.tex

@@ -54,6 +54,8 @@ Wer trinkt Wasser? Wem gehört das Zebra?
 
 
 \inputminted[linenos, numbersep=5pt, tabsize=4, frame=lines, label=zebraraetsel.pro]{prolog}{scripts/prolog/zebraraetsel.pro}
 \inputminted[linenos, numbersep=5pt, tabsize=4, frame=lines, label=zebraraetsel.pro]{prolog}{scripts/prolog/zebraraetsel.pro}
 
 
+TODO
+
 \section{Weitere Informationen}
 \section{Weitere Informationen}
 \begin{itemize}
 \begin{itemize}
     \item \href{http://wiki.ubuntuusers.de/Prolog}{\path{wiki.ubuntuusers.de/Prolog}}: Hinweise zur Installation von Prolog unter Ubuntu
     \item \href{http://wiki.ubuntuusers.de/Prolog}{\path{wiki.ubuntuusers.de/Prolog}}: Hinweise zur Installation von Prolog unter Ubuntu

+ 9 - 10
documents/Programmierparadigmen/Scala.tex

@@ -46,30 +46,29 @@ einige Unterschiede.
     \item Java hat Interfaces, Scala hat traits.
     \item Java hat Interfaces, Scala hat traits.
     \item Java hat primitive Typen, Scala ausschließlich Objekte.
     \item Java hat primitive Typen, Scala ausschließlich Objekte.
     \item Scala benötigt kein \texttt{;} am Ende von Anweisungen.
     \item Scala benötigt kein \texttt{;} am Ende von Anweisungen.
+    \item Scala ist kompakter.
 \end{itemize}
 \end{itemize}
 }
 }
 
 
-Weitere Informationen hat Graham Lea unter \url{http://grahamhackingscala.blogspot.de/2009/11/scala-under-hood-of-hello-world.html} zur Verfügung gestellt.
+Weitere Informationen hat Graham Lea unter \url{http://tinyurl.com/scala-hello-world} zur Verfügung gestellt.
 
 
 \section{Syntax}
 \section{Syntax}
 In Scala gibt es sog. \textit{values}, die durch das Schlüsselwort \texttt{val}\xindex{val}
 In Scala gibt es sog. \textit{values}, die durch das Schlüsselwort \texttt{val}\xindex{val}
 angezeigt werden. Diese sind Konstanten. Die Syntax ist der UML-Syntax ähnlich.
 angezeigt werden. Diese sind Konstanten. Die Syntax ist der UML-Syntax ähnlich.
 
 
-\begin{verbatim}
-val name: type = value
-\end{verbatim}
+\inputminted[numbersep=5pt, tabsize=4]{scala}{scripts/scala/val-syntax.scala}
 
 
 Variablen werden durch das Schlüsselwort \texttt{var}\xindex{var} angezeigt:
 Variablen werden durch das Schlüsselwort \texttt{var}\xindex{var} angezeigt:
 
 
-\begin{verbatim}
-var name: type = value
-\end{verbatim}
+\inputminted[numbersep=5pt, tabsize=4]{scala}{scripts/scala/var-syntax.scala}
 
 
 Methoden werden mit dem Schlüsselwort \texttt{def}\xindex{def} erzeugt:
 Methoden werden mit dem Schlüsselwort \texttt{def}\xindex{def} erzeugt:
 
 
-\begin{verbatim}
-def name(parameter: String): Unit = { code body... }
-\end{verbatim}
+\inputminted[numbersep=5pt, tabsize=4]{scala}{scripts/scala/method-syntax.scala}
+
+Klassen werden wie folgt erstellt:
+\inputminted[numbersep=5pt, tabsize=4]{scala}{scripts/scala/simple-class-example.scala}
+
 
 
 \section{Beispiele}
 \section{Beispiele}
 
 

+ 41 - 0
documents/Programmierparadigmen/scripts/prolog/books.pl

@@ -0,0 +1,41 @@
+% Those are the books:
+book(a).
+book(b).
+book(c).
+book(d).
+book(e).
+book(f).
+
+% This is how 'touching' works:
+touching(X,Y):- touching(Y,X). % touching is symmetric
+touching(p1,p2).
+touching(p2,p3).
+touching(p3,p4).
+touching(p3,p5).
+touching(p3,p6).
+touching(p4,p5).
+touching(p5,p6).
+
+% List all possible positions:
+position(a):- p1,p2,p3,p4,p5,p6.
+position(b):- p1,p2,p3,p4,p5,p6.
+position(c):- p1,p2,p3,p4,p5,p6.
+position(d):- p1,p2,p3,p4,p5,p6.
+position(e):- p1,p2,p3,p4,p5,p6.
+position(f):- p1,p2,p3,p4,p5,p6.
+
+% Every position has one book
+getBook(p1) :- a,b,c,d,e,f.
+getBook(p2) :- a,b,c,d,e,f.
+getBook(p3) :- a,b,c,d,e,f.
+getBook(p4) :- a,b,c,d,e,f.
+getBook(p5) :- a,b,c,d,e,f.
+getBook(p6) :- a,b,c,d,e,f.
+
+% Add your facts:
+not(touching(position(a),position(d))).
+position(e):- p5,p2.
+% C touches exactly two books: eventually something like aggregate_all(count, touching(e,X), Count):-2.
+position(c):- p2, p4,p6.
+touching(position(a),position(f)).
+touching(position(e),position(f)).

+ 1 - 0
documents/Programmierparadigmen/scripts/scala/method-syntax.scala

@@ -0,0 +1 @@
+def name(parameter: String): Unit = { code ... }

+ 6 - 0
documents/Programmierparadigmen/scripts/scala/simple-class-example.scala

@@ -0,0 +1,6 @@
+class Person (
+    val firstName: String,
+    var lastName: String,
+    age: Int) {
+    println("This is the constructur.")
+}

+ 0 - 0
documents/Programmierparadigmen/scripts/scala/test.scala


+ 1 - 0
documents/Programmierparadigmen/scripts/scala/val-syntax.scala

@@ -0,0 +1 @@
+val name: type = value

+ 1 - 0
documents/Programmierparadigmen/scripts/scala/var-syntax.scala

@@ -0,0 +1 @@
+var name: type = value