I am trying to create a deep binary predicate text/2
which will process a list and replace each number in a list by the atom number
.
Example:
?- text([a,[[13]],b,14,c(5),8], Xs).
Xs = [a,[[number]],b,number,c(5),number].
Solution:
I tried doing it as below but getting
Warning: Attempt to read past end of file in
SGETTOK
The code is:
toNumber(In,number) :-
number(In),
!.
toNumber(In,In).
maplist(_,[],[]).
maplist(Pred,[InListHead|InListTail],[OutListHead|OutListTail]) :-
Term = [Pred,InListHead,OutListHead],
call(Term),
maplist(Pred,InListHead,OutListHEad).
text(InListHead,OutListHead) :-
maplist(toNumber,InListHead,OutListHead).