2

Is it possibile associate costant and variable in the same argument? For example:

 expression(N):- write(t N), N1 is N+1, expression(N1). 

where t N become t1, t2, t3... etc. How can I do this?

0

1 Answer 1

2

In SWI prolog:

expression(N) :- atom_concat('t', N, TN), % Note: N must be instantiated in this case write(TN), N1 is N+1, expression(N1). 

Interestingly, SWI is happy with this even if N is an integer or an atom (it will treat N as an atom in that case). GNU doesn't like it if N is an integer. So you have to convert it first:

expression(N) :- number_atom(N, AtomN), % Note: N must be instantiated in this case atom_concat('t', AtomN, TN), write(TN), N1 is N+1, expression(N1). 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.