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

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

Lisp. Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
CS 355 – Programming Languages
Chapter 12 - Logic Programming
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
LEARNING FROM OBSERVATIONS Yılmaz KILIÇASLAN. Definition Learning takes place as the agent observes its interactions with the world and its own decision-making.
Lecture 2: Fundamental Concepts
Lisp. Versions of LISP Lisp is an old language with many variants –LISP is an acronym for List Processing language Lisp is alive and well today Most modern.
CS 330 Programming Languages 11 / 18 / 2008 Instructor: Michael Eckmann.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
General pattern for selecting some elements of a list This negatives example illustrates a general pattern: If you want a function which selects some elements.
Lisp by Namtap Tapchareon Lisp Background  Lisp was developed by John McCarthy in  Lisp is derives from List Processing Language. 
Cs1120 Fall 2009 David Evans Lecture 19: Stateful Evaluation.
Comp. Eng. SW Lab II: FP with Scheme 1 Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
ISBN Chapter 15 Functional Programming Languages.
CS 330 Programming Languages 11 / 21 / 2006 Instructor: Michael Eckmann.
1 Programming Languages and Paradigms Functional Programming.
CS 152: Programming Language Paradigms February 17 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
Declarative vs Procedural Programming  Procedural programming requires that – the programmer tell the computer what to do. That is, how to get the output.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
CS 403: Programming Languages Lecture 6 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 Topics Covers everything –1) in slides –2) from the very beginning. Language classification, history, and comparison Programming paradigms –Structured.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 8.
Abstraction: Procedures as Parameters CMSC Introduction to Computer Programming October 14, 2002.
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
CS 152: Programming Language Paradigms March 5 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
CS 152: Programming Language Paradigms March 12 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
Functional Programming. Some Functional Languages Lisp Scheme - a dialect of Lisp Haskell Miranda.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
Comparative Programming Languages Functional programming with Lisp/Scheme.
CS 152: Programming Language Paradigms February 12 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
1 Introduction to Functional Programming in Racket CS 270 Math Foundations of CS Jeremy Johnson.
Scott C. Johnson Lecturer Rochester Institute of Technology Spring 2016.
CS314 – Section 5 Recitation 9
Functional Programming Languages
CS 550 Programming Languages Jeremy Johnson
CS 326 Programming Languages, Concepts and Implementation
Modern Programming Languages Lecture 20 Fakhar Lodhi
CS 326 Programming Languages, Concepts and Implementation
Chapter 15 – Functional Programming Languages
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
CS 270 Math Foundations of CS Jeremy Johnson
Introduction to Functional Programming in Racket
Nondeterministic Evaluation
Mini Language Interpreter Programming Languages (CS 550)
The Metacircular Evaluator
FP Foundations, Scheme In Text: Chapter 14.
CS 36 – Chapter 11 Functional programming Features Practice
Modern Programming Languages Lecture 20 Fakhar Lodhi
The Metacircular Evaluator (Continued)
CS 5010 Program Design Paradigms “Bootcamp” Lesson 6.5
Programming Techniques
Introduction to Functional Programming in Racket
Lecture 14: The environment model (cont
Announcements Quiz 5 HW6 due October 23
6.001 SICP Interpretation Parts of an interpreter
Programming Languages
Lisp.
Presentation transcript:

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

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

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

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

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

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)

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.

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.

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

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)

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

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

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

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

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 Michael Wick Department of Computer Science University of Wisconsin – Eau Claire Eau Claire, WI 54701