newLISP Fan Club

Forum => newLISP in the real world => Topic started by: tom on September 20, 2008, 09:39:07 PM

Title: nil?
Post by: tom on September 20, 2008, 09:39:07 PM
How do you remove a nil from a list?
Title:
Post by: m i c h a e l on September 20, 2008, 10:53:31 PM
Tom,



Would this be what you are looking for?


> (clean nil? '(1 2 3 nil 4))
(1 2 3 4)


m i c h a e l
Title:
Post by: tom on September 21, 2008, 07:44:09 AM
I thought so.  trying it now, that works fine, but I have a list with both empty and nil elements, and clean seems to balk at the empty ones.  Here's what I get:



> box
("" nil "" "sdc1" "sda1" "sda2" "sdb2" "sdb1")
> (clean nil? box)
("" "" "sdc1" "sda1" "sda2" "sdb2" "sdb1")
> (clean empty? box)

ERR: list or string expected in function empty? : nil
>


EDIT



Ok, clean must not be destructive.



> (set 'box2 (clean nil? box))
("" "" "sdc1" "sda1" "sda2" "sdb2" "sdb1")
> (clean empty? box2)
("sdc1" "sda1" "sda2" "sdb2" "sdb1")
>
Title:
Post by: m i c h a e l on September 21, 2008, 10:30:05 AM
We could also cut out the box2 middle-man by using the result of the first function call as the argument to the second function:


> (set 'box '("" nil "" "sdc1" "sda1" "sda2" "sdb2" "sdb1"))
("" nil "" "sdc1" "sda1" "sda2" "sdb2" "sdb1")
> (clean empty? (clean nil? box))
("sdc1" "sda1" "sda2" "sdb2" "sdb1")
> _


Sorry if you already know this, but someone new to functional programming may not :-)



m i c h a e l
Title:
Post by: tom on September 21, 2008, 10:48:31 AM
:-)
Title:
Post by: cormullion on September 21, 2008, 10:49:16 AM
Or


> (set 'box '("" nil "" "sdc1" "sda1" "sda2" "sdb2" "sdb1") )
("" nil "" "sdc1" "sda1" "sda2" "sdb2" "sdb1")
> (clean (fn (e) (or (nil? e) (empty? e))) box)
("sdc1" "sda1" "sda2" "sdb2" "sdb1")
>
Title:
Post by: Lutz on September 21, 2008, 12:56:56 PM
Or use 'null?' which checks for the nil, the empty list (), the empty string "" and 0 and 0.00 and NaN.


> (set 'box '("" nil "" "sdc1" "sda1" "sda2" "sdb2" "sdb1"))
("" nil "" "sdc1" "sda1" "sda2" "sdb2" "sdb1")
> (clean null? box)
("sdc1" "sda1" "sda2" "sdb2" "sdb1")
>
Title:
Post by: DrDave on September 22, 2008, 05:19:54 AM
Quote from: "Lutz"Or use 'null?' which checks for the nil, the empty list (), the empty string "" and 0 and 0.00 and NaN.

Thanks for pointing out 'null?' As you know, I've read the entire user's guide more than once, but didn't recall 'null?'
Title:
Post by: cormullion on September 22, 2008, 08:30:24 AM
It's hidden between now and nper... :)
Title:
Post by: DrDave on September 22, 2008, 10:01:23 AM
Quote from: "cormullion"It's hidden between now and nper... :)

Ah, maybe I missed it becasue I'm not used to seeing alphabetical ordering such as

'npv'

'nth'

'null?'

'nper'  <---(how did this guy cut in line here??)

'number?'
Title:
Post by: cormullion on September 23, 2008, 09:03:09 AM
Quote from: "DrDave"
Quote from: "cormullion"It's hidden between now and nper... :)

Ah, maybe I missed it becasue I'm not used to seeing alphabetical ordering such as

'npv'

'nth'

'null?'

'nper'  <---(how did this guy cut in line here??)

'number?'


This would help to find the queue jumpers, but I think the original is not HTML...?



(set 'file (read-file "/usr/share/doc/newlisp/newlisp_manual.html"))
(set 'data (find-all (string {<h2><span class="function">([a-z].*?)</span></h2>}) file   $1))

(map (fn (x y)
  (if (!= x y)
   (println (format { ? %-18s should be %-18s } x y))
   (println (format {   %-18s           %-18s } x y))))
  data
 (sort data))

.....
   nil?                         nil?              
 ? not                should be normal            
 ? normal             should be not                
   now                          now                
 ? null?              should be nper              
 ? nper               should be npv                
 ? npv                should be nth                
 ? nth                should be null?              
   number?                      number?    
.....

Title:
Post by: Lutz on September 23, 2008, 09:35:45 AM
The original is in HTML. I updated this copy:



http://www.newlisp.org/downloads/newlisp_manual.html



yesterday and today, and all changes will also show up in 9.9.5
Title:
Post by: cormullion on September 23, 2008, 09:40:14 AM
Oh yes - it's the PDF that takes the time to generate from the HTML source, not the other way round. Sorry Lutz!