Lookup Table Text value

Lookup Table Text value

Anonymous
Not applicable
814 Views
1 Reply
Message 1 of 2

Lookup Table Text value

Anonymous
Not applicable

Hello

 

I am trying to a function which will return if it finds anything in a list otherwise it will return false(nill) in this case, but it keeps returning true;l

 

thank you

 

 

(defun lookup(someval)
(setq listofvalue (list "Apple" "Boat" "Fan" "List"))
(foreach itm listofvalue
(if (wcmatch (strcase someval) itm)
T
)
)
nil
)
(defun c:test ()
(if (lookup "Affp*")
princ "An apple was found!"
)
)
0 Likes
Accepted solutions (1)
815 Views
1 Reply
Reply (1)
Message 2 of 2

Ajilal.Vijayan
Advisor
Advisor
Accepted solution

Hi,

Welcome to this forum.

 

I think you need to consider below things.

  1. The test command was printing the found message as the parentheses was missing for princ inside the if function.
  2. wcmatch second argument should be the match pattern, so you have to swap the arguments.
  3. And add a new variable to return the result, if wcmatch found ant match this should return T
  4. Also please note that wcmatch is case-sensitive, so as you are using strcase in your code the match pattern will return nil in the case of (wcmatch "Apple" "APP*")

 

Please find the code in here.

Spoiler
(defun lookup(someval)
(setq rslt nil)
(setq listofvalue (list "Apple" "Boat" "Fan" "List"))
(foreach itm listofvalue
(if (wcmatch itm (strcase someval))
(setq rslt T);if match found then set the rslt value to T
)
)
rslt
)

(defun c:test ()
(if (lookup "Affp*")
(princ "An apple was found!")
)
)