Prolog: How to produce a multiple answer output?
Given: fruitid('Apple', 'Granny Smith', 1). How would I go about creating the clause: print_fruit_details(FruitID) :- Which would output 'Apple' and 'Granny Smith' given the input 1. Thanks, JAS ...
Given: fruitid('Apple', 'Granny Smith', 1). How would I go about creating the clause: print_fruit_details(FruitID) :- Which would output 'Apple' and 'Granny Smith' given the input 1. Thanks, JAS ...
Given: fruitid('Apple', 'Granny Smith', 1). fruitid('Apple', 'Cox', 2). fruitid('Pear', 'Bartlett', 3). How would I go about finding only unique items for instance: is_unique(FruitName):- In the example clauses the answer would be Pear. I'm also trying to add error handling to my code, so in this instance if an input is: is_uniqu...
A simple question, how would I go about declaring a clause which would produce the number specified +1 +2 and +3? I have tried: addup(Thenumber,Thenumber+1). addup(Thenumber,Thenumber+2). addup(Thenumber,Thenumber+3). but when I run it with say, Thenumber=5, it just returns 5+1 5+2 5+3. I have tried using 'is' to force it to evaluate ...
Given: fruitid('Apple', 'Granny Smith', 1). fruitid('Pear', 'Bartlett', 2). If I had the clause type_of_fruit(ID):- fruitid(Fruit, _, ID), write(Fruit). How could I implement a method to catch erroneous inputs? For instance fruitid(5). Thanks. AS ...
I have a Prolog file (Hanoi.pl) containing the code for solving the Hanoi Towers puzzle: hanoi( N ):- move( N, left, middle, right ). move( 0, _, _, _ ):- !. move( N, A, B, C ):- M is N-1, move( M, A, C, B ), inform( A, B ), move( M, C, B, A ). inform( X, Y ):- write( 'move a disk from ' ), write( X ), w...
I was wondering, I am aware you can use assert to add facts or rules or whatever if you have declared the predicate to be -:dynamic, but this only allows the changes that are made to be kept in that session only, e.g. if you close the prolog window then the database changes are lost. So I was wondering, is there any way of making it so...
How Can I turn off warnings in swi-prolog. Clauses of XXX/AA are not together in the source-file is very annoying. ...
We are using swi-prolog to run our testcases. Whenever the test starts, I am opening the connection to MYSQL database and storing the Name of the Test hat is being done and then closing the DB. These tests run for about 2 days continuously. After the tests are done, the results basically gets stored in folder in the server. There is a pr...
What I need to do is to break atom to tokens. E. g.: tokenize_string('Hello, World!', L). would unify L=['Hello',',','World','!']. Exactly as tokenize_atom/2 do. But when I try to use tokenize_atom/2 with non-latin letters it fails. Is there any universal replacement or how I can write one? Thanks in advance. ...
Lets say that I would like to construct a list (L2) by appending elements of another list (L) one by one. The result should be exactly the same as the input. This task is silly, but it'll help me understand how to recurse through a list and remove certain elements. I have put together the following code: create(L, L2) :- (\+ (L == []) ...
I read that Swi Prolog IDE - Eclipse - in Linux(Ubuntu) is possible. However I couldn't get the installed Eclipse to 'use' swi Prolog. Please help ...
I am new to prolog and I'm trying to to create function that will simply remove all instances of an element from a list. The following code is what I have so far: remove([H|T], E, L2) :- (\+ ([H|T] == []) -> (H == E -> remove(T, E, L2) ; append(L2, H, L2), remove(T, E, L2) ) ; append(L2, []) ). When I run ...
I want to load this simple something into my Editor: Write:-repeat,write("hi"),nl,fail. So that it prints "hi". What should I do? I'm currently trying to do File->New and Saving a file named Write into E:\Program Files\pl\xpce\prolog\lib When doing the query: ?-Write. It's printing: 1 ?- Write. % ... 1,000,000 ............ 10,0...
I have a large Prolog program with lots of predicates. I need to connect to this Prolog code from C++ (VS2008) to obtain certain query results. So I am not trying to embed Prolog in C++ as a logicasl engine, but for my C++ program to connect to my Prolog code, consult (compile) it, obtain query results, and pass them back to C++. Runnin...
The following predicate is remove(L, X, R), where L is a list, X is an element to remove from the list. The code returns the correct list, however it always also returns false afterwards. I can't find the place where two of the rules can be applied during runtime. remove([],X,[]) :- !. remove([X|T],X,L1) :- remove(T,X,L1). remove([H...
I would like to work out a number's factorial. My factorial rule is in a Prolog file and I am connecting it to a C++ file. Can someone please tell me what is wrong with my interfacing C++ to Prolog? my factorial.pl file: factorial( 1, 1 ):- !. factorial( X, Fac ):- X > 1, Y is X - 1, factorial( Y, New_Fac ), Fac i...
Upon loading into a C++ program a Prolog program that contains the command 'send' (xpce graphics), I get error messages of type: Syntax Error: Operator Expected. Here is an example command that causes the errors: send( Dialog, append, button(continue, message(@prolog, clear_my_blackboard)) ), I used to get the same errors when I us...
It would be a great help on my course. ...
Basically I am attempting to have an AI agent navigate a world based on given percepts. My issue is handling how the agent moves. Basically, I have created find_action/4 such that we pass in the percepts, action, current cell, and the direction the agent is facing. As it stands the entire code looks like: http://wesnoth.pastebin.com/kdNv...
Let's say I have the following Prolog knowledge base: likes( john, mary ). likes( john, emma ). likes( john, ashley ). If I compose the following C code: #include... term_t tv; term_t tu; term_t goal_term; functor_t goal_functor; int main( int argc, char** argv ) { argv[ 0 ] = "libpl.dll"; PL_initialise( 1, argv ); PlCa...