Author Topic: Chasing my tail!  (Read 2927 times)

0 Members and 1 Guest are viewing this topic.

Water Bear

  • Guest
Chasing my tail!
« on: January 30, 2004, 11:14:20 PM »
I'm trying to establish a routine that draws duct. Before anything I'd like to get the users input  (or partial input) and compute the rest. I'm also trying to check that the piece that the user is inputting CAN be made. That is, it will fit on the material and will not severly restrict air flow. however the initial setup is becoming so convoluted that i can't see the flaw..can anyone tell me why I can't get out of this loop?

Code: [Select]
(defun mytest ()
  (setq #dep1 24.0 ;for test purposes
#wid1 12.0
)
  (if (or (> #wid1 24) (> #dep1 24))
    (setq stock 59.25
 slips 1.375
 )
    (setq stock 60.0
 slips 0.5
 )
    )
  ;;fill in blanks, if any
  (if st1
    nil
    (setq st1 2.0)
    )
  (if st2
    nil
    (setq st2 2.0)
    )
;;;calc max and min duct sizes (to fit on sheet)
  (setq slpmat  (- stock (+ st1 st2 (* slips 2.0)))
area_sqin (* #wid1 #dep1) ;area in sq inches
)
  (while
    (setq offer (sqrt area_sqin))
;;;Ask for width, offer square
     (setq
       #wid2 (getreal
      (strcat "\nEnter duct WIDTH2 <" (rtos offer 5 1) ">:")
      )
       )
;;;if a width value is entered, ask for depth re-calculate offer based on area
     (if #wid2
       (progn
(setq offer (/ area_sqin #wid2))
(setq
  #dep2
   (getreal
     (strcat "\nEnter duct DEPTH2 <" (rtos offer 5 1) ">:")
     )
  )
)
;;;if no width value entered ask for depth use original square of area as offer
       (setq
#dep2 (getreal
(strcat "\nEnter duct DEPTH2 <" (rtos offer 5 1) ">:")
)
)
       )
;;;if a depth value is entered, verify width by re-calculation
     (if (and (null #wid2) #dep2)
       (progn
(setq offer (/ area_sqin #dep2))
(setq
  #wid2
   (getreal
     (strcat "\nEnter duct WIDTH2 <" (rtos offer 5 1) ">:")
     )
  )
)

       )

;;;if width has been left null set it offer (square)
     (if (null #wid2)
       (setq #wid2 offer)
       )
;;;if depth has been left null set it to offer (square)
     (if (null #dep2)
       (setq #dep2 offer)
       )

     (if
       (or (> (/ (abs (- #wid1 #wid2)) 2.0) slpmat)
  (> (/ (abs (- #dep1 #dep2)) 2.0) slpmat)
  )

(prompt "\nAdjust aspect ratio is FUBAR...try again")
nil
)
     ) ;while
  )

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Chasing my tail!
« Reply #1 on: January 30, 2004, 11:34:51 PM »
Sure can....
You are setting the value of area_sqin BEFORE you step into the WHILE loop and the WHILE loop simply does a mathematical calculation on area_sqin which will always return T unless there is no value in area_sqin. There is not a good way to do this because if you clear out area_sqin you will crash horribly because you cannot get the (SQRT area_sqin) if it is equal to nil .....

So.....
You need to test for a different value in the while statement ... First answer at what point do you want the loop to terminate? According to your code the loop will terminate as soon as you can no longer retrieve the value of (SQRT area_sqin) which will never happen.

I would think that you would want to terminate the while loop based upon gathering all of the correct information, try setting a tag in the "FUBAR" portion of the code like:
Code: [Select]

(if(or(>(/ (abs (- #wid1 #wid2)) 2.0) slpmat)
       (> (/ (abs (- #dep1 #dep2)) 2.0) slpmat)
   ) ;_ end of or
     (prompt "\nAdjust aspect ratio is FUBAR...try again")
     (setq exitloop t)
) ;_ end of if

 
then make your while statement ....

Code: [Select]

(while (not exitloop)
.......;do this stuff
)


Finally make exitloop a local variable in the defun line OR setq it to nil just before the proggie ends.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Water Bear

  • Guest
Chasing my tail!
« Reply #2 on: January 31, 2004, 08:19:30 AM »
Thanx Keith...
Quote
I would think that you would want to terminate the while loop based upon gathering all of the correct information, try setting a tag in the "FUBAR" portion of the code like:

    code:  
    (if(or(>(/ (abs (- #wid1 #wid2)) 2.0) slpmat)
           (> (/ (abs (- #dep1 #dep2)) 2.0) slpmat)
       ) ;_ end of or
         (prompt "\nAdjust aspect ratio is FUBAR...try again")
         (setq exitloop t)
    ) ;_ end of if



then make your while statement ....

    code:
    (while (not exitloop)
    .......;do this stuff
    )


The only problem is..that IF "FUBAR" returns T I need to start all over from the top! Would I just repeat all the code in the "while(not exitloop)"?

P.S........Nevermind I got it!
Thanx again..