TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: roy_043 on December 03, 2010, 01:06:31 PM

Title: Single predicate function for non-nil atom?
Post by: roy_043 on December 03, 2010, 01:06:31 PM
To check for a non-nil list you can use this single function:
Code: [Select]
(vl-consp lst)Instead of:
Code: [Select]
(and lst (listp lst))
To check for a non-nil atom I still use:
Code: [Select]
(and at (atom at))
Is that the only way? Or is there perhaps a single predicate function that can accomplish the same?
Title: Re: Single predicate function for non-nil atom?
Post by: Lee Mac on December 03, 2010, 01:43:09 PM
Code: [Select]
(_atom at)
Code: [Select]
(defun _atom ( a ) (and a (atom a)))
 :lol:
Title: Re: Single predicate function for non-nil atom?
Post by: David Bethel on December 03, 2010, 01:58:15 PM
How about (boundp) ?  -David
Title: Re: Single predicate function for non-nil atom?
Post by: roy_043 on December 06, 2010, 10:27:25 AM
Code: [Select]
(defun _atom (a) (and a (atom a)))
(setq
  a nil
  b 'a
  c 1
  d 'c
  lst '(1 2 3)
  ss (ssget "_X")
)

; (boundp 'a)   => nil
; (boundp 'b)   => T
; (boundp 'c)   => T
; (boundp 'd)   => T
; (boundp 'lst) => T
; (boundp 'ss)  => T

; (boundp a)   => nil
; (boundp b)   => nil
; (boundp c)   => nil
; (boundp d)   => T
; (boundp lst) => nil
; (boundp ss)  => nil

; (_atom a)   => nil
; (_atom b)   => T
; (_atom c)   => T
; (_atom d)   => T
; (_atom lst) => nil
; (_atom ss)  => T