syntax - Prolog: syntactically correct objects + relation vs. structure -
i'm new prolog , gradually working way through ivan bratko's 'prolog programming artificial intelligence' (4th ed.).
when doing exercise 2.1. (page 39), fail see why 5(x,y)
syntactically not correct, while +(north,west)
correct. @ first thought had fact functor number (as thought atom), according book, atom can digit. thought problem arguments being variables, fail see why pose problem syntactical correctness. point me in right direction of explanation?
furthermore wondering exact difference between relation , structure. while date(1, may, 2001)
(on page 35) seen structure, wondering if can same earlier examples chapter 1. is, example, relation parent(pam,bob)
first chapter so-called structure, or confusing things?
thanks in advance.
i fail see why 5(x,y) syntactically not correct, while +(north,west) correct.
a single digit not atom, number.
on page 33 section 2.1.1 atoms , numbers reads:
atoms can constructed in 3 ways: 1. strings of letters, digits , underscore character, starting lower-case letter. 2. strings of special characters such + - * / < > = : . & _ ~ 3. strings of characters enclosed in single quotes.
the character 5
- fails rule 1 because string not start underscore character or lower-case letter
- fails rule 2 because not 1 of special characters
- fails rule 3 because not enclosed in single quotes
the character +
succeeds because rule 2 special character.
one way explore further using swi-prolog functor/3
?- functor(+(north,west),name,arity). name = (+), arity = 2. ?- functor(5(x,y). error: syntax error: operator expected error: functor( error: ** here ** error: 5(x,y) .
what exact difference between relation , structure
on page 4 section 1.1 defining relations facts
in general, relation defined set of instances. example parent(tom,bob) particular instance of parent relation. other instances being:
parent(pam,bob) parent(tom,liz) parent(bob,ann) parent(bob,pat) parent(pat,jim)
on page 35 section 2.1.3 structures
structured objects (or structures) objects have several components, e.g.
date(1, may, 2001) point(1,1) seg(p1,p2) seg(point(1,1),point(2,3)) (a + b) * (c - 5) % uses infix operator *(+(a,b),-(c,5)) % uses prefix operator
looking @ question makes me think looking property common both relation , structure can used distinguish 1 other. don't know of one; when think using prolog don't think should use relation or structure
, think of how data structured
can simple number or more complex structure or structure of structures, , what predicates (rules) needed reach goal
given data. in looking @ definitions given best can specific relation can composed of many structures have same functor, not idea last in mind past period.
Comments
Post a Comment