The function 'endcons' makes this task a bit easier, I think. Try
(%i3) map(lambda([x], endcons(1+last(x),x)),ts);
(%o3) [[1,2,3],[1,3,4],[1,4,5],[2,3,4],[2,4,5],[3,4,5]]
Does this work correctly? And welcome to Maxima .
--Barton
________________________________
From: maxima-bounces at math.utexas.edu [maxima-bounces at math.utexas.edu] on behalf of Alessandro Campagni [alessandro.campagni at gmail.com]
Sent: Tuesday, March 19, 2013 21:24
To: maxima at math.utexas.edu
Subject: nested list
Hi everybody,
this is my first post here, I'm a very beginner so pardon me if my question seems trivial.
I'm building a list starting from a list of lists, appending to each one every single value taken from another list. Let me get this straight with an example:
this is the starting list
ts:[[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
now for every [x,y] i should concatenate it with every element of the following list [y+1,y+2,...,n] where n is fixed.
This is what I tried:
map (lambda ([x], append (makelist (append (x, [y]), y, last (x) + 1, 5))), ts);
map (lambda ([x], map (lambda ([y], append (x, [y])), makelist (z, z, last (x) + 1, 5))), ts);
makelist (makelist (append (x, [y]), y, last (x) + 1, 5), x, ts);
I always get:
[[[1,2,3],[1,2,4],[1,2,5]],[[1,3,4],[1,3,5]],[[1,4,5]],[[2,3,4],[2,3,5]],[[2,4,5]],[[3,4,5]]]
but what I really need is
[[1,2,3],[1,2,4],[1,2,5],[1,3,4],[1,3,5],[1,4,5],[2,3,4],[2,3,5],[2,4,5],[3,4,5]] (i.e. just a list of lists).
Now, the question: Is it possible without using for's or if's?
I played around with flatten but it didn't help me!
Thanks in advance
Sciamp