Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Combine Assoc and Wcmatch

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
mdhutchinson
555 Views, 4 Replies

Combine Assoc and Wcmatch

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?

 

 

 

4 REPLIES 4
Message 2 of 5
alanjt_
in reply to: mdhutchinson

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
  )
)

 

Message 3 of 5
mdhutchinson
in reply to: alanjt_

A small edit got it working as I want.

 

(wcmatch match (car item))

 

changed to

 

(wcmatch (car item) match))

 

then it worked.

Message 4 of 5
alanjt_
in reply to: mdhutchinson

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
  )
)

 

Message 5 of 5
Lee_Mac
in reply to: alanjt_

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")

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost