开发者

How to create dynamically List and set his value

开发者 https://www.devze.com 2023-02-23 18:01 出处:网络
for example, if N is 2, it will create list following and set his value L =开发者_开发知识库 [S1,S2],

for example, if N is 2, it will create list following and set his value

L =开发者_开发知识库 [S1,S2],
L :: 1..10.

if N is 3 , it will crate list following and set his value

L = [S1,S2,S3],
L :: 1..10.

Thanks very much :)


To make a list of length N, use length/2 with a variable as the first argument:

1 ?- N=4, length(List,N).
N = 4,
List = [_G487, _G490, _G493, _G496].


Are you looking for smth-like

list( N, List ) :-
    numlist( 1, N, List ).

which make

?- list(5, L).
L = [1, 2, 3, 4, 5].

Or what?

UPD:

kal( N, Lists ) :- govna( N, [[]], [_ | Lists] ), !.
govna( 0, Ans, Ans ).
govna( N, List, Com ) :-
    numlist( 1, 10, X ),
    append( List, [X], ListNew ),
    NewN is N - 1,
    govna( NewN, ListNew, Com ).

Is this it?

?- kal(2, X).
X = [[1, 2, 3, 4, 5, 6, 7, 8|...], [1, 2, 3, 4, 5, 6, 7|...]].
0

精彩评论

暂无评论...
验证码 换一张
取 消