keb5 at June 9th, 2006 07:19 — #1
Working in Prolog, I am trying to turn the compound term
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!
reedbeta at June 9th, 2006 12:10 — #2
This sounds like a homework question, and I am afraid we don't help people with their homework on this site. Try looking in your textbook or asking your professor for help.
keb5 at June 9th, 2006 14:45 — #3
Actually I am a PhD student trying to develop a system so this is not a "homework" question! The system is an AI planning system being developed to look at how classical planning paradigms can be applied to the computerisation of medical guidelines. The urgency is because I don't want to delay the building of the rest of my system.
I am still in need of advice if anyone can help!!! :o)
nodlehs at June 9th, 2006 17:47 — #4
No offense, but it is homework.
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.
keb5 at June 10th, 2006 04:02 — #5
Ok I appreciate your stance on what constitutes homework and realise I am unlikely to get a response but I wanted to point out that before posting to this site I did check every text book I could find (including reference manuals of various prolog systems) and searched the internet. There are no Prolog experts at my university either (in fact it was my professor who suggested poting to forums!).
I only use forum postings as a last resort when all other resources have been exhausted.
jare at June 12th, 2006 17:25 — #6
There are no Prolog experts at my university either
Are there any Prolog experts left anywhere? From what little I remember about that language, there is no answer to your question, but it's been 15 years and I'm probably not even understanding the question itself. Given the lack of expertise around, I'd suggest revisiting the decision to use Prolog if at all possible.
samuraicrow at June 13th, 2006 00:21 — #7
I'm afraid Prolog is a one-of-a-kind language. There is no substitute. Even Lisp is a different type of processing than Prolog.
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/faqs/prolog/resource-guide/part1/section-7.html has some Object-Oriented layers to add to Prolog that you might find useful.
itsbrian at July 18th, 2006 23:07 — #8
I'm not yet sure how to seperate the head of the compound term perhaps someone else can help with that. If you are using SWI prolog one way of manipulating strings is to convert into a list of ascii code, do the manipulating then revert back to string. I'm only a beginner myself still learning but maybe this might help.
?- 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!
trap_d at August 29th, 2006 19:16 — #9
In SWI-Prolog, to do that, you would use assert, retract, dynamic, forall.
ooka at August 30th, 2006 03:55 — #10
Never used prolog before, but google apparently still works
That *seems* to define how you manipulate compound terms in prolog.
trap_d at August 30th, 2006 04:51 — #11
It *seems* to be "manipulating Prolog terms in C"
ooka at August 30th, 2006 16:24 — #12
never used prolog before, just trying to help, maybe steer him onto a different track. Googling his topic title brings up a few hundred thousand topics... the answer's gotta be in there somewhere.
itsbrian at September 12th, 2006 04:12 — #13
Here's one (crude) solution!
start(A, B, C, D) :-
manipulate(A, B, C, D), !,
start(_, _, _, _) :-
manipulate(A, B, C, D) :-
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] ;
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:
trap_d at September 12th, 2006 08:32 — #14
As I understand the problem, I think you want to change the facts of the database admitPatient(P,oncology) into zadmitPatient1(P, oncology).
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
% reading the database
% opening the new database for writing
% I work with all the patient of oncology
( % I remove the fact of the database
% I add the new fact in the database
% I save the fact in the file "admitPatient1.pl"
% I save the rest of the database
% it's done.