prolog

Prolog : Simple question

I want to add any strings user entered into a list run :- write('How many students you have: '),read(x),nl. enterNameOfStudents(x). enterNameOfStudents(x) :- for(A, 1, x, 1),write('Please enter the names of students'),read(A),??????,nl,fail. What do i put in the ?????? portion to ensure that whatever the user enter will go int...

Prolog another simple question

How do i read in char type by users if they are a- , b+ , o+ ? I don't seem to have problem reading in char like a , b , c or d. i am using read(X) . Can someone help me out with this ? Thanks in advance. ...

How to stop repetitions in rules in prolog

In my prolog rule marriedcouple(X,Y) :- parent((X,Z),bornin(_)), parent((Y,Z),bornin(_)), female(X),male(Y); male(X),female(Y), different(X,Y). when a parent has two kids, the couple shows twice. How can we prevent this ? ...

How to avoid repetition in prolog

I get several results with the same outputs. I want to get jack,jane only one time, but I get it two times. How can I avoid this? I tried setof but I couldn't get it done. Please can someone help me on this? ...

Is Prolog the best language to solve this kind of problem?

I have this problem containing some inequations and requirement to minimize a value. After doing some research on the Internet, I came to conclusion that using Prolog might be the easiest way to solve it. However, I never used Prolog before, and I would hate to waste my time learning it just to discover that it is not the right tool for ...

Turning off warnings in swi-prolog

How Can I turn off warnings in swi-prolog. Clauses of XXX/AA are not together in the source-file is very annoying. ...

PROLOG all different

Hello SO, I have a very weird problem with PROLOG. I have used it before, but it's been a while and I'm rusty. I have a list of variables and I need to ensure that none of them are the same. I have tried: use_module(library(bounds)). all_different(A, B, C, D, 6, 8). However, when I try this, I get an error saying that all_different...

Python or Ruby for webbased Artificial Intelligence?

A new web application may require adding Artificial Intelligence (AI) in the future, e.g. using ProLog. I know it can be done from a Java environment, but I am wondering about the opportunities with modern web languages like Ruby or Python. The latter is considered to be "more scientific" (at least used in that environment), but using Go...

Why doesn't 'Q' unify in this PROLOG program

Hello SO, I am writing a PROLOG program in which the variable of interest (Q) refuses to unify. I have gotten around this with a hacky solution (include a write statement). But there has to be a way to make this unify, but for the love of me, I am not able to figure it out. I'd really appreciate any help. Thanks in advance. Here is my...

How can I insert an additional argument after the last argument in a prolog procedure?

I am new to learning prolog, and I want to know, if we have some procedure like father("Nic","Adam"). and I want to write a function that it will add new value to this father("Nic","Adam","something"..) how can I do this? Using list? Or what? ...

SWI-Prolog tokenize_atom/2 replacement?

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

Using recursion an append in prolog

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 == []) ...

Creating a 'remove member' function in prolog

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

amzi prolog + eclipse question

hey guys i have a question regarding amzi prolog with eclipse, Im running a .pro file which executes a breadth first search and if queue gets too long, the following error message appears: system_error 1021 Control stack full. Compile code or increase .cfg parameter 'control' If so, how may i run the compiled code under eclip...

Prolog remove function - almost working

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

search all paths and the shortest path for a graph - Prolog

Hi , I have a problem in my code with turbo prolog wich search all paths and the shortest path for a graph between 2 nodes the problem that i have is to test if the node is on the list or not exactly in the clause of member and this is my code : /* 1 ---- b ---- 3 --- | --- --- ...

Prolog Program for a recordings database

I have three types of facts: album(code, artist, title, date). songs(code, songlist). musicians(code, list). Example: album(123, 'Rolling Stones', 'Beggars Banquet', 1968). songs(123, ['Sympathy for the Devil', 'Street Fighting Man']). musicians(123, [[vocals, 'Mick Jagger'], [guitar, 'Keith Richards', 'Brian Jones']]. I need t...

Is there a way to make swi prolog print its currently working inference tree?

It would be a great help on my course. ...

Prolog: Finding the Nth Element in a List

I am attempting to locate the nth element of a List in Prolog. Here is the code I am attempting to use: Cells = [OK, _, _, _, _, _] . ... next_safe(_) :- facing(CurrentDirection), delta(CurrentDirection, Delta), in_cell(OldLoc), NewLoc is OldLoc + Delta, nth1(NewLoc, Cells, SafetyIdentifier), SafetyIdentifier = OK . Basically, I a...

Prolog: Not executing code as expected.

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