Is it possible to append a number to a term directly?
I.e., I can easily do something like this:
?- A = 1 + 2, B = 3, C = A + B.
C = 1+2+3
But is there a way (operator?) to specify something instead of '+' in the C = A + B
to get "C = 1+23"?
I feel I'm asking for something strange, so here is the context. I have a list of digits, and I want to generate all expressions that can be obtained by putting '+', '-' or nothing between the digits.
Pluses and minuses are easy part:
possible([X], X) :- !.
possible([A, B | Rest], E) :-
( H = A + B ; H = A - B ),
possible([H | Rest], E).
?- possible([1, 2, 3], E).
E = 1+2+3 ?;
E = 1+2-3 ?;
E = 1-2+3 ?;
E = 1-2-3
yes
But I also want to get "E = 12+3", "E = 1+23" and "E = 123". Is there an easy way to do it?
Update: the solution should be portable or at least work in B-Prolog.