nil?
-
- Posts: 394
- Joined: Wed Apr 26, 2006 3:37 am
- Location: Oregon, USA
- Contact:
Tom,
Would this be what you are looking for?
m i c h a e l
Would this be what you are looking for?
Code: Select all
> (clean nil? '(1 2 3 nil 4))
(1 2 3 4)
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:
EDIT
Ok, clean must not be destructive.
Code: Select all
> 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
>
Ok, clean must not be destructive.
Code: Select all
> (set 'box2 (clean nil? box))
("" "" "sdc1" "sda1" "sda2" "sdb2" "sdb1")
> (clean empty? box2)
("sdc1" "sda1" "sda2" "sdb2" "sdb1")
>
-
- Posts: 394
- Joined: Wed Apr 26, 2006 3:37 am
- Location: Oregon, USA
- Contact:
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:
Sorry if you already know this, but someone new to functional programming may not :-)
m i c h a e l
Code: Select all
> (set 'box '("" nil "" "sdc1" "sda1" "sda2" "sdb2" "sdb1"))
("" nil "" "sdc1" "sda1" "sda2" "sdb2" "sdb1")
> (clean empty? (clean nil? box))
("sdc1" "sda1" "sda2" "sdb2" "sdb1")
> _
m i c h a e l
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Or
Code: Select all
> (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")
>
Or use 'null?' which checks for the nil, the empty list (), the empty string "" and 0 and 0.00 and NaN.
Code: Select all
> (set 'box '("" nil "" "sdc1" "sda1" "sda2" "sdb2" "sdb1"))
("" nil "" "sdc1" "sda1" "sda2" "sdb2" "sdb1")
> (clean null? box)
("sdc1" "sda1" "sda2" "sdb2" "sdb1")
>
Thanks for pointing out 'null?' As you know, I've read the entire user's guide more than once, but didn't recall 'null?'Lutz wrote:Or use 'null?' which checks for the nil, the empty list (), the empty string "" and 0 and 0.00 and NaN.
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.
"Getting Started with Erlang" version 5.6.2
"Getting Started with Erlang" version 5.6.2
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Ah, maybe I missed it becasue I'm not used to seeing alphabetical ordering such ascormullion wrote:It's hidden between now and nper... :)
'npv'
'nth'
'null?'
'nper' <---(how did this guy cut in line here??)
'number?'
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.
"Getting Started with Erlang" version 5.6.2
"Getting Started with Erlang" version 5.6.2
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
This would help to find the queue jumpers, but I think the original is not HTML...?DrDave wrote:Ah, maybe I missed it becasue I'm not used to seeing alphabetical ordering such ascormullion wrote:It's hidden between now and nper... :)
'npv'
'nth'
'null?'
'nper' <---(how did this guy cut in line here??)
'number?'
Code: Select all
(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?
.....
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
http://www.newlisp.org/downloads/newlisp_manual.html
yesterday and today, and all changes will also show up in 9.9.5
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact: