IO 5 - • prefix infix or postfix e.g true 2*5 7 – Precedence • An integer associated with each operator the closer to 1 the higher the

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

View Full Document Right Arrow Icon
Read program files Reading program from a file :- consult(‘mycode.pl’). or :- [‘mycode.pl’]. Consulting several files: :- consult(file1), consult(‘file2.pl’), consult(‘c: \\pl\\ file3.txt’). or :- [file1, ‘file2.pl’, ‘c: \\pl\\ file3.txt’]. York University- CSE 3401- V. Movahedi 08_IO 21
Background image of page 1

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

View Full DocumentRight Arrow Icon
More on reading terms Examples: :- read(X). 3 + 4. X= 3+4. :- read(X). 3 + . Error! Unbalanced operator. How does Prolog know? York University- CSE 3401- V. Movahedi 08_IO 22
Background image of page 2
Terms (reminder) Term Constants Variables Functors applied to arguments Operators and their arguments Examples: :- read(X). We can type in: 8. a. myatom . ‘GOOD’. Myvariable. X. +(3,4). 3+4. York University- CSE 3401- V. Movahedi 08_IO 23
Background image of page 3

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

View Full DocumentRight Arrow Icon
Operators (reminder) Operators To make some functors easier to use, e.g. instead of +(3,4) we can write 3+4 (Important: it is not the same as 7) Position
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • prefix, infix, or postfix, e.g. \+ true, 2*5, 7! – Precedence • An integer associated with each operator, the closer to 1, the higher the precedence • e.g. multiplication has a higher precedence than addition, a+b*c is +(a, *(b,c)) – Associativity • Left or right • All arithmetic operators left associative • e.g. 8/4/4 is (8/4)/4 York University- CSE 3401- V. Movahedi 24 08_IO Declaring operators • An operator is declared by a goal: :- op( Precedence, Specifier, Name). For example: :- op(1000, xf, myop). :- op(500, yfx , ‘+’). :- op(400, yfx , ‘*’). :- op(900, fy , ‘ \ +’). • Precedence: an integer between 1 and 1200, lower values, higher priority • Name: the operator’s name • Specifier: specifies position and associativity valid specifiers: fx, fy, xfx, xfy, yfx, yfy, xf, yf York University- CSE 3401- V. Movahedi 08_IO 25...
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

IO 5 - • prefix infix or postfix e.g true 2*5 7 – Precedence • An integer associated with each operator the closer to 1 the higher the

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

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