Home > Archive > Prolog > November 2005 > sublist replacement
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
sublist replacement
|
|
|
| Hi,
I have to write a predicate "replace(S1,S2,L1,L2)" which is satisfied if
the replacement of S1 by S2 in the list L1 gives L2.
It seems to me that it means L1 and L2 have the same prefix and suffix,
so i tried to write:
rempl(S1,S2,L1,L2) :-
append(append(A,S1),B) = L1,
append(append(A,S2),B) = L2.
but it didn't work :(
Could someone help me ?
Thanks
Jocelyn
-
| |
| Nick Wedd 2005-11-24, 7:57 am |
| In message <4384222c$0$21689$626a54ce@news.free.fr>, Kaio
<lecomte.trash@free.fr> writes
>Hi,
>I have to write a predicate "replace(S1,S2,L1,L2)" which is satisfied
>if the replacement of S1 by S2 in the list L1 gives L2.
>It seems to me that it means L1 and L2 have the same prefix and suffix,
>so i tried to write:
>
>rempl(S1,S2,L1,L2) :-
> append(append(A,S1),B) = L1,
> append(append(A,S2),B) = L2.
>
>but it didn't work :(
No, it wouldn't.
You have the right idea. But when you give an expression in a Prolog
argument list (like your append(A,S1) ), it does not get evaluated - and
it wouldn't help much if it were, as it would "evaluate" to true, or
maybe to false.
Also, '=' does not cause evaluation.
I suggest that you look at some documentation on append, observe that it
has three arguments not two, and try to understand why.
Nick
--
Nick Wedd nick@maproom.co.uk
|
|
|
|
|