Presentation is loading. Please wait.

Presentation is loading. Please wait.

On Using Scheme to Introduce Prolog Daniel E. Stevenson and Michael R. Wick Department of Computer Science University of Wisconsin - Eau Claire Eau Claire,

Similar presentations


Presentation on theme: "On Using Scheme to Introduce Prolog Daniel E. Stevenson and Michael R. Wick Department of Computer Science University of Wisconsin - Eau Claire Eau Claire,"— Presentation transcript:

1 On Using Scheme to Introduce Prolog Daniel E. Stevenson and Michael R. Wick Department of Computer Science University of Wisconsin - Eau Claire Eau Claire, WI 54701

2 Road Map Motivation Motivation Reductionist Approach Reductionist Approach Scheme-to-Prolog Strategy Scheme-to-Prolog Strategy The Debate The Debate Experiment Design Experiment Design Results and Observations Results and Observations Follow-up Experiment Follow-up Experiment Results and Observations Results and Observations Future Work Future Work Contact Information Contact Information

3 Our Motivation Want to give students a concrete strategy to move from a blank page to a working Prolog program Want to give students a concrete strategy to move from a blank page to a working Prolog program We follow a “reductionist” approach to teaching Programming Languages We follow a “reductionist” approach to teaching Programming Languages l Includes use of translational semantics Scheme is our target language Scheme is our target language l Simple syntax l Level playing field l Expressive power

4 A Reductionist Approach to Programming Languages Focus on language building blocks Focus on language building blocks l What is a paradigm? F Collection of strategic decisions involving the blocks l What is a language? F Collection of tactical decisions involving the blocks Our Implementation Our Implementation l Cover basic syntax description l Demonstrate building blocks in Scheme l Implement paradigms in Scheme l Assignments are in other languages

5 A Prolog/Scheme Correspondence (1) Many problems in Prolog are list-processing problems. Many problems in Prolog are list-processing problems. The concepts of list processing and recursive definitions are similar between Scheme and Prolog The concepts of list processing and recursive definitions are similar between Scheme and Prolog Prolog’s pattern matching plays the role of car and cdr in Scheme Prolog’s pattern matching plays the role of car and cdr in Scheme Prolog rules map to Scheme cond clause Prolog rules map to Scheme cond clause append([],L,L). append([H|T],L,[H|NewT]) :- append(T,L,NewT). (define (append L1 L2) (cond ((null? L1) L2) (else (car L1) (cdr L1) [],L,L HTL L2 append(T,L,NewT) (append ) [H|NewT] (cons ))))

6 A Prolog/Scheme Correspondence (2) Many problems in Prolog are predicate problems. Many problems in Prolog are predicate problems. The concepts are again similar between Scheme and Prolog The concepts are again similar between Scheme and Prolog Prolog’s pattern matching plays the role of car and cdr in Scheme Prolog’s pattern matching plays the role of car and cdr in Scheme Prolog positive rules map to Scheme cond clauses Prolog positive rules map to Scheme cond clauses Scheme adds negative cond clauses Scheme adds negative cond clauses isMember(A, [A|L]). isMember(A, [X|L]) :- isMember(A, L). (define (isMember A L) (cond ((null? L) #f) (car L) (cdr L) A AL A, [A| A(else (isMember? ))) ((eq? A ) #t) isMember(A, L)

7 A Scheme-to-Prolog Strategy To Translate a Scheme Program into a Prolog Program: To Translate a Scheme Program into a Prolog Program: 1.Write the required behavior (predicate versus procedure) in Scheme 2.Define the corresponding Prolog relation. If the Scheme program is a predicate, use the same number of parameters in both versions. Otherwise, use one additional parameter in the Prolog version to represent the Scheme return value. 3.Translate each “positive” clause in the Scheme version to Prolog. a.If a Scheme clause requires access to the car or the cdr of an input parameter, use the pattern [H|T] in the head of the corresponding Prolog definition. b.If a Scheme clause requires two values to be equal, use the same variable in Prolog for each corresponding occurrence of the two values in Scheme. c.If a Scheme clause requires the results of other Scheme functions, use Prolog’s subgoaling to query and name the results of these functions.

8 The Debate Does our Scheme-to-Prolog strategy help or hurt? Does our Scheme-to-Prolog strategy help or hurt? l Do students waste too much time in Scheme and not enough time learning Prolog? l Given Scheme’s relationship to mathematics, is there any difference in learning between using purely mathematical recursive definitions and using recursive Scheme procedures? l Does the use of Scheme hurt students when it comes to learning the backtracking concepts of Prolog? Two Hypotheses Two Hypotheses l Null Hypothesis I: Our use of Scheme to introduce students to Prolog does not impact the students’ ability to learn early Prolog. l Null Hypothesis II: Our use of Scheme to introduce students to Prolog does not impact the students’ ability to learn later Prolog.

9 Experiment Design (1) A total of 44 students in our Programming Languages course A total of 44 students in our Programming Languages course Students split into control and experiment groups Students split into control and experiment groups l 22 students each l Same CS course background F Six students in each group had discrete including brief intro to Prolog l Exact same average CS GPA l Exact same average Overall GPA Both groups given one-hour lecture on logic programming Both groups given one-hour lecture on logic programming Both groups given Prolog Tutorial from Bucknell University Both groups given Prolog Tutorial from Bucknell University l Control given recursive definition strategy l Experiment given Scheme-to-Prolog strategy

10 Experiment Design (2) Students given four one-hour sessions to answer 10 questions Students given four one-hour sessions to answer 10 questions l Positives(L1, L2). L2 are the positive numbers from L1. l Max(N, L). N is the maximum number in L. l Palindrome(L). L is a palindrome. l Prefix(P, L). P is a prefix of L. l Last(X, L). X is the last element of L. l Rem(X, L1, L2). L2 is L1 with all occurrences of X removed. l NextTo(X, Y, L). X and Y are consecutive elements of L. l Replace(N1,N2,L1,L2). L2 is L1 with every occurrence of N1 replaced by N2. l Parent(P, C). P is a parent of C. l Ancestor(A, C). A is an ancestor of C. Students also given in-class exam at completion of logic programming section of course (emphasizing backtracking) Students also given in-class exam at completion of logic programming section of course (emphasizing backtracking)

11 Results and Observations (1) Number of Students Who Answered Each Question Correctly Number of Students Who Answered Each Question Correctly Total Number of Questions Answered Correctly Total Number of Questions Answered Correctly Max made harder – how to compare numbers Palindrome made easier – used reverse Made parent/ancestor harder We can’t teach Prolog in 4 hours

12 Results and Observations (2) Students Scores on In-Class Exam on Logic Programming Students Scores on In-Class Exam on Logic Programming We can teach Prolog Eventual learning not hurt

13 Follow-up Experiment Not a “warm fuzzy” Not a “warm fuzzy” l Are we helping our students learn new languages at all? Final Exam Final Exam l Give students 10 questions to implement in a new language l Give students BNF, reference manual, and tutorial as resources Pessimistic Experiment Pessimistic Experiment l Pick language/paradigm similar to known (Java/C++) F Ruby – object-oriented with familiar syntax l Should be least difference between control and experiment l Divide into control (students after CS 330) and experiment (students before CS 330) l Comparison between two different student bodies F Neither reported knowledge of Ruby F Control GPA: 3.11 F Experiment GPA: 3.09

14 Results and Observations Whew! The course is making a difference A clear shift in performance

15 Future Work & Contact Information Modify pre/post exams to use Haskell, ML, Snobol, … Modify pre/post exams to use Haskell, ML, Snobol, … Test on students with deeper exposure to Scheme Test on students with deeper exposure to Scheme Question-by-question analysis of pre/post exams Question-by-question analysis of pre/post exams Daniel Stevenson (stevende@uwec.edu) Michael Wick (wickmr@uwec.edu) Department of Computer Science University of Wisconsin – Eau Claire Eau Claire, WI 54701


Download ppt "On Using Scheme to Introduce Prolog Daniel E. Stevenson and Michael R. Wick Department of Computer Science University of Wisconsin - Eau Claire Eau Claire,"

Similar presentations


Ads by Google