manipulating a compund term in Prolog
Posted 09 June 2006 - 11:19 AM
Is there some way of manipulating the head of the compound term (perhaps by temporarily separating it from the body?) so that it can be changed?
This is quite urgent so any and all help would be gratefully received!
Posted 09 June 2006 - 06:45 PM
I am still in need of advice if anyone can help!!! :o)
Posted 09 June 2006 - 09:47 PM
You are a student, no matter your level, and you have a task involved in your schooling. Plus, I think if you are at a PhD level, that you would be able to find the information you are looking for in a prolog textbook or from a knowledgable Professor on campus.
Posted 10 June 2006 - 08:02 AM
I only use forum postings as a last resort when all other resources have been exhausted.
Posted 12 June 2006 - 09:25 PM
Posted 13 June 2006 - 04:21 AM
As for the question of how to do what the OP was proposing, I only had a two week orientation on Predicate Calculus so I don't know of a way to do what was proposed but I'll give it some thought.
-edit- It sounds to me like you could use a form of inheritance. Are you using an Object Prolog system or a traditional one?
-edit2- http://www.faqs.org/.../section-7.html has some Object-Oriented layers to add to Prolog that you might find useful.
Posted 19 July 2006 - 03:07 AM
?- name(admitPatient, L).
L = [97, 100, 109, 105, 116, 80, 97, 116, 105, 101, 110, 116] ;
?- name(N, [97, 100, 109, 105, 116, 80, 97, 116, 105, 101, 110, 116]).
N = admitPatient ;
Of course you still need code to do the seperation/manipulation/modification part!
Posted 29 August 2006 - 11:16 PM
Posted 30 August 2006 - 08:24 PM
Posted 12 September 2006 - 08:12 AM
start(A, B, C, D) :- tell('filename.pl'), manipulate(A, B, C, D), !, told. start(_, _, _, _) :- told. manipulate(A, B, C, D) :- write(A), write(B), write(C), write(D), write('.').
Note: both admitPatient and (P,oncology) would each be contained in some variable (ALL terms preferably). Since i haven't got terms as variables i'll put the query in manually as follows:
start('z', 'admitPatient', '1', '(P,oncology)').
This writes the modified term to filename.pl.
Which contains the new predicate:
Then to use the new predicate could use:
Is crude but is a start and it works!
To do it dynamically I guess you would need to add this line:
:- dynamic admitPatient/2.
The infix operator '=..' (pronounced "univ") can be used either to
decompose a term into a list containing its functor and arguments or
else to construct a term from such a list.
To extract the term 'admitPatient' perhaps a call similar to:
?- admitPatient(P, oncology) =.. [H|B] . P = _G404 H = admitPatient B = [_G404, oncology] ; No
Variable H (inserted at paramater B in my 'static' code above for example) can then be manipulated; likewise Variable B (inserted at paramater D above).
:excl: Of course there's a better way as i'm just a novice. :unsure:
Posted 12 September 2006 - 12:32 PM
I suppose that your facts are in a file named "admitPatient.pl", I modify the facts and I save the new database in "admitPatient1.pl".
The change are made with this :
% the predicates must be declared dynamic because they will be changed :-dynamic(admitPatient/2, zadmitPatient1/2). my_test :- % reading the database consult('admitPatient.pl'), % opening the new database for writing tell('admitPatient1.pl'), % I work with all the patient of oncology forall(admitPatient(P, oncology), ( % I remove the fact of the database retract(admitPatient(P, oncology)), % I add the new fact in the database assert(zadmitPatient1(P,oncology)), % I save the fact in the file "admitPatient1.pl" write(zadmitPatient1(P,oncology)), nl)), % I save the rest of the database forall(admitPatient(X, Y), ( write(admitPatient(X,Y)), nl)), % it's done. told.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users