Download presentation

Presentation is loading. Please wait.

Published byRicky Gravely Modified over 2 years ago

1
Built-in Functions listing(fruit).: Lists all the objects within this relation halt. Exit from Prolog write(X). /* Write to console */ nl /* New Line */ ! /* CUT Backtrack */

2
Example I: Simple Program has(jack,apples). has(ann,plums). has(dan,money). fruit(apples). fruit(plums).Queries: has(jack,_). /* Don’t care about second operand */ has(X,apples),has(Y,plums). /* who has apples and who has plums? */ has(dan,X),fruit(X). /* has Dan fruits? */ has(X,Y),not fruit(Y). /* does someone have something else? */

3
Basic Arithmetic ?- X is 5+4, Y is 5-4. X = 9, Y = 1 ?- X is 5*4, Y is 2^3. X = 20, Y = 8 ?- X is sqrt(3),Y is 3^0.5. X = 1.73205080756888, Y = 1.73205080756888 ?- X is 8 mod 3. X = 2

4
Example II: Arithmetic abs(X,X):- X >= 0, !. abs(X,Y):- Y is -X. ?- abs(0,R). R = 0 ?- abs(-9,R). R = 9

5
Example III: Lists Find Member member(X,[X|_]). member(X,[_|T]):- member(X,T). ?- member(b,[a,v,b,c]). yes ?- member(a,[b,c,g]).no Print List my_write([]). my_write([X|R]): write(X),nl,my_write(R). ?- my_write([a,b,c]). a b c yes

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google