Re: How to replace a term to the inside of an other term?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bart Demoen wrote:
student wrote:

I also note

?- X =.. [[],2].
X = [](2) ;
No

and

?- X =.. ['.',2].
X = '.'(2) ;
No

which both look a bit peculiar to me.

They might look peculiar, but they are correct, and consistent with the
general principles about the allowed amount of syntactic sugar for
lists. What did you expect ?

Cheers

Bart Demoen

I expected to see a syntax error message, I suppose. I should have
simply said I was surprised (because I was).

p.s.

/*
I hereby withdraw my first draft of 'replace/4' based on '=../2'
and replace it with the following:
*/

t_replace(T,A,B,T1) :-
T =.. [F|TL],
t_replaceL(TL,A,B,TL0),
T0 =.. [F|TL0],
( T0 = A -> T1 = B ; T1 = T0 ).

t_replaceL([],_,_,[]).
t_replaceL([T|TL],A,B,[T1|TL1]) :-
t_replace(T,A,B,T1),
t_replaceL(TL,A,B,TL1).

/*
A closely analogous predicate that operates on constructors -- and
leaves the user responsible for dealing with any system-defined
execution-time type errors that occur as a result of using them --
might then be the following:
*/

f_replace(T,A,B,T1) :-
T =.. [F|TL],
f_replaceL(TL,A,B,TL1),
( F = A -> F1 = B ; F1 = F ),
T1 =.. [F1|TL1].

f_replaceL([],_,_,[]).
f_replaceL([T|TL],A,B,[T1|TL1]) :-
f_replace(T,A,B,T1),
f_replaceL(TL,A,B,TL1).

/*
Please note: This is only a working draft and I have not done much in
the way of testing these predicates. I only offer them in hopes of
repairing some of the damage caused by my premature posting of a bad
first draft and of supporting my original contention that it might be
interesting to approach this problem via '=../2'.
*/
- --
billh
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEdtPnmuz1B9Tdo+wRAphSAKCGd7HXaGCUj3hMcJ+gLRweUaWHggCgmO0+
+jJ6jxommVsPHaz5ORGgPmw=
=AXLv
-----END PGP SIGNATURE-----
.



Relevant Pages