Removing nil from list

V

vtcad

Guest
How do I remove an element from a list? I am trying to remove an
element nil.

thanks,
 
Non destructive:

aList = list( "a" "b" "1" "2" nil "c" "3" nil "d" "4" nil "5" )
bList = remove( nil aList )
bList => ( "a" "b" "1" "2" "c" "3" "d" "4" "5" )

aList = list( nil )
bList = remove( nil aList )
bList => nil

or
setof( element aList element ) => bList
retuns a copy of aList without elements which value is nil

aList = list( "a" "b" "1" "2" nil "c" "3" nil "d" "4" nil "5" )
bList = setof( element aList element )
bList => ( "a" "b" "1" "2" "c" "3" "d" "4" "5" )

aList = list( nil )
bList = setof( element aList element )
bList => nil


or destructive

aList = list( "a" "b" "1" "2" nil "c" "3" nil "d" "4" nil "5" )
remd( nil aList )
aList => ( "a" "b" "1" "2" "c" "3" "d" "4" "5" )

Bernd
 
Bernd Fischer <""bernd.fischer\"@xignal-A%&HY%$v#&G=.de"> writes:

aList = list( "a" "b" "1" "2" nil "c" "3" nil "d" "4" nil "5" )
remd( nil aList )
aList => ( "a" "b" "1" "2" "c" "3" "d" "4" "5" )
(setq aList (remd nil aList))

See for example with
(setq aList '(nil "a" nil "b"))

where you'll not erase the first nil if you don't reassign aList.

Yours,

--
Jean-Marc
 

Welcome to EDABoard.com

Sponsor

Back
Top