Re: How to replace a term to the inside of an other term?
- From: Joachim Schimpf <j.schimpf@xxxxxxxxxxxxxxx>
- Date: Fri, 26 May 2006 10:53:31 GMT
student wrote:
Joachim Schimpf wrote:...
replace(In, OldTmpl, NewTmpl, Out) :-
functor(In, F, N),
functor(In1, F, N),
replace_args(N, In, OldTmpl, NewTmpl, In1),
( copy_term(OldTmpl-NewTmpl, Old-New), In1 = Old ->
Out = New
;
Out = In1
).
replace_args(I, In, OldTmpl, NewTmpl, Out) :-
( I > 0 ->
arg(I, In, InArg),
arg(I, Out, OutArg),
replace(InArg, OldTmpl, NewTmpl, OutArg),
I1 is I-1,
replace_args(I1, In, OldTmpl, NewTmpl, Out)
;
true
).
-- Joachim
Beautiful stuff, especially the concept of patterns with variables
that somehow end up not being instantiated, but I will have to find time
to bone up on 'functor/3', 'copy_term/3', and 'arg/3' to understand it.
Oh, functor+arg vs =.. are just a matter of preference.
Apart from the line with the copy_term, your t_replace/4 from
your other posting does exactly the same as my code.
- Joachim
.
- Follow-Ups:
- References:
- How to replace a term to the inside of an other term?
- From: Mika
- Re: How to replace a term to the inside of an other term?
- From: student
- Re: How to replace a term to the inside of an other term?
- From: Joachim Schimpf
- Re: How to replace a term to the inside of an other term?
- From: student
- Re: How to replace a term to the inside of an other term?
- From: Joachim Schimpf
- Re: How to replace a term to the inside of an other term?
- From: student
- How to replace a term to the inside of an other term?
- Prev by Date: Re: How to replace a term to the inside of an other term?
- Next by Date: ! and ->
- Previous by thread: Re: How to replace a term to the inside of an other term?
- Next by thread: Re: How to replace a term to the inside of an other term?
- Index(es):
Relevant Pages
|
|