Wrapup - CSE Home
Download
Report
Transcript Wrapup - CSE Home
Wrapup
Programming Languages as systems
for specifying computation
Comparing Lisp, Java and Perl
The future
CSE 341, S. Tanimoto
Wrapup -
1
Programming
1. Specify computation
2. Using a finite-length expression, specify arbitrarily
long computations using looping or recursion.
3. Key criterion is that the program description be
effective, so that a computer really can
interpret/compile and execute it.
CSE 341, S. Tanimoto
Wrapup -
2
Language Comparison
Lisp: uniform syntax, interpreted, mostly
functional.
Java: typical syntax, compiled, mostly
object-oriented.
Perl: permissive syntax, compiled, multiparadigm, scripting.
CSE 341, S. Tanimoto
Wrapup -
3
99 Bottles of Beer
The next step up from
“Hello World”
Print the words to the song,
“99 Bottles of Beer on the Wall.”
For solutions in over 200 languages, see
http://www.ionet.net/~timtroyr/funhouse/beer.html
CSE 341, S. Tanimoto
Wrapup -
4
BASIC
Beginners’ All purpose Symbolic Instruction Code
10
20
30
40
50
60
REM Basic version of 99 bottles of beer
FOR X=99 TO 1 STEP -1
PRINT X;"Bottle(s) of beer on the wall,";X;"bottle(s) of beer"
PRINT "Take one down and pass it around,"
PRINT X-1;"bottle(s) of beer on the wall"
NEXT
CSE 341, S. Tanimoto
Wrapup -
5
Lisp
;;; Print the words to 99 Bottles of beer.
(defun b (n)
(format nil "~A bottle~A of beer"
n (if (= n 1) "" "s")) )
(defun bb (n)
(format t "~A on the wall, ~A.~%~A ~A.~%"
(b n)(b n)
"Take one down and pass it around, "
(b (1- n)) )
(if (> n 1) (bb (1- n))) )
(bb 99)
CSE 341, S. Tanimoto
Wrapup -
6
Java
public class Bottle {
public static void main(String Argv[]) {
for(int i=99; i>0; i--) {
String b = b(i);
System.out.println(b + " on the wall, "
+ b + ".\n"
+ "Take one down and pass it around, "
+ b(i-1) + " on the wall.");
}
}
static String b(int n) {
String s = "s"; if (n == 1) s = "";
return n + " bottle" + s + " of beer";
}
}
CSE 341, S. Tanimoto
Wrapup -
7
Perl
# Print words to '99 Bottles of Beer' -- S. Tanimoto
$w = " on the wall";
$t = "\nTake one down and pass it around, ";
for (reverse(1 .. 99)) {
print b($_),"$w, ",b($_),". ",$t,b($_-1),"$w.\n"; }
sub b() { ($n) = @_;
$p = ($n != 1) ? "s" : ""; "$n bottle$p of beer"; }
CSE 341, S. Tanimoto
Wrapup -
8
Prolog
bbw(1) :- write(' One bottle of beer on the wall').
bbw(N) :- write(N), bob, write(' on the wall').
bb(1) :- bbw(1), write(', one bottle of beer'), tod,
write(' No'), bob, write('.').
bb(N) :- bbw(N), write(', '), write(N), bob, tod,
M is N - 1, bbw(M), write('.\n'), bb(M).
bob :- write(' bottles of beer').
tod :- write('. Take one down; pass it around - ').
CSE 341, S. Tanimoto
Wrapup -
9
The Future
Ubiquitous computing, wireless Internet, embedded
systems
Computers will be everywhere!
Your toaster MAY be programmable.
What kind of programming system will it offer?
What will be the consequences of inability to program?
End-user programming languages and systems will play
a key role in letting ordinary people be in control of the
devices in their own homes.
CSE 341, S. Tanimoto
Wrapup -
10
Final Exam
Coverage includes topics from:
•Lisp quiz
•Java quiz +
•regular expressions (theory and Perl practice),
•syntax description using BNF and EBNF,
•logic programming (clauses, literals, unification, Prolog’s search
procedure)
•orthogonality, polymorphism, language paradigms
•data type -- strong vs weak typing, structural equivalence of types
vs name equivalence.
CSE 341, S. Tanimoto
Wrapup -
11