Author Topic: Null vs empty?  (Read 11414 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Null vs empty?
« Reply #45 on: August 10, 2018, 12:24:13 PM »
Another (slower):
Code: [Select]
(defun test-str-9 (l) (eq (1+ (strlen (vl-string-trim "()" (vl-princ-to-string l)))) (length l)))

Nice and it's probably pretty quick but it doesn't meet the specifications--to error upon non-string entries (int, nil, list, etc).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Null vs empty?
« Reply #46 on: August 10, 2018, 12:37:22 PM »
Ok the horse is dead.
Code - Auto/Visual Lisp: [Select]
  1. ;; Make John happy ( but maybe not )
  2. (defun _chk (k l) (apply '= (cons k l)))
  3. (_chk "" (setq l '("" "" "" "" "" "" "" "")))
  4. (_chk 1 '(1 1 1 1 1 1 1))
  5. (_chk nil '(nil nil nil nil nil nil nil))
  6.  

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Null vs empty?
« Reply #47 on: August 10, 2018, 12:52:02 PM »
Ok the horse is dead.
Code - Auto/Visual Lisp: [Select]
  1. ;; Make John happy ( but maybe not )
  2. ...
  3.  

Ha! Sorry, not my rule. The rule (as I understand it) is that the function should fail/error/whatever--because there will/should never be anything other than a string in the list--immediately (no check, no return, no cleanup).

Here is a very quick tally of the posted functions that pass specifications (double check please. I don't think I got them all and I didn't see test-str-8.).
Code - Auto/Visual Lisp: [Select]
  1.              (test-str l)
  2.              ;; (test-str-2 l)          ;; does not error
  3.              ;; (_allemptystrings l)    ;; does not error
  4.              ;; (test-str-3 l)          ;; does not error
  5.              ;; (test-str-4 l)          ;; does not error
  6.              ;; (test-str-5 l)          ;; does not error
  7.              (test-str-6 l)
  8.              (test-str-7 l)
  9.              ;; (test-str-9 l)          ;; does not error
  10.  
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Null vs empty?
« Reply #48 on: August 10, 2018, 01:02:27 PM »
If you're comparing a key to a list ( function above ) why should it 'fail'? It's either T or nil and can accept multiple datatypes to test. Perhaps happiness is not in the cards for you.  ;)  Have a nice weekend.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Null vs empty?
« Reply #49 on: August 10, 2018, 02:06:41 PM »
If you're comparing a key to a list ( function above ) why should it 'fail'? It's either T or nil and can accept multiple datatypes to test. Perhaps happiness is not in the cards for you.  ;)  Have a nice weekend.
How should I know why it `has to fail'?! I asked several different times/ways.
I agree (and the "Key comparison method" is one of the most efficient methods for this task) but I was told otherwise when I raised that very point.

You ask; I don't have the reputation points to get a reply.

Wait a minute. If happiness isn't in the cards for me do you really think my weekend will be nice? :)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Null vs empty?
« Reply #50 on: August 10, 2018, 02:23:19 PM »
If you're comparing a key to a list ( function above ) why should it 'fail'? It's either T or nil and can accept multiple datatypes to test. Perhaps happiness is not in the cards for you.  ;)  Have a nice weekend.

Wait a minute. If happiness isn't in the cards for me do you really think my weekend will be nice? :)
There is a very small possibility  :)  ... no really, have a nice weekend.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Null vs empty?
« Reply #51 on: August 10, 2018, 02:26:51 PM »
Anytime with the wife and kids is nice! You too.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Null vs empty?
« Reply #52 on: August 11, 2018, 02:17:48 AM »
Another (slower):
Code: [Select]
(defun test-str-9 (l) (eq (1+ (strlen (vl-string-trim "()" (vl-princ-to-string l)))) (length l)))

Nice and it's probably pretty quick but it doesn't meet the specifications--to error upon non-string entries (int, nil, list, etc).
Code: [Select]
; (test-str-3 + test-str)
(defun AllEmptyStrings (l / o)
  (cond
    ( (not (setq o (vl-remove "" l))) )
    ( (not (apply 'strcat o)) )
  )
)
(AllEmptyStrings '("" "" "" )) ==> T
(AllEmptyStrings '("" "" "1")) ==> nil
(AllEmptyStrings '("" "" 1  )) ==> error
(AllEmptyStrings '("" "" nil)) ==> error
(AllEmptyStrings '("" "" '())) ==> error

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Null vs empty?
« Reply #53 on: August 11, 2018, 09:14:51 AM »
<…>
Here is a very quick tally of the posted functions that pass specifications (double check please. I don't think I got them all and I didn't see test-str-8.).
Code - Auto/Visual Lisp: [Select]
  1.              (test-str l)
  2.              ;; (test-str-2 l)          ;; does not error
  3.              ;; (_allemptystrings l)    ;; does not error
  4.              ;; (test-str-3 l)          ;; does not error
  5.              ;; (test-str-4 l)          ;; does not error
  6.              ;; (test-str-5 l)          ;; does not error
  7.              (test-str-6 l)
  8.              (test-str-7 l)
  9.              ;; (test-str-9 l)          ;; does not error
  10.  
Command: (test-str-7 '("" "1" "" ""))
T