prolog

Unexpected output of a Prolog script

leftHand(empty). rightHand(empty). inHands :- write("Left hand:"), nl, leftHand(X), tab(2), write(X), nl, nl, write("Right hand:"), rightHand(Y), tab(2), write(Y), nl. I expect inHands. to return something like this: Left hand: empty Right hand: empty However, this is what I saw:...

load data between prolog and db2

Hi , I am just learning prolog. I have a task ahead. I have to insert some data in to a database like Db2 express c v9.7.1 using Prolog ODBC INterface. I know there are some example predicates(SWI-PROLOG) by documentation swi-prolog home open_wordnet :- odbc_connect('WordNet', _, [ user(jan), ...

Othello (Reversi) game, flipping pieces, Prolog

I am implementing Othello game in Prolog. The game board is represented as list of lists. I am facing a problem with flipping pieces after making a move. My strategy is to look in all 8 directions from position where I placed my piece (say black), and find the enclosing black piece and flip every white piece between my pieces. So, I ...

Remove duplicates in list (Prolog)

I am completely new to Prolog and trying some exercises. One of them is: Write a predicate set(InList,OutList) which takes as input an arbitrary list, and returns a list in which each element of the input list appears only once. Here is my solution: member(X,[X|_]). member(X,[_|T]) :- member(X,T). set([],[]). set([H|T],[H...

Random items in Prolog

I know I can do X is random(10). to get a random number from 0 to 10, but is there a similar command to get a random matching item? ...

XSB Prolog - How can I consult a .p file?

Hey guys, this should be quite simple to answer.... Im using XSB Prolog...trying to load a .p prolog database I have a file xxx.P in directory C:\XSB So in XSB I type ?consult('xxx.p'). and i get: cannot find the file or module xxx.p i've tried moving the p file to the same directory as the XSB executable but no luck. Any ideas...

Prolog rule help

Dear good people, I am new to Prolog and am experimenting around with some stuff, in particular i'm thinking about how to do a certain thing in prolog. I am aware of facts and rules, facts being something of the sort specialCustomer(x). //person x is a specialcustomer and rules: totalSpend(x,500) :- specialCustom...

Prolog: Recognize a^n b^(n+1) language for n >= 1

I understand that I need to figure out my own homework, but seeing that noone in the class can figure it out, I need some help. Write a Prolog program such that p(X) is true if X is a list consisting of n a's followed by n+1 b's, for any n >= 1. ...

Program and Data are the Same in Prolog?

I have heard that in Prolog, program and data are the same thing. What does that mean? ...

Prolog problem help.

I am trying to learn prolog and have come across a problem that I can't figure out. The problem is to write a prolog predicate that takes all the numbers of a list that are less than a given number and put them into a list that will be returned. For example: input: findNum(5, [5, 3, 5, 6, 4, 5], Y) output: Y = [3, 4] Everything I've t...

Prolog - Declaring arithmetic clauses

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 ...

Prolog homework: how to parse a list of 'bits' representing a numeric value into a decimal representation?

Okay, so I have another question on a prolog homework problem I am struggling with. The problem goes as follows: Write a Prolog program that will take a list representing the bits of a binary number, and return the decimal value of the integer that the list represents. Example: valueof([1,1,0,1],X). X = 13 So here's what I hav...

Prolog homework help.

Okay, my last prolog question. It's the common geneaology problem. I am suppose to take a list of facts and have a function called descendant that will return a list that has all the descendants. For example: Given the rules: parent('Bob', 'Tim'). parent('Joe', 'Bob'). The function call: descendant('Joe', X). should re...

Question about prolog

Hello people, I am trying to create some rules and facts on a certain situation. The situation is such that if a user owes money then he is said to be in debt after 5 days if it is not repaid, if he doesn't then he is a normal person. So far i'm experimenting with something like: I have two rules: debtpayment_unfulfilled(X) :- owes_mo...

Prolog open source community, code repository,blogs,forums

I find useful groups.google.com/group/comp.lang.prolog/topics cs.cmu.edu/afs/cs/project/ai-repository/ai/areas/ google.com/Top/Computers/Programming/Languages/Prolog/Implementations/ allisons.org/ll/Logic/Prolog/Examples/ prolog.info/ Maybe there are else useful links? Please share it :-) ...

Prolog Rule - need help with getting something working?

Hello people.. I want to write a rule in prolog, which basically says If a user X has not paid amount Y within 7 days then it will evaluate to payment_outstanding(X). so far i have something like this: debtpayment_unfulfilled(X) :- owes_money(X, Amountowed, Amountpaid, Days), Days > 7 ,Amountowed > Amountpaid. owes_money(bob, 500, 0,...

Simple question - XSB Prolog

Hello! I'm diving into the world of prolog headfirst but I seem to have hit shallow water! I'm looking at database manipulation in prolog with regards to this tutorial:Learn Prolog Now! It states that I can see my database by entering listing So i tried it and it should basically output everything in my .P file(facts, rules), but thi...

2 Questions 1.How to find differences in lists in prolog and 2. Determine if the lists are the same (same elements but doesnt have to have the same order)

1.If i have two lists say A and B made upp of different letters. [b,a,c] in list A and [b,d,c,e] in list B how can i get prolog to give me C,which is a list of elements that A has which are not included in list B Ex. So if i type difference([b,a,c],[b,d,c,e],C). I want the answer to read: C=[a] If i have two lists where list A is ma...

"dynamic" predicate in prolog

If I want to make a rule dynamic so i can use assert after the database file has been loaded, how do i do it? I'm using XSB Prolog at the moment, the file is something like this: :- dynamic likes/2 likes(mary,tom) when i try to consult the file with XSB i get an error: ? consult('D:\file.P). not permitted to assert to static predica...

Prolog - ASSERT and RETRACT

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...