|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 | Next > |
|
|
Newbie: common Syntax error: Operator expectedI have such code which is copy-pasted from book:
PREDICATES f(integer, integer) CLAUSES f(X, 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 bytes true. What should I fix to run under SWI-Prolog? |
|
|
Re: Newbie: common Syntax error: Operator expectedVladimir Mihailenko schrieb: > I have such code which is copy-pasted from book: > > PREDICATES > f(integer, integer) > CLAUSES > f(X, 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 bytes > true. > > 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 regards Uwe Lesta _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: Newbie: common Syntax error: Operator expectedOn 2009/10/28, at 14:38, Vladimir Mihailenko wrote: > I have such code which is copy-pasted from book: > > PREDICATES > f(integer, integer) > CLAUSES > f(X, 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 bytes > true. > > What should I fix to run under SWI-Prolog? > -- The code seems to be written for VisualProlog, which, despite its name and being a fine language, is not Prolog as me and others understand it. To compile the code above remove the lines in all-caps. Cheers, Paulo ----------------------------------------------------------------- Paulo Jorge Lopes de Moura, PhD Assistant Professor Dep. of Computer Science, University of Beira Interior 6201-001 Covilhã, Portugal Office 3.18 Ext. 3276 Phone: +351 275319891 Fax: +351 275319899 Email: <mailto:pmoura@...> Home page: <http://www.di.ubi.pt/~pmoura> Research: <http://logtalk.org/> Blog: <http://blog.logtalk.org/> ----------------------------------------------------------------- _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: Newbie: common Syntax error: Operator expected Vladimir:
'%' is commentary. This program would have compiled, if you supplied a full-stop after the fact 'f(integer, integer)', though the value of that fact in this case is unclear. Prolog is a typeless language. There is no need to declare an argument's type before using it, as is generally required in other strongly-typed languages. % PREDICATES % f(integer, integer) % CLAUSES f(X, 0) :- X<3, !. f(X, 2) :- X>=3, X<6, !. f(X, 4) :- X>=6. ?- between(1,10, X), f(X,Y). X = 1, Y = 0 ; X = 2, Y = 0 ; X = 3, Y = 2 ; X = 4, Y = 2 ; X = 5, Y = 2 ; X = 6, Y = 4 ; X = 7, Y = 4 ; X = 8, Y = 4 ; X = 9, Y = 4 ; X = 10, Y = 4. ?- From: Vladimir Mihailenko <michailenko@...> To: swi-prolog@... Sent: Wed, Oct 28, 2009 10:38 am Subject: [SWIPL] Newbie: common Syntax error: Operator expected
|
|
|
Re: Newbie: common Syntax error: Operator expectedThank you. I used PREDICATES and CLAUSES, because SWI-Prolog IDE properly highlights it like keywords. Can u say what is wrong with this code:
min(X, Y, X) :- X <= Y. min(X, Y, Y) :- Y < X. ERROR: c:/users/admin/documents/q.pl:1:0: Syntax error: Operator expected % q compiled 0.00 sec, 824 bytes true. |
|
|
Re: Newbie: common Syntax error: Operator expectedOn 2009/10/28, at 15:38, Vladimir Mihailenko wrote: > Can u say what is wrong with this code: > > min(X, Y, X) :- X <= Y. > min(X, Y, Y) :- Y < X. > > ERROR: c:/users/admin/documents/q.pl:1:0: Syntax error: Operator > expected Change X <= Y to X =< Y. Cheers, Paulo ----------------------------------------------------------------- Paulo Jorge Lopes de Moura, PhD Assistant Professor Dep. of Computer Science, University of Beira Interior 6201-001 Covilhã, Portugal Office 3.18 Ext. 3276 Phone: +351 275319891 Fax: +351 275319899 Email: <mailto:pmoura@...> Home page: <http://www.di.ubi.pt/~pmoura> Research: <http://logtalk.org/> Blog: <http://blog.logtalk.org/> ----------------------------------------------------------------- _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
RE: Newbie: common Syntax error: Operator expectedIt should be X =< Y.
Mihai Fonoage -----Original Message----- From: swi-prolog-admin@... [mailto:swi-prolog-admin@...] On Behalf Of Vladimir Mihailenko Sent: Wednesday, October 28, 2009 11:38 AM To: swi-prolog@... Subject: Re: [SWIPL] Newbie: common Syntax error: Operator expected Thank you. I used PREDICATES and CLAUSES, because SWI-Prolog IDE properly highlights it like keywords. Can u say what is wrong with this code: min(X, Y, X) :- X <= Y. min(X, Y, Y) :- Y < X. ERROR: c:/users/admin/documents/q.pl:1:0: Syntax error: Operator expected % q compiled 0.00 sec, 824 bytes true. -- View this message in context: http://www.nabble.com/Newbie%3A-common-Syntax-error%3A-Operator-expected-tp2 6095829p26096831.html Sent from the SWI Prolog mailing list archive at Nabble.com. _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: Newbie: common Syntax error: Operator expectedOoh... Its going to be infinitely... I just copy/paste examples and get the same error message (writing first post I thought that the reason is the same, but now...): conc([], L, L). conc([H|T], L, [H|T1]):–conc(T,L,T1). Same error message: 6 ?- consult(q). ERROR: c:/users/admin/documents/q.pl:2:0: Syntax error: Operator expected % q compiled 0.00 sec, 0 bytes true. Can you recomend some resources which explores SWI-Prolog syntax or provides some simple but working examples... Paulo Moura wrote: > > > On 2009/10/28, at 15:38, Vladimir Mihailenko wrote: > >> Can u say what is wrong with this code: >> >> min(X, Y, X) :- X <= Y. >> min(X, Y, Y) :- Y < X. >> >> ERROR: c:/users/admin/documents/q.pl:1:0: Syntax error: Operator >> expected > > > Change X <= Y to X =< Y. > > Cheers, > > Paulo > > > ----------------------------------------------------------------- > Paulo Jorge Lopes de Moura, PhD > Assistant Professor > Dep. of Computer Science, University of Beira Interior > 6201-001 Covilhã, Portugal > > Office 3.18 Ext. 3276 > Phone: +351 275319891 Fax: +351 275319899 > Email: <mailto:pmoura@...> > > Home page: <http://www.di.ubi.pt/~pmoura> > Research: <http://logtalk.org/> Blog: <http://blog.logtalk.org/> > ----------------------------------------------------------------- > > > > > > > > _______________________________________________ > SWI-Prolog mailing list > SWI-Prolog@... > https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog > > -- View this message in context: http://www.nabble.com/Newbie%3A-common-Syntax-error%3A-Operator-expected-tp26095829p26097523.html Sent from the SWI Prolog mailing list archive at Nabble.com. _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
RE: Newbie: common Syntax error: Operator expectedOoh... Its going to be infinitely... I just copy/paste examples and get the same error message (writing first post I thought that the reason is the same, but now...):
conc([], L, L). conc([H|T], L, [H|T1]):–conc(T,L,T1). Same error message: 6 ?- consult(q). ERROR: c:/users/admin/documents/q.pl:2:0: Syntax error: Operator expected % q compiled 0.00 sec, 0 bytes true. Can you recomend some resources which explores SWI-Prolog syntax or provides some simple but working examples...
|
|
|
|
|
|
RE: Newbie: common Syntax error: Operator expected>Ooh... Its going to be infinitely... I just copy/paste examples and get the
>same error message (writing first post I thought that the reason is the >same, but now...): > >conc([], L, L). >conc([H|T], L, [H|T1]):-conc(T,L,T1). > >Same error message: > >6 ?- consult(q). >ERROR: c:/users/admin/documents/q.pl:2:0: Syntax error: Operator expected >% q compiled 0.00 sec, 0 bytes >true. Change ":-" with ":-". The dash in your example is the problem (it seems a little longer than the default one). >Can you recomend some resources which explores SWI-Prolog syntax or >provides >some simple but working examples... I would recommend going to http://www.swi-prolog.org/ and reading the manual. Sincerely, Mihai Fonoage Mihai Fonoage wrote: > > It should be X =< Y. > > Mihai Fonoage > > -----Original Message----- > From: swi-prolog-admin@... > [mailto:swi-prolog-admin@...] On Behalf Of Vladimir Mihailenko > Sent: Wednesday, October 28, 2009 11:38 AM > To: swi-prolog@... > Subject: Re: [SWIPL] Newbie: common Syntax error: Operator expected > > > Thank you. I used PREDICATES and CLAUSES, because SWI-Prolog IDE properly > highlights it like keywords. Can u say what is wrong with this code: > > min(X, Y, X) :- X <= Y. > min(X, Y, Y) :- Y < X. > > ERROR: c:/users/admin/documents/q.pl:1:0: Syntax error: Operator expected > % q compiled 0.00 sec, 824 bytes > true. > -- > View this message in context: > > 6095829p26096831.html > Sent from the SWI Prolog mailing list archive at Nabble.com. > > _______________________________________________ > SWI-Prolog mailing list > SWI-Prolog@... > https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog > > _______________________________________________ > SWI-Prolog mailing list > SWI-Prolog@... > https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog > > -- View this message in context: http://www.nabble.com/Newbie%3A-common-Syntax-error%3A-Operator-expected-tp2 6095829p26098255.html Sent from the SWI Prolog mailing list archive at Nabble.com. _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
|
|
|
RE: Newbie: common Syntax error: Operator expectedYour question seems answered. The tutorial I used to get started was:
http://www.dbnet.ece.ntua.gr/~adamo/csbooksonline/prolog-notes.pdf It teaches you the basics. I found it online and claim no responsibility or credit for anything in it, but it's easy going and covers the most important things. From then on the SWI-prolog manual gives you the specifics and between that and experimenting you can get nice and far. The most tricky part of prolog programming is probably the mental switch from an imperative to a logical structure, but once you understand that it makes a lot more sense! :P Cheers, Andrew Quoting Vladimir Mihailenko <michailenko@...>: > > Ooh... Its going to be infinitely... I just copy/paste examples and get the > same error message (writing first post I thought that the reason is the > same, but now...): > > conc([], L, L). > conc([H|T], L, [H|T1]):?conc(T,L,T1). > > Same error message: > > 6 ?- consult(q). > ERROR: c:/users/admin/documents/q.pl:2:0: Syntax error: Operator expected > % q compiled 0.00 sec, 0 bytes > true. > > Can you recomend some resources which explores SWI-Prolog syntax or provides > some simple but working examples... > > > Mihai Fonoage wrote: >> >> It should be X =< Y. >> >> Mihai Fonoage >> >> -----Original Message----- >> From: swi-prolog-admin@... >> [mailto:swi-prolog-admin@...] On Behalf Of Vladimir Mihailenko >> Sent: Wednesday, October 28, 2009 11:38 AM >> To: swi-prolog@... >> Subject: Re: [SWIPL] Newbie: common Syntax error: Operator expected >> >> >> Thank you. I used PREDICATES and CLAUSES, because SWI-Prolog IDE properly >> highlights it like keywords. Can u say what is wrong with this code: >> >> min(X, Y, X) :- X <= Y. >> min(X, Y, Y) :- Y < X. >> >> ERROR: c:/users/admin/documents/q.pl:1:0: Syntax error: Operator expected >> % q compiled 0.00 sec, 824 bytes >> true. >> -- >> View this message in context: >> http://www.nabble.com/Newbie%3A-common-Syntax-error%3A-Operator-expected-tp2 >> 6095829p26096831.html >> Sent from the SWI Prolog mailing list archive at Nabble.com. >> >> _______________________________________________ >> SWI-Prolog mailing list >> SWI-Prolog@... >> https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog >> >> _______________________________________________ >> SWI-Prolog mailing list >> SWI-Prolog@... >> https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog >> >> > > -- > View this message in context: > http://www.nabble.com/Newbie%3A-common-Syntax-error%3A-Operator-expected-tp26095829p26098255.html > Sent from the SWI Prolog mailing list archive at Nabble.com. > > _______________________________________________ > SWI-Prolog mailing list > SWI-Prolog@... > https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: Newbie: common Syntax error: Operator expectedOn Oct 29, 2009, at 3:38 AM, Vladimir Mihailenko wrote: > > I have such code which is copy-pasted from book: > > PREDICATES > f(integer, integer) > CLAUSES > f(X, 0) :- X<3, !. > f(X, 2) :- X>=3, X<6, !. > f(X, 4) :- X>=6. That is not Edinburgh/ISO Prolog. That's another language entirely, once called Turbo Prolog. > 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 bytes > true. > (1) Turbo Prolog has static type checking. Edinburgh/ISO Prolog does not. If you really want this, you should be using Mercury instead. Otherwise, drop the first three lines. The differences between Turbo Prolog and Edinburgh/ISO Prolog are by no means limited to the type system; you can expect to make much bigger changes to other code from the book. (2) Prolog makes no syntactic distinction between "input" and "output" arguments, but in this predicate, it seems clear that X is acting as input (because nothing binds it, yet it is tested) and the second argument is output. If that's so, then the cuts are in the wrong place. For this particular predicate, it's not an issue (each clause is fully guarded, the clauses should be reordered without changing the behaviour), but as a general rule, EVEN IN TURBO PROLOG, it is better to postpone output unifications until _after_ the cuts. f(X, Y) :- X < 3, !, Y = 0. f(X, Y) :- X >= 3, X < 6, !, Y = 2. f(X, Y) :- X >= 6, !, Y = 4. > What should I fix to run under SWI-Prolog? Try another book. Clocksin and Mellish, Programming with ISO Prolog, Sterling & Shapiro, The Art of Prolog, but avoid Bratko's book with its rather ugly style. _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: Newbie: common Syntax error: Operator expectedOn Oct 29, 2009, at 4:38 AM, Vladimir Mihailenko wrote: > > Thank you. I used PREDICATES and CLAUSES, because SWI-Prolog IDE > properly > highlights it like keywords. Can u say what is wrong with this code: > > min(X, Y, X) :- X <= Y. > min(X, Y, Y) :- Y < X. > > ERROR: c:/users/admin/documents/q.pl:1:0: Syntax error: Operator > expected > % q compiled 0.00 sec, 824 bytes > true. There are two problems with this. (1) The "equals or less than" operator is spelled '=<' in Prolog, not '<='. This is because Prolog was used very much for things like theorem proving, expert systems, and so on, and the arrows (<= , =>) were far too useful to waste on comparing numbers. (2) Given a call min(X, Y, Z), it is not possible for both clauses to succeed. But Prolog doesn't know that. (I _think_ XSB Prolog does or did know that; I know there was one Prolog that was smart enough to notice complementary goals.) So it is necessary to use a "green" cut. Once again, the output unifications should be done afterwards. min(X, Y, Z) :- X =< Y, !, Z = X. min(X, Y, Z) :- X > Y, !, Z = Y. _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: Newbie: common Syntax error: Operator expectedOn Oct 29, 2009, at 5:59 AM, Vladimir Mihailenko wrote: > conc([], L, L). > conc([H|T], L, [H|T1]):–conc(T,L,T1). There's nothing wrong with that. (Except that it's pointless, because append/3 is built in.) More precisely, it's ugly not to put spaces around ":-" and it's inconsistent to put spaces after the commas in the head but not the body. But it's not _wrong_. The syntax error was presumably earlier in the file. > Can you recomend some resources which explores SWI-Prolog > syntax or provides some simple but working examples... Practically ANY book about Prolog other than a book about Turbo/Visual ``Prolog''. _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: Newbie: common Syntax error: Operator expected> Given a call min(X, Y, Z), it is not possible for both clauses to > succeed. But Prolog doesn't know that. (I _think_ XSB Prolog > does or did know that; I know there was one Prolog that was smart > enough to notice complementary goals.) hProlog is smart enough, if you write the clauses as min(X, Y, Z) :- X =< Y, X = Z. min(X, Y, Z) :- Y < X, Y = Z. But there is nothing "smart" about it, just a couple of 100s of LOC to implement some obvious source to source transformations. If we could supply such a module that can be plugged into the compiler without any further work for Jan, I bet he would use it. Anyone interested to work on this ? Cheers Bart Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: Newbie: common Syntax error: Operator expectedOn Oct 29, 2009, at 10:08 AM, Richard O'Keefe wrote: > > On Oct 29, 2009, at 5:59 AM, Vladimir Mihailenko wrote: > >> conc([], L, L). >> conc([H|T], L, [H|T1]):–conc(T,L,T1). > > There's nothing wrong with that. Whoops. I failed to notice the abuse of Unicode. The character after the colon is not the minus sign it should be. This may be an editor problem. I *should* have noticed the problem because I was unable to paste from the Mail window into a Terminal set to Latin-1. Just recently I've started seeing web pages and e-messages with en-dashes where hyphens or minuses should be. I suspect that it's an editor problem, people pressing the right key and getting the wrong character. I also suspect that it may be Windows- related. I suggest that FIGURE DASH, EN DASH, EM DASH, and HORIZONTAL BAR should be banned from Prolog source code except when quoted. Arguably U+2212 MINUS SIGN should be treated as synonymous with U+002D HYPHEN-MINUS, but that's harder to set up than banning the U+2012..U+2015 range. _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: Newbie: common Syntax error: Operator expectedOn Oct 29, 2009, at 10:25 AM, Bart Demoen wrote: > hProlog is smart enough, if you write the clauses as > > min(X, Y, Z) :- X =< Y, X = Z. > min(X, Y, Z) :- Y < X, Y = Z. Good for it! > > > But there is nothing "smart" about it, just a couple of 100s of LOC to > implement some obvious source to source transformations. That's rather like saying "This knife is not sharp, it's just very good at cutting things." The basic question is whether a Prolog system compiles one clause at a time (as NIP did, for example) or whether it compiles at least a whole predicate at a time. If you are trying to support incremental modifications to predicates, that is, if you are trying to compile dynamic predicates, then clause at a time makes sense. Inserting an implicit cut in the first clause of min/3 is not a good idea if the second clause may be removed and replaced at any time. If you are compiling static predicates, where the entire predicate has to be removed and replaced as a whole, then predicate-at-a-time makes sense. Does hProlog still insert the implicit cut when the predicate is declared to be dynamic? _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: Newbie: common Syntax error: Operator expected> That's rather like saying "This knife is not sharp, it's just very > good at cutting things." Sharpness is a property of knives. Smartness is not a property of Prolog. > Does hProlog still insert the implicit cut when the predicate > is declared to be dynamic? hProlog has no dynamic predicates. Cheers Bart Demoen Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
| < Prev | 1 - 2 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |