Jump to content

IF - condition (I need an additional LISP lesson)


Bluebird1973

Recommended Posts

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

Link to comment
Share on other sites

(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.

Link to comment
Share on other sites

You could also use ( member ) but it is case sensitive as well

(if (member (strcase (getvar 'loginname)) 
          '("USERNAME" "USERNAME1" "USERNAME2" "USERNAME3"))
   (YadaYada))

 

-David

Link to comment
Share on other sites

Thank you guys !!!

 

GAP CLOSED! :D

 

... and of course ronjonp and David ... case sensitive ... USERNAME not UserName ...

 

kind regards

Bluebird1973

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...