I need to get part of a list. Is there a function in skill? It's better return a list.
I tried some coding, but failed:
a = list((0:0) (1:1) (2:2) (3:3) (4:2) (5:0))
b = nthcdr(3 a)
c = remove(b a)
As I suppose, c should be a list of ((0:0) (1:1) (2:2)). But actually c is equal to a.
You can do this destructively (which means it is quite efficient) using the following:
rplacd(nthcdr(2 a) nil)
a => ((0 0) (1 1) (2 2))
If you wanted a non-destructive list range function, you could implement it like this:
procedure(CCFlistRange(lst start end) let((tail) tail=copy(nthcdr(start lst)) rplacd(nthcdr(end-start tail) nil) tail ))
Whether this would be more efficient than doing something like:
procedure(CCFlistRange(lst start end) let(((count 0)) setof(elem lst prog1(count>=start && count<=end count++)) ))
Would need some profiling and testing with various list sizes.