{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# IO 5 - • prefix infix or postfix e.g true 2*5 7 –...

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

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

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

View Full Document
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
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

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

View Full Document
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
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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern