Author Topic: Help with "if" and "="  (Read 2300 times)

0 Members and 1 Guest are viewing this topic.

DanB

  • Bull Frog
  • Posts: 367
Help with "if" and "="
« on: February 15, 2005, 05:14:27 PM »
Looking for some clarifications on what is taking place in the following code:

Code: [Select]

  (if BLK
    (progn
      (setq TYP (strcat "\nBlock to Insert: <" BLK "> "))
      (setq BLK (if (= (setq CTP (getstring TYP)) "") BLK CTP))
     )
      (setq BLK (getstring "\nBlock to Insert: "))
   )


My take on this:
If the variable BLK is NOT defined then prompt user "Block to Insert: " thus setting the variable BLK to the input. (I think I'm okay with this part)

If variable BLK is defined then prompt user "Block to Insert: <" BLK "> " while displaying BLK's value in <>
The user input at this line is stored in variable TYP. (Here's where I'm not following along). Are we checking to see if BLK and CTP are equal at this point? with the variable CTP being the value of TYP (a text string from previous user input). Can anyone help walk me through this?

Thanks,
Dan

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help with "if" and "="
« Reply #1 on: February 15, 2005, 05:40:40 PM »
Dan
You walked yourself thought it very well.
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.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Help with "if" and "="
« Reply #2 on: February 15, 2005, 06:58:10 PM »
Quote from: DanB

The user input at this line is stored in variable TYP. (Here's where I'm not following along). Are we checking to see if BLK and CTP are equal at this point? with the variable CTP being the value of TYP (a text string from previous user input). Can anyone help walk me through this?

Dan,  I can see how you could be confused the way it is written:
Code: [Select]
(setq BLK (if (= (setq CTP (getstring TYP)) "") BLK CTP))
Here's another way of writing it that may make it clearer to you:
Code: [Select]

(setq CTP (getstring TYP))
(if (= CTP "");;if user presses enter or spacebar
   (setq BLK BLK) ;;leave the block the same as it was
   (setq BLK CTP);;nope, a new value was entered, lets use it now
 )
 


Does that make more sense?

DanB

  • Bull Frog
  • Posts: 367
Help with "if" and "="
« Reply #3 on: February 16, 2005, 07:33:26 AM »
Quote

Does that make more sense?


It does now, thanks for the clarification.