Author Topic: Maybe I'm just thick - Cond question...  (Read 2749 times)

0 Members and 1 Guest are viewing this topic.

bruno_vdh

  • Newt
  • Posts: 107
Re: Maybe I'm just thick - Cond question...
« Reply #15 on: August 01, 2023, 03:52:45 AM »
OK, maybe I'm just thick. Is one of these 2 snippets correct? Are they the same?  :uglystupid2:
#1 can be written with or, while #2 can only be constructed with cond, if that helps your thinking...

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Maybe I'm just thick - Cond question...
« Reply #16 on: August 01, 2023, 11:38:44 AM »
For me a simpler way to read the cond

Code: [Select]
     (cond
             ((wcmatch txt1 "UPD Not Found"))(setq txt TXT1))
             ((wcmatch txt2 "UPD Not Found"))(setq txt TXT2))
             ((null FULL))(setq txt full)
             ((setq txt "NO TAG#"))
     );;_end cond
"Unbalanced closing brackets."

Also .. you can pull the (setq txt outside of the COND and only return the values.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BIGAL

  • Swamp Rat
  • Posts: 1429
  • 40 + years of using Autocad
Re: Maybe I'm just thick - Cond question...
« Reply #17 on: August 01, 2023, 08:47:07 PM »
Thanks ronjonp just typed did not check

Code: [Select]
(cond
             ((wcmatch txt1 "UPD Not Found")(setq txt TXT1))
             ((wcmatch txt2 "UPD Not Found")(setq txt TXT2))
             ((null FULL)(setq txt full))
             ((setq txt "NO TAG#"))
     );;_end cond
A man who never made a mistake never made anything

steve.carson

  • Newt
  • Posts: 108
Re: Maybe I'm just thick - Cond question...
« Reply #18 on: August 02, 2023, 10:58:22 AM »
I know when I first started using cond, I always got tripped up by the parenthesis so I would type something like this first, just to keep things straight in my head:

Code - Auto/Visual Lisp: [Select]
  1.     ((         ) ;<-- First test
  2.         (          ) ;<-- Do this
  3.         (          ) ;<-- And this
  4.     )
  5.     ((         ) ;<-- Second test
  6.         (          ) ;<-- Do this
  7.         (          ) ;<-- And this
  8.     )
  9.     ((         ) ;<-- Third test
  10.         (          ) ;<-- Do this
  11.         (          ) ;<-- And this
  12.     )
  13. ); cond
  14.  

And then go back and start filling it in with what I want it to do.

CHulse

  • Swamp Rat
  • Posts: 504
Re: Maybe I'm just thick - Cond question...
« Reply #19 on: August 02, 2023, 11:53:21 AM »
This is what I eventually ended up with (and is working nicely).
Thanks to everyone for the help with this.

Code - Auto/Visual Lisp: [Select]
  1.                         (setq TXT
  2.                                 (cond
  3.                                         ((not(or (wcmatch TAG1 "UPD Not Found,0,")(null TAG1))) ;;check if UDP not found, empty string, 0, or null
  4.                                                 TAG1
  5.                                         )
  6.                                         ((not(or(wcmatch TAG2 "UPD Not Found,0,")(null TAG2)))
  7.                                                 TAG2
  8.                                         )
  9.                                         ((not(or(wcmatch FULL "0,")(null FULL) ))  
  10.                                                 FULL
  11.                                         )      
  12.                                         ( T
  13.                                                 "NO TAG#"
  14.                                         )
  15.                                 );;_end cond   
  16.                         );;_end setq
  17.  
Cary Hulse
Urban Forestry Manager
Wetland Studies and Solutions

Civil 3D 2020 & 2023

bruno_vdh

  • Newt
  • Posts: 107
Re: Maybe I'm just thick - Cond question...
« Reply #20 on: August 03, 2023, 03:55:19 AM »
Hi,
This is what I eventually ended up with (and is working nicely).

Just a small note, it is better to check if the variable is null first:
Code: [Select]
_$ (setq TAG1 nil)
nil
_$ (not (or (wcmatch TAG1 "UPD Not Found,0,") (null TAG1)))
; erreur: type d'argument incorrect: stringp nil
_$ (not (or (null TAG1) (wcmatch TAG1 "UPD Not Found,0,")))
nil

bruno_vdh

  • Newt
  • Posts: 107
Re: Maybe I'm just thick - Cond question...
« Reply #21 on: August 03, 2023, 05:29:19 AM »
Just a small note, it is better to check if the variable is null first:
Code: [Select]
_$ (setq TAG1 nil)
nil
_$ (not (or (wcmatch TAG1 "UPD Not Found,0,") (null TAG1)))
; erreur: type d'argument incorrect: stringp nil
_$ (not (or (null TAG1) (wcmatch TAG1 "UPD Not Found,0,")))
nil

To avoid type errors, you can also use the member function as a predicate
Code - Auto/Visual Lisp: [Select]
  1. (not (member TAG1 '("UPD Not Found" "0" "" nil)))