PDA

View Full Version : Make LISP non-case sensitive when using IF statement


ReachAndre
2007-03-23, 03:55 PM
Hello all, Finally I am getting into the "if" function.
My problem so far is that my values seem to be case sensitive so I am writing alot of duplicates. Is there a way to make lisp non-case sensitive? Example below

(defun c:casesen (/ alertaction)
(setq alertaction (getstring "Create an alert action? (Sure/Rathernot): "))
(if
(= alertaction "s")
(setq alertaction "S")
)
(if
(= alertaction "S")
(alert "There is your alert")
)
(if
(= alertaction "r")
(setq alertaction "R")
)
(if
(= alertaction "R")
(alert "no alert action taken")
)
(princ)
)[ Moderator Action = ON ] What are [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]

jmcshane
2007-03-23, 04:08 PM
You could use the strcase which forces the text to uppercase.



(defun c:casesen (/ alertaction)
(setq alertaction (strcase (getstring "Create an alert action? (Sure/Rathernot): ")))
(if
(= alertaction "S")
(alert "There is your alert")
)
(if
(= alertaction "R")
(alert "no alert action taken")
)
(princ))

ReachAndre
2007-03-23, 04:34 PM
Thankyou very much

kennet.sjoberg
2007-03-23, 08:56 PM
. . .or downcase

(strcase "Make me DownCase" T ) --> "make me downcase"
(strcase "Make me UpperCASE" nil ) --> "MAKE ME UPPERCASE"

: ) Happy Computing !

kennet

abdulhuck
2007-03-25, 11:32 AM
Is there a way to make lisp non-case sensitive? Example below

(defun c:casesen (/ alertaction)
(setq alertaction (getstring "Create an alert action? (Sure/Rathernot): "))

Hi,

Though not an answer to your question, I would suggest an alternative to your task. Try to use getkword function wherever you need to get a keyword as an answer.


(defun c:casesen (/ alertaction)
(initget "Sure Rathernot") ; will accept only these two words
(setq alertaction (getkword "\nCreate an alert action? (Sure/Rathernot): "))
(if (= alertaction "Sure")
(then do sure things)
(do unsure things)
)


It's very convenient, you can capitalize the required user inputs in any part of the word.

(initget "One Two tHree")
(setq ans (getkword "\nOption one, two or three <O/T/H>: "))
(cond
(( = ans "One") (then process first option))
(( = ans "Two") (then process second option))
(( = ans "tHree") (then process third option))
)


Regards

jaseh
2007-03-27, 01:43 PM
This is off on a different tack, but I thought it worth sharing for anyone unaware,

(initget "One Two tHree")
(setq ans (getkword "\nOption one, two or three [One/Two/tHree]: "))

Using square brackets "[One/Two/tHree]" in the above statement means any options will be available to the user on the mouse right click context sensitive menu.

jmcshane
2007-03-27, 01:56 PM
Completely unaware....
Thats a nice little touch
Cheers jaseh

abdulhuck
2007-03-28, 10:46 PM
Using square brackets "[One/Two/tHree]" in the above statement means any options will be available to the user on the mouse right click context sensitive menu.
Cool, thanks

Regards,
AbdulHuck

jaseh
2007-03-29, 10:15 AM
No problem, glad to share any tips that help. I always thought it added a neat little polish

kennet.sjoberg
2007-03-29, 02:35 PM
. . .2 years later LINK (http://forums.augi.com/showthread.php?t=18356#post117170) ;)

: ) Happy Computing !

kennet