Bluebird1973 Posted November 13, 2017 Posted November 13, 2017 Hi, could anyone please help me out with this? (if (= "UserName" (strcase (getvar 'loginname))) ... I would like to add here some other UserNames (if (= (or "UserName1" "UserName2" "...") (strcase (getvar 'loginname))) but this didn't work. How could I handle this? kind regards Bluebird1973 Quote
ronjonp Posted November 13, 2017 Posted November 13, 2017 (cond ((wcmatch (strcase (getvar 'loginname)) "USERNAME,USERNAME1,USERNAME2,USERNAME3")) (code) ) Be aware that = and wcmatch are case sensitive, so your example above will never work using strcase on the login name. Quote
David Bethel Posted November 13, 2017 Posted November 13, 2017 You could also use ( member ) but it is case sensitive as well (if (member (strcase (getvar 'loginname)) '("USERNAME" "USERNAME1" "USERNAME2" "USERNAME3")) (YadaYada)) -David Quote
Tharwat Posted November 13, 2017 Posted November 13, 2017 Or ... (if (vl-position (strcase (getvar 'loginname)) '("USERNAME" "USERNAME1" "USERNAME2")) (...) ) Quote
Bluebird1973 Posted November 13, 2017 Author Posted November 13, 2017 Thank you guys !!! GAP CLOSED! ... and of course ronjonp and David ... case sensitive ... USERNAME not UserName ... kind regards Bluebird1973 Quote
Lee Mac Posted November 13, 2017 Posted November 13, 2017 If you really wanted to use OR, per your original example: (setq usr (strcase (getvar 'loginname))) (if (or (= "USER1" usr) (= "USER2" usr) (= "USER3" usr) ) ... ) But I would also likely use member/wcmatch in this scenario. Quote
BIGAL Posted November 14, 2017 Posted November 14, 2017 Had a bit of fun with the guys here so I used a cond as each user got a different response, the wcmatch would just give an answer of match found. Quote
ronjonp Posted November 14, 2017 Posted November 14, 2017 Had a bit of fun with the guys here so I used a cond as each user got a different response, the wcmatch would just give an answer of match found. You could also accomplish that with ASSOC like so: (print (cdr (assoc "USERNAME2" '(("USERNAME1" . "Message1") ("USERNAME2" . "Message2") ("USERNAME3" . "Message3")) ) ) ) Quote
Grrr Posted November 14, 2017 Posted November 14, 2017 Or with a recursive or, which works the same as vl-some: (defun _or ( f L ) (if L (if (not (f (car L))) (_or f (cdr L)) t))) (_or '((x) (= "User2" x)) '("User1" "User2" "User3")) BTW this is one is shorter, but I tried avoiding or: (defun _or ( f L ) (if L (or (f (car L)) (_or f (cdr L))))) Quote
Lee Mac Posted November 14, 2017 Posted November 14, 2017 How about: (defun _or ( f l ) (cond ((not l) nil) ((f (car l))) ((_or f (cdr l)))) ) Quote
Grrr Posted November 14, 2017 Posted November 14, 2017 How about:(defun _or ( f l ) (cond ((not l) nil) ((f (car l))) ((_or f (cdr l)))) ) Looks 'cleaner', Lee! Quote
Tharwat Posted November 14, 2017 Posted November 14, 2017 Another recursive. (defun user-p (u l) (cond ((= u (car l))) (l (user-p u (cdr l)))) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.