remove the nth value of a list

remove the nth value of a list

Anonymous
Not applicable
727 Views
2 Replies
Message 1 of 3

remove the nth value of a list

Anonymous
Not applicable

I am trying to remove the nth value of a list if all values are nil (except the 1st row)

Here is list -

(setq Ltemp
       (list
         (list "Row1ColA" "Row1ColB" "Row1ColC" "Row1ColD" "Row1ColE")
         (list "Row2Text" "X" "X" nil "X")
         (list "Row3Text" "X" "X" nil nil)
         (list "Row4Text" "X" nil nil nil)
         (list "Row5Text" nil "X" nil nil)
       )
)

 

In this example it would remove the 4th value in the list.

 

I can test this in a foreach loop, but would like to use (and learn) mapcar,lambda

 

 

0 Likes
728 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

I am trying to remove the nth value of a list .... 

 


Try a Search -- I think something at least very similar to this has come up before.  The first approach that comes to mind is the (vl-remove) function, but that won't do it, because if the [in your example] fourth item in a list is nil, all nil-value items will be removed from that list, not just the fourth one.  I think the approach would be to build a temporary list of the first three items by stepping through, at the same time removing them from the original list, then also remove the fourth item from the original list, and finally (append) the temporary list with what remains of the original list.

Kent Cooper, AIA
0 Likes
Message 3 of 3

Kent1Cooper
Consultant
Consultant

Kent1Cooper wrote:

Try a Search -- ....


For example, here.

Kent Cooper, AIA
0 Likes