Prolog Error Operator Expected
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have syntax error: , or ) expected prolog Meta Discuss the workings and policies of this site About Us prolog syntax error Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with prolog syntax error . or operator expected after expression us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, warning singleton variables prolog just like you, helping each other. Join 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 to 3, etc. Variable x is defined in node
Syntax Error Operator Expected Ocaml
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). 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_clea
here for a quick overview of the site Help Center Detailed answers to any
Syntax Of Prolog
questions you might have Meta Discuss the workings and policies arguments are not sufficiently instantiated of this site About Us Learn more about Stack Overflow the company Business Learn more about prolog not operator hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack http://stackoverflow.com/questions/6082779/syntax-error-operator-expected-in-prolog Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Syntax Error: Operator expected in SWI Prolog up vote 1 down vote favorite I keep getting a syntax error every time I try to compile this buffer. I've gone http://stackoverflow.com/questions/32580525/syntax-error-operator-expected-in-swi-prolog through the ordinary steps of removing all spaces, but still I keep getting the same error every time. solve_puzzle(Swimmers):- Swimmers=[_Girl1,_Girl2,_Girl3], [girl(_,_,_,first),girl(_,_,_,second),girl(_,_,_,third)]=Swimmers, is_faster(girl(claudia,_,_,_),(_,_,cheltenham_girls,_),Swimmers), is_faster(girl(mary,_,_,_),girl(_,table_tennis,_,_),Swimmers), member(girl(_,weightlifting,_,first),Swimmers), member(girl(mary,_,sydney_girls_high_school,_),Swimmers), member(girl(claudia,ballroom_dancing,_,_),Swimmers), member(girl(_,_,hornsby_girls_high_school,_),Swimmers). is_faster(F,S,[F|[S|_]]). is_faster(F,S,[F,S,[_|Rest]]):- is_faster[F,S,Rest). Whats doing this? I seem to run into this every time I attempt prolog. prolog syntax-error share|improve this question edited Sep 15 '15 at 12:34 repeat 12.9k427121 asked Sep 15 '15 at 7:49 David 82 3 SWI even tells you the exact line of the error. Write: is_faster(F, S, [F,S,_|Rest]) :- is_faster(F, S, Rest). to at least fix the syntax error (semantic problems may still be present). Removing all spaces is certainly not required or recommended. Also, check out more convenient list syntax: You can write the penultimate clause equivalently as is_faster(F, S, [F,S,_]). (again, just considering syntax, and leaving the semantics unchanged). –mat Sep 15 '15 at 7:53 add a comment| 1 Answer 1 active oldest votes up vote 2 down vo
Session Lecture 4 Slides Practical Session Lecture 5 Slides Practical Session Interpreting the error messages and http://cs.union.edu/~striegnk/courses/esslli04prolog/practical.day1.php?s=practical.day1.node4 warnings that Prolog may give you Prolog will tell you if http://swi-prolog.iai.uni-bonn.narkive.com/vjA0tPsJ/newbie-common-syntax-error-operator-expected 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 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 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 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 or operator expected 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 variables are often due to a typo (as in our example). Sometimes you do want to use variables which are mentioned only once in a clause. To avoid getting the singleton variable warning, you should use the anonymous variable _ instead of a named variable in this case. Finally, Prolog complains when different clause
0) :- X<3, !.f(X, 2) :- X>=3, X<6, !.f(X, 4) :- X>=6.When I try to run it in SWI-Prolog I get error:1 ?- consult(q).ERROR: c:/users/admin/documents/q.pl:2:4: Syntax error: Operator expected% q compiled 0.00 sec, 1,136 bytestrue.What should I fix to run under SWI-Prolog?--View this message in context: http://www.nabble.com/Newbie%3A-common-Syntax-error%3A-Operator-expected-tp26095829p26095829.htmlSent from the SWI Prolog mailing list archive at Nabble.com. Uwe Lesta 2009-10-28 15:07:47 UTC PermalinkRaw Message Post by Vladimir MihailenkoPREDICATESf(integer, integer)CLAUSESf(X, 0) :- X<3, !.f(X, 2) :- X>=3, X<6, !.f(X, 4) :- X>=6.1 ?- consult(q).ERROR: c:/users/admin/documents/q.pl:2:4: Syntax error: Operator expected% q compiled 0.00 sec, 1,136 bytestrue.What should I fix to run under SWI-Prolog?The code above is TURBO-PROLOG.cut off the first three lines and try again--Kind regardsUwe Lesta Paulo Moura 2009-10-28 15:09:09 UTC PermalinkRaw Message Post by Vladimir MihailenkoPREDICATESf(integer, integer)CLAUSESf(X, 0) :- X<3, !.f(X, 2) :- X>=3, X<6, !.f(X, 4) :- X>=6.1 ?- consult(q).ERROR: c:/users/admin/documents/q.pl:2:4: Syntax error: Operator expected% q compiled 0.00 sec, 1,136 bytestrue.What should I fix to run under SWI-Prolog?--The code seems to be written for VisualProlog, which, despite its nameand being a fine language, is not Prolog as me and others understandit. To compile the code above remove the lines in all-caps.Cheers,Paulo-----------------------------------------------------------------Paulo Jorge Lopes de Moura, PhDAssistant ProfessorDep. of Computer Science, University of Beira Interior6201-001 Covilhã, PortugalOffice 3.18 Ext. 3276Phone: +351 275319891 Fax: +351 275319899Email: