Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Finding Maximum with Nil

1 REPLY 1
Reply
Message 1 of 2
mike
256 Views, 1 Reply

Finding Maximum with Nil

 
1 REPLY 1
Message 2 of 2
Kent1Cooper
in reply to: mike

If the issue is that (max) doesn't like nil as an argument:

 

Command: (max 12 15 nil 75 34)
; error: bad argument type: numberp: nil

 

then if you can put the values into a list, and get rid of any nil's in it, you can find the maximum of the numerical values:

 

Command: (apply 'max (vl-remove nil '(12 15 nil 75 34)))
75

 

Or, if there might be other kinds of non-numerical values than just nil:

 

Command: (max 45.3 "what" 98 12.34)
; error: bad argument type: numberp: "what"
 

you can do something similar, removing anything that isn't a number:

 

Command: (apply 'max (vl-remove-if-not '(lambda (x) (numberp x)) '(45.3 "what" 98 12.34)))
98.0

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost