So I'm trying to test my the predicate reduce/4 defined as following:
:- op(20,xfy,?=).
reduce(R,X ?=Y,P,Q) :-
R=rename,
regle(X ?=Y,R),
length(P,N),
trouve(Y,P,N,M),
remove(N,M,P,Q).
but i keep getting this error:
?- reduce(rename,X ?= Y,[?=(X,Y),?=(f(a),g(Z)),?=(X,a)],Q].
ERROR: Syntax error: Illegal start of term
ERROR: reduce(rename,X ?= Y,[?=(X,Y),?=(f(a),g(Z)),?=(X,a)],
ERROR: ** here **
ERROR: Q] .
I'm new to Prolog so maybe it is something stupid.
You use ] instead of ) to close the bracket of reduce
reduce(rename,X ?= Y,[?=(X,Y),?=(f(a),g(Z)),?=(X,a)],Q].
% ^open ^close
You can fix this with:
?- reduce(rename,X ?= Y,[?=(X,Y),?=(f(a),g(Z)),?=(X,a)],Q).
I cannot validate if this solves your problem, because you did not provide a definition for regle/2, etc. But the fact that I get a semantic error, seems to solve the syntax error nevertheless.
Related
I am writing a predicate to print true if a list contains 3 copies of an element and also to print the element. Also the predicate should print alternate solutions if they exist.
The predicate which I have written -
hasTriplicate(List):-hasTriplicateAcc(List,Element,0).
%hasTriplicateAcc is wrapped by predicate hasTriplicate since I wanted the arity of hasTriplicate to be 1.
hasTriplicateAcc(_,Element,3):-write(Element).
hasTriplicateAcc([H|T],H,Ct):-hasTriplicateAcc(T,H,Ct1),Ct1 is Ct+1.
hasTriplicateAcc([Z|T],H,Ct):-hasTriplicateAcc(T,H,Ct),Z=\=H.
The output
hasTriplicate([1,1,1]).
11
ERROR: Arguments are not sufficiently instantiated
ERROR: In:
ERROR: [11] 3 is _10188+1
ERROR: [10] hasTriplicateAcc([1,1],1,_10218) at c:/users/user/desktop/code/hastriplicate.pl:3
ERROR: [9] hasTriplicateAcc([1,1|...],1,0) at c:/users/user/desktop/code/hastriplicate.pl:3
ERROR: [7] <user>
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
Exception: (10) hasTriplicateAcc([1, 1], 1, _10332)
I don't understand the error. It would be good if anyone tells me how to correct my code for the predicate.
I think this solution will work .
hascountminimal(_,_,0):-true,!.
hascountminimal([E|L],E,N):- ! , N1 is N - 1 , N >= 1 , hascountminimal(L,E,N1) .
hascountminimal([_|L],E,N):- hascountminimal(L,E,N).
intripple(L,E):-hascountminimal(L,E,3),write(E).
What is wrong in this code
frequency(f1).
frequency(f2).
frequency(f3).
allocation(z1,z2,z3,z4,z5,z6,z7,z8) :-
frequency(z1), frequency(z2), frequency(z3), frequency(z4), frequency(z5), frequency(z6), frequency(z7), frequency(z8),
z1\==z2, z1\==z3, z2\==z4, z2\==z3, z3\==z4, z3\==z6, z4\==z5, z4\==z6, z4\==z7, z6\==z7, z6\==z8.
?- allocation(f1,f2,f3,f1,f2,f3,f2,f3).
syntax error: . or operator expected after expression
The following code highlighting should make it clear why the goal allocation(f1,f2,f3,f1,f2,f3,f2,f3) cannot succeed:
allocation(Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8) :-
dif(Z1,Z2), dif(Z1,Z3),
dif(Z2,Z3), dif(Z2,Z4),
dif(Z3,Z4), dif(Z3,Z6),
dif(Z4,Z5), dif(Z4,Z6), dif(Z4,Z7),
dif(Z6,Z7), dif(Z6,Z8),
maplist(frequency, [Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8]).
Note the use of dif/2 instead of (\==)/2 in the code above?
prolog-dif preserves logical-purity, for easier debugging!
I am learning Prolog and .(a,[]) == [a]. should return true in SWI-Prolog, but it gives me an error saying
ERROR: Type error: `dict' expected, found `a' (an atom)
ERROR: In:
ERROR: [11] throw(error(type_error(dict,a),_4020))
ERROR: [10] '$type_error'(dict,a) at /Applications/SWI-
Prolog.app/Contents/swipl/boot/init.pl:3369
ERROR: [9] '$dicts':'.'(a,[],_4086) at /Applications/SWI-
Prolog.app/Contents/swipl/boot/dicts.pl:46
ERROR: [8] '<meta-call>'(user:(...,...)) <foreign>
ERROR: [7] <user>
Anyone knows how to fix this?
Start the SWI Prolog executable with the --traditional command line option (comment due to user:false).
Then it works:
1 ?- .(a,[]) == [a].
true.
2 ?- current_prolog_flag( traditional, X).
X = true.
3 ?- set_prolog_flag( traditional, false).
ERROR: set_prolog_flag/2: No permission to modify flag `traditional'
4 ?-
This is mentioned in the documentation here (see "traditional", near the bottom of the page).
As can be seen, attempting to change it from within the running SWI session, fails.
I am using gprolog allong with gplc and I get fatal error: redefining built-in predicate member/2 when I try to compile the following code. I also get uncaught exception: error(existence_error(procedure,member/0),member/0) when I try to consult the same code.
Code:
member(X,[X|T]).
member(X,[H|T]) :- member(X,T).
The query I give:
| ?- member(X,[a,b,c,d,e]).
X = a ? ;
uncaught exception: error(existence_error(procedure,member/0),member/0)
I want to load rdf url from this rule:
getActorFilms(Actor_Name,Films):-
my_replace(Actor_Name, ' ', '_', Correct_Syntax_Of_Actor_Name),
string_concat('http://dbpedia.org/data/',Correct_Syntax_Of_Actor_Name, URL_TO_LOAD),
string_concat(URL_TO_LOAD,'.rdf',RDF_URL),
rdf_load(RDF_URL),
rdf(Films, 'http://dbpedia.org/ontology/starring', Object)
.
when the input is e.g. for an example 'Hugh Jackman'
it tells the error:
ERROR: [Thread pdt_console_client_0_Default Process] source_sink `http://dbpedia.org/data/Hugh_Jackman.rdf' does not exist
I'm really concerned about the ` character between http and source_sink
I think it should be '
although the url is correct, so what to do with that error?
You should pass an atom to rdf_load, not a string. This behavior (the misleading error message, not accepting a string) is probably a bug.
This works for me:
?- use_module(library('semweb/rdf_db')).
true.
?- use_module(library('semweb/rdf_http_plugin')).
true.
?- rdf_load('http://dbpedia.org/data/Hugh_Jackman.rdf').
% Parsed "http://dbpedia.org/data/Hugh_Jackman.rdf" in 0.02 sec; 371 triples
true.
?- string_to_atom(S, 'http://dbpedia.org/data/Hugh_Jackman.rdf'), rdf_load(S).
ERROR: source_sink `http://dbpedia.org/data/Hugh_Jackman.rdf' does not exist
I hope this solves your problem.