Prolog_Part_3

# Prolog_Part_3 - X =:= Y (same numbers ?) X =\= Y (different...

This preview shows pages 1–5. Sign up to view the full content.

Prolog- Syntax (cont.) Structures or compound terms Defined as a function (called a functor in Prolog) and its arguments (called components) e.g. book(programmming_in_prolog, clocksin, 2003) functor components Can use anonymous variable when not enough info, e.g. book(book123,_,_) York University- CSE 3401 11 03_Prolog

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

View Full Document
Operators They are functions or predicates, implemented for easier use. For example instead of +(3,4) we can write 3+4 + is an infix operator Instead of +(*(2,3), *(8,9)), we can write 2*3+8*9 * is another operator with a higher priority ( precedence ) over + Arithmetic operators are left associative , e.g. 8/4/4 means (8/4)/4 We will learn how to define new operators later in the course. York University- CSE 3401 12 03_Prolog
Arithmetic Some arithmetic operators X + Y, X - Y, X * Y, X / Y X // Y (integer quotient) X mod Y (remainder)

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: X =:= Y (same numbers ?) X =\= Y (different numbers?) X &lt; Y, X &gt; Y, X =&lt; Y, X &gt;= Y (comparisons) is: an infix operator, evaluating the right-hand argument, then matching with left-hand argument York University- CSE 3401 13 03_Prolog Examples York University- CSE 3401 03_Prolog 14 ?- 3=:=3. true. ?- 3=:=4. false. ?- 3=:=2+1. true. ?- is(3,2+1). true. ?- is(2+1,3). false. ?- 2&gt;3. false. ?- 2+3. ERROR: toplevel: Undefined procedure: (+)/2 ?- is(X,2+3). X = 5. ?- is(X,5/2). X = 2.5. ?- is(X,5//2). X = 2. ?- is(X,5 mod 2). X = 1. ? X is 5//2. X=2. Example York University- CSE 3401 15 pop(china, 800). area(china, 4). density(X,Y):- pop(X,P), area(X,A), Y is P/A. The population density of a country X is Y, if: The population of X is P, and The area of X is A, and Y is calculated by dividing P by A. :- density(china, X). X=200. 03_Prolog...
View Full Document

## This note was uploaded on 02/14/2012 for the course CSE 3401 taught by Professor Movahedi during the Fall '11 term at York University.

### Page1 / 5

Prolog_Part_3 - X =:= Y (same numbers ?) X =\= Y (different...

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

View Full Document
Ask a homework question - tutors are online