The top Cond comes up just T just and will not run

The top Cond comes up just T just and will not run

cadking2k5
Advocate Advocate
888 Views
8 Replies
Message 1 of 9

The top Cond comes up just T just and will not run

cadking2k5
Advocate
Advocate

I have something like this the top option on the Cond list will not work it just comes up T on the command line no matter which one I put in the top one I can rearrange them and whatever is in the top comes up T and will not run.
(DEFUN C:THREAD ()
(initget 1 "U A B W M V R Unified Acme Buttress Whitworth ModifiedSqr SharpV woRm")
(setq option (getkword "\nPick a type of Thread [Unified/Acme/Buttress/Whitworth/ModifiedSqr/sharpV/woRm]:<U> "))
(if (null option)(setq option "U"))
(cond
((or
(= option "U")
(= option "Unified")
(unf)
)
)
((or
(= option "A")
(= option "Acme")
(acm)
)
)
((or
(= option "B")
(= option "Buttress")
(but)
)
)
((or
(= option "M")
(= option "ModifiedSqr")
(msq)
)
)
((or
(= option "V")
(= option "SharpV")
(shv)
)
)
((or
(= option "W")
(= option "Whitworth")
(ww)
)
)
((or
(= option "r")
(= option "woRm")
(wrm)
)
)
)
)
(defun unf ()
xxxxxxxxxxx
)
(defun acm ()
xxxxxxxxxxx
)
(defun shv ()
xxxxxxxxxxx
)
(defun but ()
xxxxxxxxxxx
)
(defun msq()
xxxxxxxxxxx
)
(defun ww()
xxxxxxxxxxx
)
(defun wrm ()
xxxxxxxxxxx
)

0 Likes
889 Views
8 Replies
Replies (8)
Message 2 of 9

cadking2k5
Advocate
Advocate

I figured it out need to move the ) to like this
((or
(= option "V")
(= option "SharpV")

)
(shv)
)

0 Likes
Message 3 of 9

Kent1Cooper
Consultant
Consultant

In addition, you can simplify this quite a bit, by taking advantage of the nature of (initget)/(getkword) structure.  You don't need to list the individual letters in addition to  the keywords.  The whole point of this structure is that a User can type in either the specified letter(s), not case-sensitive, or any more than that all the way up to the entire word, and in all cases it will return the entire word as listed in the (initget) string.  Then you can test for just that entire word only, regardless of how the User got to it, and not  for the initial letters.  You can do this:

(DEFUN C:THREAD ()
(initget 1 "Unified Acme Buttress Whitworth ModifiedSqr sharpV woRm"); none of the individual letters included
(setq option (getkword "\nPick a type of Thread [Unified/Acme/Buttress/Whitworth/ModifiedSqr/sharpV/woRm]:<U> "))
(if (null option)(setq option "Unified")); [spell it out all the way -- that's what will be tested for]
(cond
  ((= option "Unified") (unf))

  ((= option "Acme") (acm))

  ....
)

Kent Cooper, AIA
0 Likes
Message 4 of 9

ВeekeeCZ
Consultant
Consultant

@Kent1Cooper wrote:

...
(initget 1 "Unified Acme Buttress Whitworth ModifiedSqr sharpV woRm"); none of the individual letters included
(setq option (getkword "\nPick a type of Thread [Unified/Acme/Buttress/Whitworth/ModifiedSqr/sharpV/woRm] <Unified>: "))
(if (null option)(setq option "Unified")); [spell it out all the way -- that's what will be tested for]...


 

One more fault spotted - you need to allow the <enter> option by NOT using 1 in the INITGET function.

0 Likes
Message 5 of 9

ronjonp
Mentor
Mentor

You could also do something like this .. it's an easy way to make sure your options always show up:

(defun c:thread	(/ o)
  (initget (setq o "Unified Acme Buttress Whitworth ModifiedSqr sharpV woRm"))
  (alert
    (cond
      ((getkword (strcat "\nPick a type of Thread [" (vl-string-translate " " "/" o) "]:<Unified>")))
      ("Unified")
    )
  )
  (princ)
)
0 Likes
Message 6 of 9

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

....
(cond
  ((= option "Unified") (unf))

  ((= option "Acme") (acm))

  ....
)


 

Once you've gotten the 'option' variable string, you can carry on with the above approach:

 

  (cond
    ((= option "Unified") (unf))
    ((= option "Acme") (acm))
    ((= option "Buttress") (but))
    ((= option "ModifiedSqr") (msq))
    ((= option "SharpV") (shv))
    ((= option "Whitworth") (ww))
    ((= option "woRm") (wrm))
  ); cond

 

OR you can eliminate all that repetition of   ((= option   over and over again, by instead of using (cond), using an association list  to run the function associated with the string in a little two-item sub-list:

 

  (eval ; evaluate the item, recognize its parentheses and call the function
    (cadr ; second item in the sub-list
      (assoc option ; returns the sub-list whose first item  is the 'option' string
        '(("Unified" (unf)) ("Acme" (acm)) ("Buttress" (but)) ("ModifiedSqr" (msq))
          ("SharpV" (shv)) ("Whitworth" (ww)) ("woRm" (wrm)))
      ); assoc
    ); cadr
  ); eval

Kent Cooper, AIA
Message 7 of 9

ronjonp
Mentor
Mentor

Here's another example to simplify what you're doing:

(defun c:thread	(/ o)
  ;; Make your subs the same name as your options ( you could even use the first three letters of each )
  (mapcar '(lambda (x) (eval (read (strcat "(defun " x " nil (alert \"" x "\"))"))))
	  '("Unified" "Acme" "Buttress" "Whitworth" "ModifiedSqr" "sharpV" "woRm")
  )
  (initget (setq o (strcase "Unified Acme Buttress Whitworth ModifiedSqr sharpV woRm")))
  (setq	o
	 (cond
	   ((getkword (strcat "\nPick a type of Thread [" (vl-string-translate " " "/" o) "]:<Unified>")
	    )
	   )
	   ("Unified")
	 )
  )
  ;; Then this is all you need to run them :)
  (eval (read (strcat "(" o ")")))
  ;; This would evaluate the first three letters of each option
  ;; (eval (read (strcat "(" (substr o 1 3) ")")))
  (princ)
)
0 Likes
Message 8 of 9

john.uhden
Mentor
Mentor

IMHO, you guys are not going to one-up the alpha elite here.

John F. Uhden

0 Likes
Message 9 of 9

ronjonp
Mentor
Mentor

Huh ? Just showing another way to organize this which IMO is more succinct.

0 Likes