I have the following code:
Bear in mind that while this code works on lists, these lists represent sets, so [1,1,2,2,3,3] and [1,2,3] should be equivalent.
%contains(L1, L2), returns true if L1 contains L2
contains(_, []).
contains(L1, [Head|Tail]) :- member(Head, L1), contains(L1, Tail).
%equals(L1, L2), returns true if L1 is equal t...
I'm trying to implement a findall predicate in Prolog (yes I know it's built in, this is for an assignment).
It is written as follows:
my_findall(N,P,Pred,L) :- Pred, not(new(N,P)), !, assert(new(N,P)), my_findall(N1,P1,Pred,L1), L=[N,P,L1], retract(new(N,P)).
my_findall(_,_,_, []).
For some reason it only gives me the first solut...
I am a C# programmer, and after going through some wonderful discussions regarding functional programming and declarative programming. I feel I am not good at both :P, so, I was thinking of starting learning prolog, and haskell. Please suggest about the feasibility in doing so. And if I learn F#, then learning Haskell makes any sense ? W...
For a project I'm working on I'd like to use WordNet to do some linguistic classification of user input, and I'd like to use the Prolog version of the database.
I've tried P#, which works reasonably well, but which appears to be unable to handle the sheer size of the WordNet databases. It can compile the smallest of the files I want to ...
Hello,
I was wondering whether anyone had managed to use the 'listing.' command in JPL to examine the contents of the Prolog knowledgebase? JPL requires you construct queries and will return solutions based on the variables which you set in the query. For example (Java):
Query q = new Query("holdsAt((X,Y) = true, 3)");
while ( q.hasM...
I'm interfacing with WordNet, and some of the terms I'd like to classify (various proper names) are capitalised in the database, but the input I get may not be capitalised properly. My initial idea here is to write a predicate that produces the various capitalisations possible of an input, but I'm not sure how to go about it.
Does anyon...
I want to use Prolog with PHP. Is it possible?
...
I was solving a puzzle in prolog the other day and realized that were I using another programming language, I would have made use of a hash table/dictionary, but as far as I know this isn't really possible in prolog.
So my first question is are there any prologs that support a dictionary-like data structure with the performance charact...
Hi,
I've been given the question:
'Define a predcate ordered/1, which cheks if a list of integers is correctly in ascending order. For example, the goal ordered([1,3,7,11]) should succed, as should the goal ordered ([1,3,3,7]), whereas the goal ordered([1,7,3,9]) should fail.
So far I have this:
ordered([]).
ordered([N, M|Ns]):-
ap...
pred(Args).
pred(Args) :-
goalA,
goalB,
!,
pred(Args).
pred(Args) :-
goalC,
goalD,
!,
pred(Args).
Normally I would write a recursive predicate that was concerned with memory performance something along the lines of the above snippet of code. With the cut being used to try to force tail call optimization...
How can I count nested list elements in prolog?
I have the following predicates defined, which will count a nested list as one element:
length([ ], 0).
length([H|T],N) :- length(T,M), N is M+1.
Usage:
?- length([a,b,c],Out).
Out = 3
This works, but I would like to count nested elements as well i.e.
length([a,b,[c,d,e],f],Output...
Hi,
There are some special operators in Prolog, one of them is "is", however, recently I came across the =:= operators, and I have no idea how it works.
Can someone explain what the operator does, and also where can I find a predefined list of such special operators and what they do?
Thanks.
...
Hi Guys,
I am just learning prolog. I have a task ahead. I have to insert some data in to a database like mysql or MSSQL using Prolog ODBC INterface. I know there are some example predicates(SWI-PROLOG) like
open_wordnet :-
odbc_connect('WordNet', _,
[ user(jan),
password(xxx),
...
Why doesn't this work to define "married" in Prolog?
married(X,Y):-married(Y,X).
Are these kinds of circular predicates not allowed? How would I fix it?
Thanks
...
I'm trying to work on a homework assignment based on the old song, I'm my own grandpa.
So, I've started out defining rules for who a son, daughter, father, father_in_law, etc was.
However, something must be wrong with the order of my rules/facts because every time I load it I get the following errors:
GNU Prolog 1.3.1
By Daniel D...
The following story is from N. Wirths (1976) Algorithsm + Datastructures = Programs.
I married a widow (let's call her W)
who had a grown-up daughter (call her
D). My father (F), who visited us
quite often, fell in love with my
step-daughter and married her. Hence,
my father became my son-in-law and my
step-daughter bec...
I'm working on writing a simple Prolog interpreter in Java.
How can I find the last character index of the first element either the head element or the tail element of a string in "List Syntax"?
List Syntax looks like:
(X)
(p a b)
(func (func2 a) (func3 X Y))
(equal eve (mother cain))
The head for each of those strings in...
How to define a relative rule in Prolog?
This is what I got so far:
spouce(X,Y) :-
wife(X,Y).
spouce(X,Y) :-
husband(X,Y).
relative-by-blood(X,Y) :-
ancestor(Z,X),
ancestor(Z,Y).
relative(X,Y) :-
relative-by-blood(X,Y).
relative(X,Y) :-
spouce(X,Y).
relative(X,Y) :-
relative-by-blood(X,Z), %<- not sure...
How to expand a query into a list?
f(a,b).
f(a,c).
d(a.d).
expand(f(a,X), Out) -----> Out=[b,c,d]
...
What is wrong with my power function?
pow(_,0,1).
pow(X,Y,Z) :-
pow(X,Y-1,X*Z).
?- pow(2,3,Z).
ERROR: Out of global stack
...