Search Results

Search found 217 results on 9 pages for 'sicstus prolog'.

Page 4/9 | < Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >

  • Display radio buttons in prolog xpce

    - by Ben03
    I created a menu with Radio Buttons in XPCE prolog, but my radio buttons are showing on the same line, and I want to have each one on a separate line. My code is the following: new(D, dialog('title')), send(D, size, size(500,500)), send(D, append, new(Op, menu(options, marked))), send(Op, append, option1), send(Op, append, option2), send(Op, append, option3), send(Op, size, size(300,300)), send(D, display, Op, point(100, 40)), send(D, append(new(B1,button(ok, message(D, return, Op?selection))))), send(D, display, B1, point(100, 100)), send(D, append(button(cancel, message(D, return, @nil)))), send(D, default_button(ok)), get(D, confirm, Rval), free(D). Thanks in advance

    Read the article

  • Help With Prolog Lists

    - by BeginnerPro
    Hi, Im new to Prolog and was looking for some assistance. What i am trying to do is basically get the some of the list of list, if that makes sense? lol What i am trying to achieve is.... sum([ [1,2],[3,4],[5,6] ]). should return: Number Of Lists: 3 List 1 3 List 2 7 List 3 11....etc I can get the Number of Lists which is fairly simple but im not quite sure how to loop through the List and then for each List add the number up. Am i making this more complicated than it actually is? lol! If anyone can help me or point me in the general direction that would be great. Thanks in advance

    Read the article

  • Reading in multiple words for prolog

    - by prolog123456789
    Im running prolog via poplog on unix and was wondering if there was a way to read in multiple words (such as encase it into a string). For instance, read(X) will only allow X to be 1 term. However, if I encase the user input with "", it will return a list of character codes, is this the correct method as I can not find a way to convert it back to a readable string. I would also like to be able to see if the multiworded string contains a set value (for instance, if it contains "i have been") and am unsure of how i will be able to do this as well.

    Read the article

  • Prolog Family tree

    - by Tania
    Hi I have a Question in prolog , I did it but its not showing answers When i ask about the brothers,sisters,uncles,aunts This is what I wrote, what's wrong ? /*uncle(X, Y) :– male(X), sibling(X, Z), parent(Z, Y).*/ /*uncle(X, Y) :– male(X), spouse(X, W), sibling(W, Z), parent(Z, Y).*/ uncle(X,Y) :- parent(Z,Y), brother(X,Z). aunt(X,Y) :- parent(Z,Y), sister(X,Z). sibling(X, Y) :- parent(Z, X), parent(Z, Y), X \= Y. sister(X, Y) :- sibling(X, Y), female(X). brother(X, Y) :- sibling(X, Y), male(X). parent(Z,Y) :- father(Z,Y). parent(Z,Y) :- mother(Z,Y). grandparent(C,D) :- parent(C,E), parent(E,D). aunt(X, Y) :– female(X), sibling(X, Z), parent(Z, Y). aunt(X, Y) :– female(X), spouse(X, W), sibling(W, Z), parent(Z, Y). male(john). male(bob). male(bill). male(ron). male(jeff). female(mary). female(sue). female(nancy). mother(mary, sue). mother(mary, bill). mother(sue, nancy). mother(sue, jeff). mother(jane, ron). father(john, sue). father(john, bill). father(bob, nancy). father(bob, jeff). father(bill, ron). sibling(bob,bill). sibling(sue,bill). sibling(nancy,jeff). sibling(nancy,ron). sibling(jell,ron). And one more thing, how do I optimize the rule of the brother so that X is not brother to itself.

    Read the article

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

    - by prologian
    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 --- | --- --- | ----- a |5 d --- | ----- --- | --- 2 --- | --- 4 -- c -- for example we have for b--->c ([b,c],5) , ([b,a,c],3) and ([b,d,c],7) : possible paths. ([b,a,c],3) : the shortest path. */ DOMAINS list=Symbol * PREDICATES distance(Symbol,Symbol) path1(Symbol,Symbol,list,integer) path(Symbol,Symbol,list,list,integer) distance(Symbol,list,integer) member(Symbol,list) shortest(Symbol,Symbol,list,integer) CLAUSES distance(a,b,1). distance(a,c,2). distance(b,d,3). distance(c,d,4). distance(b,c,5). distance(b,a,1). distance(c,a,2). distance(d,b,3). distance(d,c,4). distance(c,b,5). member(X, [Y|T]) :- X = Y; member(X, T). absent(X,L) :-member(X, L),!,fail. absent(_,_). /*find all paths*/ path1(X, Y, L, C):- path(X, Y, L, I, C). path(X, X, [X], I, C) :- absent(X, I). path(X, Y, [X|R], I, C) :- distance(X, Z, A) , absent(Z, I), path(Z, Y, R, [X|I] ,C1) , C=C1+A . /*to find the shortest path*/ shortest(X, Y, L, C):-path(X, Y, L, C),path(X, Y, L1, C1),C<C1.

    Read the article

  • Recursion Problems in Prolog

    - by Humble_Student
    I'm having some difficulties in prolog, I'm trying to write a predicate that will return all paths between two cities, although at the moment it returns the first path it finds on an infinite loop. Not sure where I'm going wrong but I've been trying to figure this out all day and I'm getting nowhere. Any help that could be offered would be appreciated. go:- repeat, f([],0,lon,spa,OP,OD), write(OP), write(OD), fail. city(lon). city(ath). city(spa). city(kol). path(lon,1,ath). path(ath,3,spa). path(spa,2,kol). path(lon,1,kol). joined(X,Y,D):- path(X,D,Y);path(Y,D,X). f(Ci_Vi,Di,De,De,PaO,Di):- append([De],Ci_Vi,PaO), !. f(Cities_Visited,Distance,Start,Destination,Output_Path,Output_Distance):- repeat, city(X), joined(Start,X,D), not_member(X,Cities_Visited), New_Distance is Distance + D, f([Start|Cities_Visited],New_Distance,X,Destination,Output_Path,Output_Distance). not_member(X,List):- member(X,List), !, fail. not_member(X,List). The output I'm expecting here is [spa,ath,lon]4 [spa,kol,lon]3. Once again, any help would be appreciated. Many thanks in advance.

    Read the article

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

    - by inspectorG4dget
    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 code (I have annotated wherever I have excluded code for brevity) :- use_module(library(bounds)). :- use_module(library(lists)). solve([17],Q,_,_,_):- write(Q). %this is the hacky workaround solve(L,Q,1,3,2) :- jump(L,Q,N,1,3,2,R), solve(N,R,S,D,M), member([S|[D|[M|[]]]],[[1, 3, 2], [1, 9, 4], [2, 10, 5] this list contains 76 items - all of which are lists of length 3. I have omitted them here for the sake of brevity]). % there are about 75 other definitions for solve, all of which are structured exactly the same. The only difference is that the numbers in the input parameters will be different in each definition jump(L,Q,N,S,D,M,R):- member(S,L), not(member(D,L)), member(M,L), delete(L,S,X), delete(X,M,Y), append(Y,[D],N), append(Q,[[S,D]],R). cross_sol(Q) :- solve([5,9,10,11,17,24],[],S,D,M), member([S,D,M], [ I have edited out this list here for the sake of brevity. It is the same list found in the definition of solve ]). For some reason, Q does not unify. Please help!

    Read the article

  • Factorial in Prolog and C++

    - by Joshua Green
    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++ code. Can someone tell me what is wrong with my C++ interface please? % factorial.pl factorial( 1, 1 ):- !. factorial( X, Fac ):- X > 1, Y is X - 1, factorial( Y, New_Fac ), Fac is X * New_Fac. // factorial.cpp # headerfiles term_t t1; term_t t2; term_t goal_term; functor_t goal_functor; int main( int argc, char** argv ) { argc = 4; argv[0] = "libpl.dll"; argv[1] = "-G32m"; argv[2] = "-L32m"; argv[3] = "-T32m"; PL_initialise(argc, argv); if ( !PL_initialise(argc, argv) ) PL_halt(1); PlCall( "consult(swi('plwin.rc'))" ); PlCall( "consult('factorial.pl')" ); cout << "Enter your factorial number: "; long n; cin >> n; PL_put_integer( t1, n ); t1 = PL_new_term_ref(); t2 = PL_new_term_ref(); goal_term = PL_new_term_ref(); goal_functor = PL_new_functor( PL_new_atom("factorial"), 2 ); PL_put_atom( t1, t2 ); PL_cons_functor( goal_term, goal_functor, t1, t2 ); PL_halt( PL_toplevel() ? 0 : 1 ); }

    Read the article

  • Learn Prolog Now! DCG Practice Example

    - by Timothy
    I have been progressing through Learn Prolog Now! as self-study and am now learning about Definite Clause Grammars. I am having some difficulty with one of the Practical Session's tasks. The task reads: The formal language anb2mc2mdn consists of all strings of the following form: an unbroken block of as followed by an unbroken block of bs followed by an unbroken block of cs followed by an unbroken block of ds, such that the a and d blocks are exactly the same length, and the c and d blocks are also exactly the same length and furthermore consist of an even number of cs and ds respectively. For example, ε, abbccd, and aaabbbbccccddd all belong to anb2mc2mdn. Write a DCG that generates this language. I am able to write rules that generate andn, b2mc2m, and even anb2m and c2mndn... but I can't seem to join all these rules into anb2mc2mdn. The following are my rules that can generate andn and b2mc2m. s1 --> []. s1 --> a,s1,d. a --> [a]. d --> [d]. s2 --> []. s2 --> c,c,s2,d,d. c --> [c]. d --> [d]. Is anb2mc2mdn really a CFG, and is it possible to write a DCG using only what was taught in the lesson (no additional arguments or code, etc)? If so, can anyone offer me some guidance how I can join these so that I can solve the given task?

    Read the article

  • Four-color theorem in Prolog (using a dynamic predicate)

    - by outa
    Hi, I'm working on coloring a map according to the four-color theorem (http://en.wikipedia.org/wiki/Four_color_theorem) with SWI-Prolog. So far my program looks like this: colour(red). colour(blue). map_color(A,B,C) :- colour(A), colour(B), colour(C), C \= B, C \= A. (the actual progam would be more complex, with 4 colors and more fields, but I thought I'd start out with a simple case) Now, I want to avoid double solutions that have the same structure. E.g. for a map with three fields, the solution "red, red, blue" would have the same structure as "blue, blue, red", just with different color names, and I don't want both of them displayed. So I thought I would have a dynamic predicate solution/3, and call assert(solution(A,B,C)) at the end of my map_color predicate. And then, for each solution, check if they already exist as a solution/3 fact. The problem is that I would have to assert something like solution(Color1,Color1,Color2), i.e. with variables in order to make a unification check. And I can't think of a way to achieve this. So, the question is, what is the best way to assert a found solution and then make a unification test so that "red, red, blue" would unify with "blue, blue, red"?

    Read the article

  • PROLOG - DCG parsing

    - by user2895589
    Hello I am new Prolog and DGC.I want to write a DCG to parse time expressions like 10.20 am or 12 oclock. how can I check 10.20 am is valid expression or not for Olcock I wrote some code. oclock --> digit1,phrase1. digit1 --> [T],{digit1(T)}. digit1(1). digit1(2). digit1(3). digit1(4). digit1(5). digit1(6). digit1(7). digit1(8). digit1(9). digit1(10). digit1(11). digit1(12). phrase1 --> [P],{phrase1(P)}. phrase1(Oclock). i ma checking by query oclock([1,oclock],[]). can someone help me on this.

    Read the article

  • Class Problem (c++ and prolog)

    - by Joshua Green
    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.next_solution()) { cout << (char*)av[1] << endl; } } This works in a separate code, so the syntax is correct. But I am also trying to get this simple backtracking to work within a class: class UserTaskProlog { public: UserTaskProlog(ArRobot* r); ~UserTaskProlog(); protected: int cycles; char* argv[1]; ArRobot* robot; void logTask(); }; This class works fine, with my cycles variable incrementing every robot cycle. However, when I run my main code, I get an Unhandled Exception error message: UserTaskProlog::UserTaskProlog(ArRobot* r) : robotTaskFunc(this, &UserTaskProlog::logTask) { cycles = 0; PlEngine e(argv[0]); PlCall("consult('myFile.pl')"); robot->addSensorInterpTask("UserTaskProlog", 50, &robotTaskFunc); } UserTaskProlog::~UserTaskProlog() { robot->remSensorInterpTask(&robotTaskFunc); // Do I need a destructor here for pl? } void UserTaskProlog::logTask() { cycles++; cout << cycles; { PlFrame fr; PlTermv av(2); av[0] = PlCompound("john"); PlQuery q("likes", av); while (q.next_solution()) { cout << (char*)av[1] << endl; } } } I have my opening and closing brackets for PlFrame. I have my frame, my query, etc... The exact same code that backtracks and prints out mary and emma and sara. What am I missing here that I get an error message? Here is what I think the code should do: I expect mary and emma and sara to be printed out once, every time cycles increments. However, it opens SWI-cpp.h file automatically and points to class PlFrame. What is it trying to tell me? I don't see anything wrong with my PlFrame class declaration. Thanks,

    Read the article

  • Prolog Cut Not Working

    - by user2295607
    Im having a problem with Prolog since cut is not doing what (i believe) its supposed to do: % line-column handlers checkVallEle(_, _, 6, _):- write('FAIL'), !, fail. checkVallEle(TABULEIRO, VALUE, LINE, COLUMN):- COLUMN>5, NL is LINE+1, checkVallEle(TABULEIRO, VALUE, NL, 0). % if this fails, it goes to the next checkVallEle(TABULEIRO, VALUE, LINE, COLUMN):- (checkHorizontal(TABULEIRO, VALUE, LINE, COLUMN, 0), write('HORIZONTAL '); checkVertical(TABULEIRO, VALUE, LINE, COLUMN, 0), write('VERTICAL'); checkDiagonalRight(TABULEIRO, VALUE, LINE, COLUMN, 0), write('DIAGONALRIGHT'); checkDiagonalLeft(TABULEIRO, VALUE, LINE, COLUMN, 0), write('DIAGONALLEFT')), write('WIN'). % goes to the next if above fails checkVallEle(TABULEIRO, VALUE, LINE, COLUMN):- NC is COLUMN+1, checkVallEle(TABULEIRO, VALUE, LINE, NC). What I wish to do is that if the code ever reaches the first statement, that is, if the line is ever 6, it fails (since it went out of range), without checking for more possibilities. But what happens is, when it reaches the first statement, it keeps going to the below statements and ignores the cut symbol, and I dont see why. I just want the statement to fail when it reaches the first line. I also made an experience... run(6):-write('done'), !, fail. run(X):-X1 is X+1, run(X1). And this is what i get from tracing: | ?- run(0). 1 1 Call: run(0) ? 2 2 Call: _1079 is 0+1 ? 2 2 Exit: 1 is 0+1 ? 3 2 Call: run(1) ? 4 3 Call: _3009 is 1+1 ? 4 3 Exit: 2 is 1+1 ? 5 3 Call: run(2) ? 6 4 Call: _4939 is 2+1 ? 6 4 Exit: 3 is 2+1 ? 7 4 Call: run(3) ? 8 5 Call: _6869 is 3+1 ? 8 5 Exit: 4 is 3+1 ? 9 5 Call: run(4) ? 10 6 Call: _8799 is 4+1 ? 10 6 Exit: 5 is 4+1 ? 11 6 Call: run(5) ? 12 7 Call: _10729 is 5+1 ? 12 7 Exit: 6 is 5+1 ? 13 7 Call: run(6) ? 14 8 Call: write(done) ? done 14 8 Exit: write(done) ? 13 7 Fail: run(6) ? 11 6 Fail: run(5) ? 9 5 Fail: run(4) ? 7 4 Fail: run(3) ? 5 3 Fail: run(2) ? 3 2 Fail: run(1) ? 1 1 Fail: run(0) ? no What are all those Fails after the write? is it still backtracing to previous answers? Is this behaviour the reason why cut is failing in my first code? Please enlighten me.

    Read the article

  • Prolog : Simple question

    - by abduls85
    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 into a user-defined list which will be used for further processing later ? Please help. I have tried numerous stuff like append and other but it does not work :(

    Read the article

  • assert fact into file in prolog

    - by smile
    Hello everyone, How can I assert a fact into a file without deleting the previous fact? In the following line, when I execute it twice, the second fact overwrites the first fact: tell('animal.txt'),write(Animal),nl,told. But when I use assert or assertz it will do nothing. Help me please. Thank you :)

    Read the article

  • Prolog Program for a recordings database

    - by RP
    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 to create these 4 rules: together(X,Y) This succeeds if X and Y have played on the same album. artistchain(X,Y) This succeeds if a chain of albums exists from X to Y; two musicians are linked in the chain by 'together'. role(X,Y) This succeeds if X had role Y (e.g. guitar) ever. song(X,Y) This succeeds if artist X recorded song Y. Any help?

    Read the article

  • Prolog: Sentence Parser Problem

    - by Devon
    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). adjective(orange). adjective(sweet). noun(cat). noun(mat). noun(fox). noun(cucumber). noun(saw). noun(mother). noun(father). noun(family). noun(depression). prep(on). prep(with). verb(sat). verb(nibbled). verb(ran). verb(looked). verb(is). verb(has). % Sentece Structures sentence(Phrase) :- append(NounPhrase, VerbPhrase, Phrase), nounPhrase(NounPhrase), verbPhrase(VerbPhrase). sentence(Phrase) :- verbPhrase(Phrase). nounPhrase([]). nounPhrase([Head | Tail]) :- det(Head), nounPhrase2(Tail). nounPhrase(Phrase) :- nounPhrase2(Phrase). nounPhrase(Phrase) :- append(NP, PP, Phrase), nounPhrase(NP), prepPhrase(PP). nounPhrase2([]). nounPhrase2(Word) :- noun(Word). nounPhrase2([Head | Tail]) :- adjective(Head), nounPhrase2(Tail). prepPhrase([]). prepPhrase([Head | Tail]) :- prep(Head), nounPhrase(Tail). verbPhrase([]). verbPhrase(Word) :- verb(Word). verbPhrase([Head | Tail]) :- verb(Head), nounPhrase(Tail). verbPhrase(Phrase) :- append(VP, PP, Phrase), verbPhrase(VP), prepPhrase(PP).

    Read the article

  • Prolog adding and removing list element if non present in second list

    - by logically
    I don't know what I'm missing here. I wan't to add an element if it is in arg1 but not in arg2 and want to remove an element if it is in arg1 but not in arg2. I'm using an if condition with includes function that return true if the element is in the arg2 list, false otherwise. Then use built it predicates append and select to add or remove. I'm getting false to all my objectives searches. I comment and uncomment depending on what predicate I want, add or remove. includes([],_). includes([P|Z],S) :- memberchk(P,S), includes(Z,S). addop([],list,res). addop([P|R],list,res) :- includes(P,s0) - addop(R,list,res) ; append(P,list,res), addop(R,list,res). rem([],list,res). rem([P|R],list,res) :- includes(P,list) - rem(R,list,res) ; select(P,list,res),rem(R,list,res). Thanks for help.

    Read the article

  • Using recursion an append in prolog

    - by Adrian
    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 == []) -> L=[H|T], append([H], create(T, L2), L2);[]). calling it by create([1,2,3,4], L2) returns L2 = [1|create([2,3,4], **)\. which is not a desired result.

    Read the article

  • Prolog: Error Handling and Find Unique

    - by anotherstat
    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_unique(pineapple) How could I catch this and output an error message? Thanks, AS

    Read the article

  • Prolog term concatenation

    - by d0pe
    Hi, I'm trying to format a result from a program but getting an hard time. I wanted to give something like this as result: Res = do(paint(x) do(clean(a), do(repair(b) , initialState))) basically, I want to concatenate successive terms to initialState atom but, it doesn't work with atom_concat since the other terms to concatenate aren't atoms and also I wanted to add the ) everytime I pass through the "do" function. So it would be something like: Res = initialState. When do function was called, I would have a function like concatenateTerm(Pred, Res, Res). Pred beeing repair(b) for instance and obtain the result: res = do(repair(b), initialState). Is this possible to be done? Thanks

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >