Q&A's, tips, howto's
			
		
		
			- 
				
																			
								tomtoo							 
									
		- Posts: 46
 		- Joined: Wed Oct 28, 2009 10:00 pm
 		
		
						
						
		
		
						
						
													
							
						
									
						Post
					
								by tomtoo » 
			
			
			
			
			Hi guys,
I would like to replace any and all nils in a list with "none" .  If I can see the nil
I can do
but
Code: Select all
(dolist (i a)(when (null? i)(setf i "none")))
returns nil. and
returns true.
How might I fix this? I don't know where a nil might pop up.
thank you.
 
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								fdb							 
									
		- Posts: 66
 		- Joined: Sat Nov 09, 2013 8:49 pm
 		
		
						
						
		
		
						
						
													
							
						
									
						Post
					
								by fdb » 
			
			
			
			
			Hi tomtoo,
you'll have to refer to an index in the list to set the correct value in the list, i is just a temporary loop variable, see below. 
Code: Select all
(set 'a '(1 2 nil 4))
(dolist (i a)(when (null? i)(setf (a $idx) "none")))
This works but doesn't return the changed list. An easier way is to use the replace function:
Code: Select all
(set 'a '(1 2 nil 4))
(replace nil a "none")
> 
(1 2 nil 4)
(1 2 "none" 4)