Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 330 Programming Languages 12 / 09 / 2008 Instructor: Michael Eckmann.

Similar presentations


Presentation on theme: "CS 330 Programming Languages 12 / 09 / 2008 Instructor: Michael Eckmann."— Presentation transcript:

1 CS 330 Programming Languages 12 / 09 / 2008 Instructor: Michael Eckmann

2 Michael Eckmann - Skidmore College - CS 330 - Fall 2008 Today’s Topics Questions / comments? Prolog Closing remarks

3 Michael Eckmann - Skidmore College - CS 330 - Fall 2008 Prolog Prolog implementations use backward chaining Backward chaining –begin with goal and attempt to find sequence that leads to set of facts in database When goal has more than one subgoal, Prolog uses depth-first search Depth-first search – find a complete proof for the first subgoal before working on others backtrackingFor a goal with multiple subgoals, if fail to show truth of one of subgoals, Prolog uses backtracking Backtracking –reconsider previous subgoal to possibly find a solution

4 Michael Eckmann - Skidmore College - CS 330 - Fall 2008 Prolog append([], List, List). append([Head | List_1], List_2, [Head | List_3])‏ :- append (List_1, List_2, List_3). Reminder: –Append can append 2 lists together to result in the third (we saw this last time.) How do we call it this way?

5 Michael Eckmann - Skidmore College - CS 330 - Fall 2008 Prolog append([], List, List). append([Head | List_1], List_2, [Head | List_3])‏ :- append (List_1, List_2, List_3). Reminder: –Append can append 2 lists together to result in the third (we saw this last time.) How do we call it this way? First and second parameter are literally lists, the third parameter is a variable. e.g. append([a],[b],L). would succeed and L=[a,b] –However, append, when called can also verify if first list and second list would result in the third list if they were appended together. Call it with all parameters being lists. e.g. append([a],[b],[a,b]). would succeed.

6 Michael Eckmann - Skidmore College - CS 330 - Fall 2008 Prolog append([], List, List). append([Head | List_1], List_2, [Head | List_3])‏ :- append (List_1, List_2, List_3). –Append, can also be called with the third parameter instantiated and the first two as variables. This would instantiate the first and second parameter by decomposing the third parameter. Call it with all parameters being lists. e.g. append(F,S,[a,b,c]). would generate: –F = a –S = [b,c] –Let's see this in action by rearranging the subgoals in last class's sentence parsing program.

7 Michael Eckmann - Skidmore College - CS 330 - Fall 2008 Prolog The way the sentence parsing program is written now is more efficient if the database of words is large. Why?

8 Michael Eckmann - Skidmore College - CS 330 - Fall 2008 Prolog Let's look at a family program (family3.pro). Let's look at a program to solve towers of hanoi (hanoi.pro).

9 Michael Eckmann - Skidmore College - CS 330 - Fall 2008 Prolog Open a terminal and type gedit & and then enter (for coding)‏ Bprolog bp and enter cl(myprog.pro) %compile and load a prolog program consult(myprog.pro) % use if want to trace the code trace % put bp in trace mode, need to consult first notrace % take bp out of trace mode halt % exits help % prints help ; % use to get next result Examples of consult, trace and ; which we didn't use last time w/ speed.pro

10 Michael Eckmann - Skidmore College - CS 330 - Fall 2004 Other topics Object oriented programming –What makes a language object oriented? What are the characteristics of all OOPL's?

11 Michael Eckmann - Skidmore College - CS 330 - Fall 2004 Other topics Object oriented programming –What makes a language object oriented? What are the characteristics of all OOPL's? Abstract data types (classes)‏ Inheritance Dynamic binding of method calls to methods What are these features?

12 Michael Eckmann - Skidmore College - CS 330 - Fall 2004 Other topics Object oriented programming Paradigm Evolution 1. Procedural - 1950s-1970s (procedural abstraction)‏ 2. Data-Oriented - early 1980s (data abstraction)‏ 3. OOP - late 1980s (inheritance and dynamic binding)‏ Origins of Inheritance –Observations of the mid-late 1980s : Productivity increases can come from reuse Unfortunately, –ADTs are difficult to reuse--never quite right –All ADTs are independent and at the same level Inheritance solves both--reuse ADTs after minor changes and define classes in a hierarchy

13 Michael Eckmann - Skidmore College - CS 330 - Fall 2004 Other topics Exception Handling –Unusual event detectable by hardware or software that may require special processing –try/catch/finally in Java –try/catch/catch* in C++ Event Handling –Event driven programming Parts of program executed at unpredictable times e.g. GUI buttons, fields, etc.


Download ppt "CS 330 Programming Languages 12 / 09 / 2008 Instructor: Michael Eckmann."

Similar presentations


Ads by Google