Reputation: 41
I´m doing a project where I need to recognize specific strings and add them to a list. Im using this method to insert them in a specific position:
insertAt(E,N,Xs,Ys) :-
same_length([E|Xs],Ys),
append(Before,Xs0,Xs),
length(Before,N),
append(Before,[E|Xs0],Ys)
The problem is that when I insert any String for example '4X',in my list appears 4X, as a number and a variable. How can i keep the single quotes after the insert? This is the line that gives me problems:
insertAt('>500',0,ListA,ListB),writeln(ListB).
When the list show in promt it looks like [>500],without the quotes.
Upvotes: 1
Views: 30
Reputation: 24976
Simple example since you didn't indicate how you are creating 4X
test :-
append(["4x"],[],New),
write(New).
Example run:
?- test.
[4x]
true.
After updates in comments.
Is there a way to write while maintaining the quotes?
?- print('4x').
'4x'
true.
?- print([a,b,'4X',d]).
[a,b,'4X',d]
true.
Of note: portray/1
I have never used portray/1
but you might.
Upvotes: 1