Author Topic: Basics: NULL versus NOT versus (= NIL) versus (equal NIL) ...  (Read 2756 times)

0 Members and 1 Guest are viewing this topic.

Peter2

  • Swamp Rat
  • Posts: 654
Basics: NULL versus NOT versus (= NIL) versus (equal NIL) ...
« on: January 13, 2014, 06:11:04 AM »
There  are some ways to test the non-existence (NIL) of a value:
Code: [Select]
(null mynonvalue)
(not mynonvalue)
(equal nil mynonvalue)
(= nil mynonvalue)
The help for NOT and NULL is nearly the same and uses the same example, EQUAL and = or /= are another approach ...

Is there an important difference between or an important malpractice of these codes?
Or is it to 95% a question of personal style?

Regards
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Basics: NULL versus NOT versus (= NIL) versus (equal NIL) ...
« Reply #1 on: January 13, 2014, 06:23:36 AM »
For the null/not I think it's about personal style and symantics. They both do the exact same thing: test if something evaluates to nil. Usually I'd use null to test if a variable contains nil, and not to test if an expression evaluates to nil, just because it "seems" more logical that way (to me). But both would work fine interchangeably.

As for =, eq, and equal. There is some differences which you need to be aware of. = and eq are "nearly" the same thing, though eq tends to make string comparisons less error-prone. Equal is much more involved, it can even compare to a fuzz factor.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Basics: NULL versus NOT versus (= NIL) versus (equal NIL) ...
« Reply #2 on: January 13, 2014, 08:49:16 AM »
To confuse the subject you can use AND & OR for some test:
Code: [Select]
Command: (and t)
T

Command: (and nil)
nil
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Peter2

  • Swamp Rat
  • Posts: 654
Re: Basics: NULL versus NOT versus (= NIL) versus (equal NIL) ...
« Reply #3 on: January 13, 2014, 09:15:04 AM »
... though eq tends to make string comparisons less error-prone. Equal is much more involved, it can even compare to a fuzz factor.
But comparing with NIL it should be the same, isn't it?
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Basics: NULL versus NOT versus (= NIL) versus (equal NIL) ...
« Reply #4 on: January 13, 2014, 09:22:45 AM »
But comparing with NIL it should be the same, isn't it?
Yes, comparing with nil - then =, eq and equal should do the same thing. Though I try to use = only where numbers / booleans (T/nil) are concerned, eq in most other cases, equal only where I want to compare lists or add some fuzz-factor.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Basics: NULL versus NOT versus (= NIL) versus (equal NIL) ...
« Reply #5 on: January 13, 2014, 09:34:38 AM »
In lisp nil is an empty list. Otherwise you have to do a LOT of error trapping

Code: [Select]
(cdr (assoc "XYZ" nil))
Would return an error if nil were simply a (not T) value instead of a list

Code: [Select]
(listp nil) T
(equal nil '() 1e-8) T

For a purist (NULL item) verifies that the item is bound to nil

Though a lot is your personal style, some of the tests do have specific uses
ie ( eq ) works on enames.

-David




R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: Basics: NULL versus NOT versus (= NIL) versus (equal NIL) ...
« Reply #6 on: January 14, 2014, 03:36:07 PM »
Personally, I tend to use null to test whether a symbol is bound to nil (i.e. whether a variable is null), and would reserve not for negating boolean expressions:
Code: [Select]
(null myvar)
Code: [Select]
(if (not (wcmatch "foo" "bar"))
    ...
From what I can tell, I think this is similar to Irné's opinion on the topic above.

Peter2

  • Swamp Rat
  • Posts: 654
Re: Basics: NULL versus NOT versus (= NIL) versus (equal NIL) ...
« Reply #7 on: January 16, 2014, 01:26:10 PM »
Thanks to all for the comments - one step more to improve my style.
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23