Thank you all for your answers. It was very helpful.
And here is my simple procedural aproach:
Tuples(S, N):=
block(
K:length(S),
counter:create_list(1, i, 1, N),
res:[create_list(S[counter[i]],i,1,N)],
for i:1 thru K^N-1 do (
counter[1]:counter[1]+1,
for j:1 thru N-1 do (
if counter[j]>K then (
counter[j]:1,
counter[j+1]:counter[j+1]+1
)
else(
return
)
),
res:append(res, [create_list(S[counter[i]],i,1,N)])
),
res
)$
usage:
Tuples([a,b], 2);
[[a,a],[b,a],[a,b],[b,b]]
Tuples([[a,b],c], 2);
[[[a,b],[a,b]],[c,[a,b]],[[a,b],c],[c,c]]
Greetings
Piotr Slomski