1
它是否可能在相同的參數中關聯costant和變量? 例如:將常數連接到變量
expression(N):-
write(t N),
N1 is N+1,
expression(N1).
其中t N
成爲t1
,t2
,t3
......等我怎樣才能做到這一點?
它是否可能在相同的參數中關聯costant和變量? 例如:將常數連接到變量
expression(N):-
write(t N),
N1 is N+1,
expression(N1).
其中t N
成爲t1
,t2
,t3
......等我怎樣才能做到這一點?
在SWI序言:
expression(N) :-
atom_concat('t', N, TN), % Note: N must be instantiated in this case
write(TN),
N1 is N+1,
expression(N1).
有趣的是,SWI是滿意這個即使N
是整數或原子(它會將N
如在這種情況下的原子)。如果N
是一個整數,GNU不喜歡它。所以你必須先轉換它:
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).