swi-prolog

Prolog instantiation error?

Hello guys, I'm stuck with some sort of error which i don't really understand in prolog. I get this error when calling a rule(which seems to work sometimes?) : error(instantiation_error,Var0) Can anyone explain to me what this means? so i have two rules: special(X) :- user(X, Days), Days >= 20. special(X) :- premiumuser(X). user(gu...

argv Memory Allocation

I was wondering if someone could tell me what I am doing wrong that I get this Unhandled Exception error message: 0xC0000005: Access violation reading location 0x0000000c. with a green pointer pointing at my first Prolog code (fid_t): Here is my header file: class UserTaskProlog { public: UserTaskProlog( ArRobot* r );...

Prolog - Finding the current directory, relative directory for 'tell' predicate

I'm having trouble trying to figure out how to get prolog to spit out a text file where I want it to. I'm currently doing a bunch of operations and then using tell('output.txt') to record the output. Now the problem is that when I do this, it creates this file in the SWI \bin\ folder. I was wondering if there's a way to make it create...

Class Problem (c++ and prolog)

I am using the C++ interface to Prolog (the classes and methods of SWI-cpp.h). For working out a simple backtracking that john likes mary and emma and sara: likes(john, mary). likes(john, emma). likes(john, ashley). I can just do: { PlFrame fr; PlTermv av(2); av[0] = PlCompound("john"); PlQuery q("likes", av); while (q.nex...

Prolog: Sentence Parser Problem

Hey guys, Been sat here for hours now just staring at this code and have no idea what I'm doing wrong. I know what's happening from tracing the code through (it is going on an eternal loop when it hits verbPhrase). Any tips are more then welcome. Thank you. % Knowledge-base det(the). det(a). adjective(quick). adjective(brown). adject...

Prolog returns Out = _G431 when it suppose to return a list of lists

createSchedule([[math109]], fall, Out). [[cs485, cs485], [cs355, cs355, cs462, cs462, cs462], [cs345, cs345, cs352, cs352, cs352, cs362, cs362, cs362, cs396, cs396, cs396], [cs330, cs330, cs330], [cs255, cs255, cs255, cs268, cs268], [math114, cs245, cs245], [math112, cs145, cs146], [math109]] Out = _G431 this is what prolog returns an...

PREDICATE( name, arity )

Suppose I have the program below: #include files PREDICATE( add, 3 ) { return A3 = (long)A1 + (long)A2; } int main( int argc, char** argv ) { PlEngine e( argv[0] ); PlCall( "consult('myFile.pl')" ); PL_halt( PL_toplevel() ? 0 : 1 ); } When I compile it, it links Prolog and C++ and then launches the Prolog command pro...

prolog list manipulating

I have the following code which basically needs to add a list as an item to a greater list. So NewBoardsList should contain all the boards generated in the moves_generate_board function. The problem is that i get a False in Prolog. Any help ? moves((Colour,_),Board,NewBoardsList):- other_colour(Colour,OtherColour), fin...

Problem when reading backslash in Prolog

I'm writing a lexer in Prolog which will be used as a part of functional language interpreter. Language spec allows expressions like for example let \x = x + 2; to occur. What I want lexer to do for such input is to "return": [tokLet, tokLambda, tokVar(x), tokEq, tokVar(x), tokPlus, tokNumber(2), tokSColon] and the problem is, that P...

SWI-Prolog: how to load rdf triples using semweb/rdf_db library?

Hi, I have a rdf file (file.trp) in n-triples format, where each line is a well-formed triple: "subject predicate object ." I tried to use rdf_load in semweb/rdf_db to load it into memory, but failed. Here is what I tried: ?- rdf_load('file.trp'). ?- rdf_load('file.trp', [format(triples)]). The trace shows that the goal fails at: ...

Prolog, fail and do not backtrack.

Is there any build-in predicate in SWI-Prolog that will always fail AND prevent machine from backtracking - it is stop the program from executing immediately (this is not what fail/0 does)? I could use cuts, but I don't like them. Doing something like !, fail is not a problem for me, but in order to accomplish what I want, I would hav...

What does [a|b|c] evaluate to in SWI-Prolog?

The pipe operator in prolog returns one or more atomic Heads and a Tail list. ?- [a,b,c] = [a,b|[c]]. true. Nesting multiple pipes in a single match can be done similar to this: ?- [a,b,c] = [a|[b|[c]]]. true. What does the statement [a|b|c] infer about a, b and c? EDIT So far, all I can deduce is: ?- [a,b,c] = [a|b|c]. false....

Prolog homework problem?

the problem is ; we have a funtion take 3 argument, like; func ( [[0, 0, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0]], (1, 1), X ) the first one is nested list, which is show 5x5 matrix and 1s means it is full, 0 means empty and, the second parameter (1,1) our starting point 1st row 1st column, the 3rd p...

How to solve this logical problem with Prolog?

That's my first question so please be tolerant. I've logical problem to write in prolog/CLP: "It is known only one character is telling the truth. Mr April says Mr May tells lies. Mr May says Mr June tells lies. Mr June says that both Mr April and Mr May tell lies. Write a program which determines who is telling the trut...

PROLOG - How to implement stack?

I have to implement stac in Prolog, but WITHOUT using list. Each element of stack should point to before element. Is there possible to do it? Could I define rules in runtime program? ( like: element('foo','bar'). where foo is content of element end bar is pointer to another? ...

Prolog Beginner: How to unify with arithmentic comparison operators or how to get a set var to range of values

I am new to prolog. I need to write an integer adder that will add numbers between 0-9 to other numbers 0-9 and produce a solution 0-18. This is what I want to do: % sudo code add(in1, in2, out) :- in1 < 10, in2 < 10, out < 18. I would like to be able to call it like this: To Check if it is a valid addition: ?- add(1,...

Prolog Beginner: Trivial Example that I cannot get to work.

I have some prolog. The lessThanTen and example predicates work as expected however the exam predicate does not work. lessThanTen(9). lessThanTen(8). lessThanTen(7). lessThanTen(6). lessThanTen(5). lessThanTen(4). lessThanTen(3). lessThanTen(2). lessThanTen(1). lessThanTen(0). % This should always return 5. example(X) :- X i...

Prolog: How to make three lists the same lenght (by adding leading zeros)

I am writing a prolog program to solve a problem. The problem takes three lists as input: solve( [L|Lr] , [R|Rr] , [S|Sr] ) :- Unfortunately the lists all need to be equal length for the program to work. So these work: ?- solve( [A, B, C, D] , [1, 3, 5, 6], [E, F, G, H]). ?- solve( [1] , [2], [3]). But these do not: ?- s...

Prolog Beginner: How to make unique values for each Variable in a predicate.

I have a prolog predicate: Add( [A|B] , Answer ) :- ... ~ Add everything in the list to come up with answer ... I would now like to implement AddUnique that would return unique values for everything in the list except when I give it the variable twice. Here are somethings that are logically equivalent: ?- AddUnique...

Prolog Best Practice: checking if a variable is already bound.

I posted this solution to an question but ony left me a comment saying: Predicates to check if "variable" is free or already bound should change strategy for deriving right unifications for other "variables" (i.e. speed up, or make possible to derive them). The same for dynamic predicates - they can be used to speed-up ...