Prolog Lists - Organization of Programming Languages - Lecture Notes, Study notes of Programming Languages

This course is an introduction to concepts in programming languages. The course covers a range of programming paradigms including procedural, functional, and logic-based languages. This lecture includes: Prolog Proof Trees, Horn Clause, Dentoes Conjunction, Propositional to Predicate Logic, Universally Quantified, Existentially Quantified, Haskell Pattern

Typology: Study notes

2012/2013

Uploaded on 09/28/2013

noob
noob 🇮🇳

4.4

(25)

105 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture Notes CPSC 326 (Spring 2013)
Today ...
Project part 2
Reading and HW 9
Prolog lists
S. Bowers 1 of 4
pf3
pf4

Partial preview of the text

Download Prolog Lists - Organization of Programming Languages - Lecture Notes and more Study notes Programming Languages in PDF only on Docsity!

Today ...

  • Project part 2
  • Reading and HW 9
  • Prolog lists

Variable naming and proof trees

Be careful with variable names

r(X, Y) :- r(X, Z), s(Z, Y).

solve [r(X,Y)]

solve [r(X,Z),s(Z,Y)]

solve [r(X,Z1),s(Z1,Z),s(Z,Y)]

We cannot use Z here again!!

• We cannot use Z here again!^ So we rename to Z1 …!

  • So we rename to Z ...

List predicates

Checking list membership

member(X, [X | ]). member(X, [ | T]) :- member(X, T).

Q: What is the proof tree for member(2, [1, 2])?

Q: What is the proof tree for member(2, [1, 3])?

Note this example works like pattern matching in Haskell ...

  • try first rule ... if it doesn’t succeed, try next candidate
  • unfold the rule
  • and so on

Q: How would we write a last predicate?

last(X, [X]). last(X, [_|T]) :- last(X, T).

Q: What is the proof tree for last(2, [1, 2])?