prolog

Learn Prolog Now! DCG Practice Example

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

What are the uses of the fail predicate in Prolog?

I can't come up with a situation where I would need it. ...

Prolog simple question

Hi, I'm still figuring out how prolog really works and was trying to develop an small test program with an if statment but can't really get the value I need out. prog(Sx,Sy) :- Sx > 0 -> update(Sx,10,S1), update(S1,10,S2), prog(S2,S2) ; Sy. update(S,V,RES) :- RES is S-V. I want prog to give Sy as an answer ...

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

Prolog term concatenation

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

Does anybody have practice in programming PCMEF - architectures?

PCMEF is an architecture style presented in the book Practical Software Engineering by Maciaszek and Liong. The layers are: P: Presentation C: Controller M: Mediator E: Entity F: Foundation. It is some kind of enchancement compared with MVC - architecture. I recommend it to interactice, data and communicating - oriented purposes. I...

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

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

prolog, a conditional like form

Hi, well i'm having a hard time working with prolog (gprolog). My problem is this, I've the next predicate: prob(factA,factB,X,first):- X=<50. prob(factA,factB,X,second):- X>50,X=<80. prob(factA,factB,X,none):- X>80,X=<100. that is factA have 50% of probability of occur, factB a 30%, and lastly 20% of non of the facts occur. Also ...

Prolog Constants

Is there any way to define constants in prolog? I'd like to write something like list1 :- [1, 2, 3]. list2 :- [4, 5, 6]. predicate(L) :- append(list1, list2, L). The work-around I'm using now is list1([1, 2, 3]). list2([4, 5, 6]). predicate(L) :- list1(L1), list2(L2), append(L1, L2, L). but it's a bit clumsy to bind ...

Is there any serious project going on using PROLOG?

**Is there any serious project going on using** **?** ...

Prolog - Make an app that does nothing and runs forever

Any good ways to do this? ...

Prolog term to Erlang

Let's say you have this prolog term "city(London, England)". ie London is a city in England. How do you represent that in Erlang, pattern matching? ...

Embedding a Prolog engine in Obj-C projects

Hi all, I'm looking for a light-weight Prolog engine to be embedded in an Obj-C application under Mac OSX. In Java there are some excellent implementations with the characteristics I need: deployability, lightness, dynamic configurability, integration with Java and ease of interoperability. Can you recommend something similar in C/C++? ...

Prolog Assignment Suggestion

Hello to all, i been asking by lecturer to write a Prolog application with 20 facts, 10 rules and 10 queries but this seems easy but i just can think out a scenario/idea of a project like any business rules. We not allow to program family tree. can anyone suggest ? Thanks. ...

Prolog Rules Reflect Strucutre

Hello to all, i need to design a rules which test a loan is a car loan or not. carLoan(flexiCar,minLoanAmount(20000),maxTenure(12) ). iscarloan(X, Y, Z) :- carLoan(X, Y >= minLoanAmount(20000), Z =<(maxTenure(12)) ). iscarloan(X, 25000, 10). I need to test the Y and Z variable against the structure from the fact inside the rule. Ho...

Counting definite clause grammar recursions in Prolog

I have the following Prolog definite clause grammar: s-->[a],s,[b]. s-->[]. This will result in words like [a,a,b,b] being accepted in opposite to words like [a,b,a,b]. To put it in a nutshell the grammar is obviously a^n b^n. Now I want to return n to the user. How can I calculate n? ...

Prolog Recursive Rules Wrong Result

Hello to all, i have define a recursive rule but the result seems incorrect. customer(peter,bank(maybank),customertype(personal), citizen(malaysian),age(62),credit(50000), income(3000),property(car) ). isseniorcitizen(X) :- customer(X, bank(_),customertype(_), citizen(malaysian),age(Age),credit(_), income(_),property(_)), Age >=...

Parsing numbers with multiple digits in Prolog

I have the following simple expression parser: expr(+(T,E))-->term(T),"+",expr(E). expr(T)-->term(T). term(*(F,T))-->factor(F),"*",term(T). term(F)-->factor(F). factor(N)-->nat(N). factor(E)-->"(",expr(E),")". nat(0)-->"0". nat(1)-->"1". nat(2)-->"2". nat(3)-->"3". nat(4)-->"4". nat(5)-->"5". nat(6)-->"6". nat(7)-->"7". nat(8)-->"8"....

generation of positive numbers in a special case

Hi, i am searching for a possibility to transform this code zero(0). positive(X) :- \+ zero(X). so that calls like ?- positive(X). will generate values for X. Actually only calls with specific values for X are tested correctly but no values can be generated. Thanks. ...

Prolog Combine Rule

Hello to all, i need to write a rule which consists of sub rule. Any idea how to achieve this ? isloanaccept(Name, LoanAmount, LoanTenure) :- customer(Name, bank(_),customertype(_), citizen(malaysian),age(Age),credit(C), income(I),property(car|house)), Age >= 18, C > 500, I > (LoanAmount / LoanTenure) / 12. lo...