cse 341, s. tanimoto wrapup - 1 wrapup programming languages as systems for specifying computation...

11
CSE 341, S. Tanimoto 1 Wrapup Programming Languages as systems for specifying computation Comparing Lisp, Java and Perl The future

Upload: silas-hutchinson

Post on 17-Jan-2016

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 341, S. Tanimoto Wrapup - 1 Wrapup Programming Languages as systems for specifying computation Comparing Lisp, Java and Perl The future

CSE 341, S. Tanimoto Wrapup -

1

Wrapup

Programming Languages as systems

for specifying computation

Comparing Lisp, Java and Perl

The future

Page 2: CSE 341, S. Tanimoto Wrapup - 1 Wrapup Programming Languages as systems for specifying computation Comparing Lisp, Java and Perl The future

CSE 341, S. Tanimoto Wrapup -

2

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.

Page 3: CSE 341, S. Tanimoto Wrapup - 1 Wrapup Programming Languages as systems for specifying computation Comparing Lisp, Java and Perl The future

CSE 341, S. Tanimoto Wrapup -

3

Language Comparison

Lisp: uniform syntax, interpreted, mostly functional.

Java: typical syntax, compiled, mostly object-oriented.

Perl: permissive syntax, compiled, multi-paradigm, scripting.

Page 4: CSE 341, S. Tanimoto Wrapup - 1 Wrapup Programming Languages as systems for specifying computation Comparing Lisp, Java and Perl The future

CSE 341, S. Tanimoto Wrapup -

4

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, seehttp://www.ionet.net/~timtroyr/funhouse/beer.html

Page 5: CSE 341, S. Tanimoto Wrapup - 1 Wrapup Programming Languages as systems for specifying computation Comparing Lisp, Java and Perl The future

CSE 341, S. Tanimoto Wrapup -

5

BASICBeginners’ All purpose Symbolic Instruction Code

10 REM Basic version of 99 bottles of beer20 FOR X=99 TO 1 STEP -130 PRINT X;"Bottle(s) of beer on the wall,";X;"bottle(s) of beer"40 PRINT "Take one down and pass it around,"50 PRINT X-1;"bottle(s) of beer on the wall"60 NEXT

Page 6: CSE 341, S. Tanimoto Wrapup - 1 Wrapup Programming Languages as systems for specifying computation Comparing Lisp, Java and Perl The future

CSE 341, S. Tanimoto Wrapup -

6

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)

Page 7: CSE 341, S. Tanimoto Wrapup - 1 Wrapup Programming Languages as systems for specifying computation Comparing Lisp, Java and Perl The future

CSE 341, S. Tanimoto Wrapup -

7

Javapublic 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"; }}

Page 8: CSE 341, S. Tanimoto Wrapup - 1 Wrapup Programming Languages as systems for specifying computation Comparing Lisp, Java and Perl The future

CSE 341, S. Tanimoto Wrapup -

8

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"; }

Page 9: CSE 341, S. Tanimoto Wrapup - 1 Wrapup Programming Languages as systems for specifying computation Comparing Lisp, Java and Perl The future

CSE 341, S. Tanimoto Wrapup -

9

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 - ').

Page 10: CSE 341, S. Tanimoto Wrapup - 1 Wrapup Programming Languages as systems for specifying computation Comparing Lisp, Java and Perl The future

CSE 341, S. Tanimoto Wrapup -

10

The FutureUbiquitous 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.

Page 11: CSE 341, S. Tanimoto Wrapup - 1 Wrapup Programming Languages as systems for specifying computation Comparing Lisp, Java and Perl The future

CSE 341, S. Tanimoto Wrapup -

11

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.