Prolog Syntax Error Operator Expected
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring
Syntax Error: , Or ) Expected Prolog
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question prolog syntax error . or operator expected after expression x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join warning singleton variables prolog them; it only takes a minute: Sign up “Syntax error: Operator expected” in Prolog up vote 3 down vote favorite I have this graph structure representing data flow in Prolog. I have an edge from node 1 to 2, 1
Syntax Error Operator Expected Ocaml
to 3, etc. Variable x is defined in node 1, variable t in node 4, etc. Variable d is used in node 4, variable x in node 7, etc. The function definition_clear_path should compute the definition-clear path of any variable. When I run this I get the following error: definition_clear_path/3: Undefined procedure: definition_clear_path1/4 However, there are definitions for: definition_clear_path/3 When I enter the rule for definition_clear_path1 from the terminal I get Syntax error: Operator expected. Why? edge(1, 2). edge(1,3).
Arguments Are Not Sufficiently Instantiated
edge(3,7). edge(3,4). edge(4,6). edge(4,5). edge(7,x). def(p,1). def(e,1). def(d,1). def(x,1). def(c,1). def(d,4). def(t,4). def(c,5). def(x, 6). def(c,6). use(d,3). use(e,3). use(d,4). use(c,4). use(x,4). use(t,4). use(c,5). use(x,6). use(c,6). use(d,6). use(x,7). pos_path(X,Y, [X,Y]):- edge(X,Y). pos_path(Start, End, [Start|T]) :- edge(Start,Mid), pos_path(Mid, End, T). definition_clear_path( Node , J , Var ):- definition_clear_path1( Node , J , Var , [ Node ] ) . definition_clear_path1(B , J, K , F):- edge (B , J ). definition_clear_path1( Node , J , Var , L):- edge ( Node , N1 ) , not(def( Var , N1 )) , not(use( Var , N1 )) , definition_clear_path1( N1 , J , Var , [ Node | L ] ) . prolog share|improve this question edited Mar 2 '15 at 1:21 Palec 5,03242244 asked May 21 '11 at 15:44 Lyes Khalil 18114 If you put definition_clear_path at the end, does the error goes away? –George Kastrinis May 21 '11 at 16:04 No, same error. –Lyes Khalil May 21 '11 at 16:23 add a comment| 1 Answer 1 active oldest votes up vote 11 down vote accepted Remove the space between edge and the opening parenthesis. Spaces delimit terms, so Prolog will think that edge is an operator rather than the functor of a compound term. share|improve this answer answered May 21 '11 at 18:21 Nick Main 1,027615 add a comment| Your Answer draft saved draft discarded Sign up or log in
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies prolog not operator of this site About Us Learn more about Stack Overflow the company
Prolog Write
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users prolog lists Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a http://stackoverflow.com/questions/6082779/syntax-error-operator-expected-in-prolog minute: Sign up Prolog - Getting Syntax Error - Operator Expected up vote 3 down vote favorite I'm starting to learn Prolog, and I'm running into a compiler error with my code. I'm trying to write some code that will check if a family is in poverty if they meet certain conditions. The last line couple of lines are the poverty conditions, http://stackoverflow.com/questions/10375621/prolog-getting-syntax-error-operator-expected and that's where I'm getting the Opertator Expected error. I'm trying to say that given the family ID, if the size of that family is one, and the income is less than 11170, then that family is in poverty. And for a family of size >8 the poverty level is 38890 plus 3960 for every additional family member. How can I correct these errors? family_in_poverty should be returning true or false. family(10392, person(tom, fox, born(7, may, 1960), works(cnn, 152000)), person(ann, fox, born(19, april, 1961), works(nyu, 65000)), % here are the children... [person(pat, fox, born(5, october, 1983), unemployed), person(jim, fox, born(1, june, 1986), unemployed), person(amy, fox, born(17, december, 1990), unemployed)]). family(38463, person(susan, rothchild, born(13, september, 1972), works(osu, 75000)), person(jess, rothchild, born(20, july, 1975), works(nationwide, 123500)), % here are the children... [person(ace, rothchild, born(2, january, 2010), unemployed)]). married(FirstName1, LastName1, FirstName2, LastName2) :- family(_, person(FirstName1, LastName1, _, _), person(FirstName2, LastName2, _, _), _). married(FirstName1, LastName1, FirstName2, LastName2) :- family(_, person(FirstName2, LastName2, _, _), person(FirstName1, LastName1, _, _), _). householdIncome(ID, Income) :- family(ID, person(_, _, _, works(_, Income1)), person(_, _, _, works(_, Income2)), _), Income is In
Session Lecture 4 Slides Practical Session Lecture 5 Slides http://cs.union.edu/~striegnk/courses/esslli04prolog/practical.day1.php?s=practical.day1.node4 Practical Session Interpreting the error messages and warnings that Prolog may give you Prolog will tell you if the things that you are writing are syntactically incorrect. Download the knowledge base kb.syntax_error.pl and load it into Prolog. You will get the syntax error following answer. ?- consult('kb.syntax_error.pl'). ERROR: /home/kris/lehre/esslli04/esslli04prolog/kbs/kb.syntax_error.pl:5: Syntax error: Operator expected ERROR: /home/kris/lehre/esslli04/esslli04prolog/kbs/kb.syntax_error.pl:11: Syntax error: Operator expected ERROR: /home/kris/lehre/esslli04/esslli04prolog/kbs/kb.syntax_error.pl:14: Syntax error: Unexpected end of clause ERROR: /home/kris/lehre/esslli04/esslli04prolog/kbs/kb.syntax_error.pl:17: Syntax error: Unexpected end of file % kb.syntax_error.pl compiled 0.00 sec, 1,348 bytes Yes This tells you that or operator expected there are four syntax errors. It also tells you that the Prolog interpreter thinks that the errors are in lines 6, 12, 15, and 18. And it gives you some indications as to what might cause the problems (operator expected, unexpected end of clause/file). Which are the mistakes? Solutions Another thing that you might get complaints about are singleton variables; i.e., variables which are used only once in a clause. Download the knowledge base kb.singleton_vars.pl and load it into Prolog. You will get the following: ?- consult('kb.singleton_vars.pl'). Warning: (/home/kris/lehre/esslli04/esslli04prolog/kbs/kb.singleton_vars.pl:8): Singleton variables: [X, Y] % kb.singleton_vars.pl compiled 0.00 sec, 1,520 bytes Yes Prolog tells you that X and Y are singleton variables in the clause starting at line 8. Prolog warns you when it detects singleton variables, because singleton