Is there a way to remove a specific element from a list by knowing his location in the list and specifying to remove the elment from that location? :(
One way would be to do:
procedure(CCFremoveByIndex(lst n) let(((count 0)) setof(elem lst (count++!=n)) ))
The second argument is the position to remove, where 0 is the first entry in the list.
Another alternative is to use destructive methods:
procedure(CCFremoveByIndex(lst n) let((remainder) if(zerop(n) then cdr(lst) else remainder=nthcdr(n-1 lst) rplacd(remainder cddr(remainder)) lst ) ))
I've not profiled these, but the second generates less garbage, because it modifies the list in place, whereas the first constructs a new list.
That said, it's a slightly odd thing to do - generally if you're accessing lists via a numbered index, it often means you're using the wrong approach. Lists are sequential data structures, and so are not really well suited to be accessed in a "random access" manner.
Thank U for the feedback... just started using Skill and am a bit confused when U say "wrong approach" to access lists via an index :(
What I have at the moment are two lists: first with the main elements and second with parametter for each element in the first list (same index in the lists). When accessing element X from first list, I am also reading element 3 from second list to use the pair.
With the remove option, all I really want is to make sure that I can access element 3 from both lists and remove them accordingl.
From your experience, is there any risk that the list will not keep the order of the elements as they were added to the lists? :(