nil??

nil??

Anonymous
Not applicable
510 Views
7 Replies
Message 1 of 8

nil??

Anonymous
Not applicable
When aquiring a selection set with ssget for all "dimension" in a drawing
with (setq ss1 (ssget "x" '((0 . "dimension")))), I would like to check to
see if it is not nil before working on it. I've tried (if (/= ss1 nil))
and (if (/= ss1 "")), but these don't seem to work. Does anybody know the
correct way of accomplishing this simple task??

Tips appreciated!

Thanks,
Scott B.
0 Likes
511 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
(not ss1) will return T if the selection set is empty.
0 Likes
Message 3 of 8

Anonymous
Not applicable
(if ss1
(progn
do something
)
(prompt "\nNothing selected!")
)

-gnb

Scott Bellows wrote:

> When aquiring a selection set with ssget for all "dimension" in a drawing
> with (setq ss1 (ssget "x" '((0 . "dimension")))), I would like to check to
> see if it is not nil before working on it. I've tried (if (/= ss1 nil))
> and (if (/= ss1 "")), but these don't seem to work. Does anybody know the
> correct way of accomplishing this simple task??
>
> Tips appreciated!
>
> Thanks,
> Scott B.
0 Likes
Message 4 of 8

Anonymous
Not applicable
I think what you need here is the (null) function. (null item) verifies that
the item, in this case your ss1, is bound to nil. and the (not) reverses the
result...

So instead of (if (/= ss1 nil)...)
you should use (if (not (null ss1)) ...)

HTH,
David

Scott Bellows wrote:

> When aquiring a selection set with ssget for all "dimension" in a drawing
> with (setq ss1 (ssget "x" '((0 . "dimension")))), I would like to check to
> see if it is not nil before working on it. I've tried (if (/= ss1 nil))
> and (if (/= ss1 "")), but these don't seem to work. Does anybody know the
> correct way of accomplishing this simple task??
>
> Tips appreciated!
>
> Thanks,
> Scott B.
0 Likes
Message 5 of 8

Anonymous
Not applicable
Nope.

(if ss1 ...)

is all you need.
__
David Brewer wrote in message
news:384FF32F.354165F6@onr.com...
> I think what you need here is the (null) function. (null item)
verifies that
> the item, in this case your ss1, is bound to nil. and the (not)
reverses the
> result...
>
> So instead of (if (/= ss1 nil)...)
> you should use (if (not (null ss1)) ...)
0 Likes
Message 6 of 8

Anonymous
Not applicable
I have to agree. (not (null)) is a double negative and therefore amounts to
no test at all. Which is why Paul recommended the simple (if ss1) in the
first place.

"Paul Turvill" wrote in message
news:82p3kv$qgk4@adesknews2.autodesk.com...
> Nope.
>
> (if ss1 ...)
>
> is all you need.
> __
> David Brewer wrote in message
> news:384FF32F.354165F6@onr.com...
> > I think what you need here is the (null) function. (null item)
> verifies that
> > the item, in this case your ss1, is bound to nil. and the (not)
> reverses the
> > result...
> >
> > So instead of (if (/= ss1 nil)...)
> > you should use (if (not (null ss1)) ...)
>
>
>
0 Likes
Message 7 of 8

Anonymous
Not applicable
I disagree, Frank... in lisp, (not (null ss1)) is not a double negative...
(not) is a negative, but (null ss1) tests to see if the item is bound to nil
(nothing). If ss1 is not nil; (not (null ss1)) returns T, which is what he was
trying to do with with (/= ss1 nil)...

As someone else said earlier, there is always several ways to get where you're
going in Lisp.

BUT, as Paul pointed out... all of this amounts to nil anyway, since (if ss1
...) is all that's really necessary to test ss1..... 🙂

Frank Oquendo wrote:

> I have to agree. (not (null)) is a double negative and therefore amounts to
> no test at all. Which is why Paul recommended the simple (if ss1) in the
> first place.
>
> "Paul Turvill" wrote in message
> news:82p3kv$qgk4@adesknews2.autodesk.com...
> > Nope.
> >
> > (if ss1 ...)
> >
> > is all you need.
> > __
> > David Brewer wrote in message
> > news:384FF32F.354165F6@onr.com...
> > > I think what you need here is the (null) function. (null item)
> > verifies that
> > > the item, in this case your ss1, is bound to nil. and the (not)
> > reverses the
> > > result...
> > >
> > > So instead of (if (/= ss1 nil)...)
> > > you should use (if (not (null ss1)) ...)
> >
> >
> >
0 Likes
Message 8 of 8

Anonymous
Not applicable
>So instead of (if (/= ss1 nil)...)
>you should use (if (not (null ss1)) ...)

>...in lisp, (not (null ss1)) is not a double negative...
>(not) is a negative, but (null ss1) tests to see if the item is bound to nil
>(nothing). If ss1 is not nil; (not (null ss1)) returns T, which is what he was
>trying to do with with (/= ss1 nil)...

Bleah!

As I'msure you know, any variable that is "bound to nil" is exactly
the same as an unbound variable for the purposes of conditional
testing. Conditional expressions always test for a non-nil evaluation,
i.e. a variable bound to a value or another test expression that
passes. Anything else is nil and the test fails. Whether some variable
was explicitly set to nil is irrelevant.

e.g.

!var
nil

(if var "Yup") -> nil
(setq var nil) -> nil
(null var) -> T
(if var "Yup") -> nil

In short, any conditional test that performs a (not (null var)) is
about as redundant and sloppy as you can get, and you probably didn't
properly set up the test expression to begin with.

> When aquiring a selection set with ssget for all "dimension" in a drawing
> with (setq ss1 (ssget "x" '((0 . "dimension")))), I would like to check to
> see if it is not nil before working on it. I've tried (if (/= ss1 nil))
> and (if (/= ss1 "")), but these don't seem to work. Does anybody know the
> correct way of accomplishing this simple task??

The correct way of doing this is

(if (setq ss1 (ssget "x" '((0 . "dimension"))))
(DoSomething)
(DoSomethingElse)
)

Also, the string "" is NOT the same as nil - it is a null string
value.

Matt
stachoni@bellatlantic.net

On Sun, 12 Dec 1999 00:05:08 -0600, David Brewer
wrote:

>I disagree, Frank... in lisp, (not (null ss1)) is not a double negative...
>(not) is a negative, but (null ss1) tests to see if the item is bound to nil
>(nothing). If ss1 is not nil; (not (null ss1)) returns T, which is what he was
>trying to do with with (/= ss1 nil)...
>
>As someone else said earlier, there is always several ways to get where you're
>going in Lisp.
>
>BUT, as Paul pointed out... all of this amounts to nil anyway, since (if ss1
>...) is all that's really necessary to test ss1..... 🙂
>
>
>Frank Oquendo wrote:
>
>> I have to agree. (not (null)) is a double negative and therefore amounts to
>> no test at all. Which is why Paul recommended the simple (if ss1) in the
>> first place.
>>
>> "Paul Turvill" wrote in message
>> news:82p3kv$qgk4@adesknews2.autodesk.com...
>> > Nope.
>> >
>> > (if ss1 ...)
>> >
>> > is all you need.
>> > __
>> > David Brewer wrote in message
>> > news:384FF32F.354165F6@onr.com...
>> > > I think what you need here is the (null) function. (null item)
>> > verifies that
>> > > the item, in this case your ss1, is bound to nil. and the (not)
>> > reverses the
>> > > result...
>> > >
>> > > So instead of (if (/= ss1 nil)...)
>> > > you should use (if (not (null ss1)) ...)
>> >
>> >
>> >
0 Likes