Each of these returns T as follows...
(wcmatch "ROOM#" "*`#*,*NUM*,*NO")
T
_$ (wcmatch "ROOMNO" "*`#*,*NUM*,*NO")
T
_$ (wcmatch "ROOMNUM" "*`#*,*NUM*,*NO")
T
I am looking for code that will use a combination of Wcmatch with the Assoc function...
(setq PairLstA (list (list "ROOM#" "195)(list "ROOMNAME" "REST ROOM")))
(setq PairLstB (list (list "NAME" "MEN'S ROOM")(list "ROOMNUM" "385")))
(setq PairLstC (list (list "ROOMNO" "495")(list "ROOMNM" "WOMEN'S ROOM")))
(WcAssoc "*`#*,*NUM*,*NO" PairLstA)
should return... ("ROOM#" "195")
(WcAssoc "*`#*,*NUM*,*NO" PairLstB)
should return... ("ROOMNUM" "385")
(WcAssoc "*`#*,*NUM*,*NO" PairLstC)
should return... ("ROOMNO" "495")
Does this make sense?
Solved! Go to Solution.
Solved by alanjt_. Go to Solution.
Untested...
Case sensitive:
(defun _AssocWCMatch (match lst) (vl-some (function (lambda (item) (if (wcmatch match (car item)) item ) ) ) lst ) )
not case sensitive:
(defun _AssocWCMatch (match lst) (setq match (strcase match)) (vl-some (function (lambda (item) (if (wcmatch match (strcase (car item))) item ) ) ) lst ) )
A small edit got it working as I want.
(wcmatch match (car item))
changed to
(wcmatch (car item) match))
then it worked.
Whoops. That's what happens when you scratch something out quickly.
Glad it works anyway. You're welcome.
Here's both codes, corrected:
(defun _AssocWCMatch (match lst) (vl-some (function (lambda (item) (if (wcmatch (car item) match) item ) ) ) lst ) ) (defun _AssocWCMatch (match lst) (setq match (strcase match)) (vl-some (function (lambda (item) (if (wcmatch (strcase (car item)) match) item ) ) ) lst ) )
Another, recursive variation:
(defun wcassoc ( s l / x ) (if (setq x (car l)) (if (wcmatch (car x) s) x (wcassoc s (cdr l))) ) )
_$ (setq l '(("ROOM#" "195") ("ROOMNAME" "REST ROOM"))) (("ROOM#" "195") ("ROOMNAME" "REST ROOM")) _$ (wcassoc "*`#*,*NUM*,*NO" l) ("ROOM#" "195")