19 - Click to edit Master subtitle style Chapter Nineteen...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Click to edit Master subtitle style Chapter Nineteen Modern Programming Languages, 2nd ed. A First Look At Prolog Chapter Nineteen Modern Programming Languages, 2nd ed. 11 Chapter Nineteen Modern Programming Languages, 2nd ed. Outline ■ Terms ■ Using a Prolog language system ■ Rules ■ The two faces of Prolog ■ Operators ■ Lists ■ Negation and failure ■ What Prolog is good for Chapter Nineteen Modern Programming Languages, 2nd ed. 22 Chapter Nineteen Modern Programming Languages, 2nd ed. Terms ■ Everything in Prolog is built from terms : – Prolog programs – The data manipulated by Prolog programs ■ Three kinds of terms: – Constants: integers, real numbers, atoms – Variables – Compound terms Chapter Nineteen Modern Programming Languages, 2nd ed. 33 Chapter Nineteen Modern Programming Languages, 2nd ed. Constants ■ Integer constants: 123 ■ Real constants: 1.23 ■ Atoms: – A lowercase letter followed by any number of additional letters, digits or underscores: fred – A sequence of non-alphanumeric characters: * , . , = , @#$ – Plus a few special atoms: Chapter Nineteen Modern Programming Languages, 2nd ed. 44 Chapter Nineteen Modern Programming Languages, 2nd ed. Atoms Are Not Variables ■ An atom can look like an ML or Java variable: – i , size , length ■ But an atom is not a variable; it is not bound to anything, never equal to anything else ■ Think of atoms as being more like string constants: "i" , "size" , "length" Chapter Nineteen Modern Programming Languages, 2nd ed. 55 Chapter Nineteen Modern Programming Languages, 2nd ed. Variables ■ Any name beginning with an uppercase letter or an underscore, followed by any number of additional letters, digits or underscores: X , Child , Fred , _ , _123 ■ Most of the variables you write will start with an uppercase letter ■ Those starting with an underscore, including _ , get special treatment Chapter Nineteen Modern Programming Languages, 2nd ed. 66 Chapter Nineteen Modern Programming Languages, 2nd ed. Compound Terms ■ An atom followed by a parenthesized, comma-separated list of one or more terms: x(y,z) , +(1,2) , .(1,) , parent(adam,seth) , x(Y,x(Y,Z)) ■ A compound term can look like an ML function call: f(x,y) ■ Again, this is misleading ■ Think of them as structured data Chapter Nineteen Modern Programming Languages, 2nd ed. 77 Chapter Nineteen Modern Programming Languages, 2nd ed. Terms ■ All Prolog programs and data are built from such terms ■ Later, we will see that, for instance, +(1,2) is usually written as 1+2 ■ But these are not new kinds of terms, just abbreviations Chapter Nineteen Modern Programming Languages, 2nd ed. 88 < term > ::= < constant > | < variable > | < compound-term > < constant > ::= < integer > | < real number > | < atom > < compound-term > ::= < atom > ( < termlist > ) < termlist > ::= < term > | < term > , < termlist > Chapter Nineteen Modern Programming Languages, 2nd ed....
View Full Document

This note was uploaded on 09/30/2011 for the course CS 6371 taught by Professor Hamlen during the Spring '11 term at University of Texas at Dallas, Richardson.

Page1 / 76

19 - Click to edit Master subtitle style Chapter Nineteen...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online