CSc 372 - Comparative Programming Languages
1 : Introduction

Christian Collberg

Department of Computer Science

University of Arizona

1 Why learn programming languages?

2 Functional Programming (FP)

3 Logic Programming (FP)

4 String Processing


A Preview


5 3 Languages -- A Preview

You Are Not Supposed to Understand This Lecture!!!








yet...



6 Hello World (Prolog)

The file hello.pl
\begin{lstlisting}[language=Prolog]
hello :-
write('Hello World!'),nl.
\end{lstlisting}

Loading and running
\begin{lstlisting}[language=csh]
> gprolog
\vert ?- ['hello.pl'].
\vert ?- hello.
Hello World!
\par
yes
\vert ?-
\end{lstlisting}

7 Hello World (Haskell)

The file hello.gh
\begin{lstlisting}[language=Haskell]
main = putStr (''Hello World'')
\end{lstlisting}

Loading and running
\begin{lstlisting}[language=csh]
> hugs
\par
Main> :load hello.gh
Main> main
Hello World
Main>
\end{lstlisting}

8 Hello World (Icon)

The file hello.icn
\begin{lstlisting}[language=Pascal]
procedure main()
write(''Hello World!'')
end
\end{lstlisting}

Compiling and running
\begin{lstlisting}[language=csh]
> icont hello.icn
> hello
Hello World!
\end{lstlisting}

9 Hello World (Java)


\begin{lstlisting}[language=Java]
class Hello {
String message;
\par
Hello(Stri...
...lo myHello = new Hello(''Hello World'');
myHello.sayit();
}
}
\end{lstlisting}

10 Repeating Hello World (Prolog)

The file hello.pl
\begin{lstlisting}[language=Prolog]
hello2(0).
hello2(N) :-
N>0,
write('Hello World!'),nl,
N1 is N - 1,
hello2(N1).
\end{lstlisting}

Loading and running
\begin{lstlisting}[language=Prolog]
> gprolog
\vert ?- ['hello.pl'].
\vert ?- hello2(2).
Hello World!
Hello World!
\end{lstlisting}

11 Repeating Hello World (Haskell)

The file hello.gh
\begin{lstlisting}[language=Haskell]
main n = putStr (unlines (take n (repeat ''Hello World!'')))
\end{lstlisting}

Loading and running
\begin{lstlisting}[language=Haskell]
> hugs
\par
Main> :load hello.gh
Main> main 2
Hello World!
Hello World!
\end{lstlisting}

12 Repeating Hello World (Icon)

The file hello.icn
\begin{lstlisting}[language=Pascal]
procedure hello(n)
every i:= 1 to n do
write(''Hello World!'')
end
\par
procedure main()
hello(2)
end
\end{lstlisting}

Compiling and running
\begin{lstlisting}[language=csh]
> icont hello.icn
> hello
Hello World!
Hello World!
\end{lstlisting}

13 3 Languages -- A Preview

Remember...



You Are Not Supposed to Understand This Lecture!!!



yet...



...but you will need to know it all for the final!


14 Readings and References

15 Homework

16 Summary



Christian S. Collberg
2005-08-22