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

One is NIL - One is T

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
362 Views, 10 Replies

One is NIL - One is T

I have one variable that is T and the other is NIL,

how to assign the one that is T to a variable.

sample...

(setq PC_Name (getenv "computername"))
(setq User_Name (getenv "username"))

(setq ChkUserName (dos_dirp (strcat "I:\\" User_Name)))     ; is T
(setq ChkPCName (dos_dirp (strcat "I:\\" PC_name)))           ; is NIL

 

(setq THEONETRUE (......)) ;;; HOW TO ASSIGN THE ONE TRUE

 

Thank you in advance for your help.

 

DC

 

 

 

 

 

 

10 REPLIES 10
Message 2 of 11
rkmcswain
in reply to: Anonymous

So you have two variables, one of which will always be nil and the other will always contain a non-nil value?

 

(setq a nil b "value")
(if a (setq thetrueone a)(setq thetrueone b))

 

R.K. McSwain     | CADpanacea | on twitter
Message 3 of 11
Anonymous
in reply to: rkmcswain

(setq a nil b "value")
(if a (setq thetrueone a)(setq thetrueone b))

 

thanks, but this way only THETRUEONE return "T" it does take the "value".

 

Message 4 of 11
Anonymous
in reply to: Anonymous

my mistake.... you right. thank you.

Message 5 of 11
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

I have one variable that is T and the other is NIL,

how to assign the one that is T to a variable.

sample...

(setq PC_Name (getenv "computername"))
(setq User_Name (getenv "username"))

(setq ChkUserName (dos_dirp (strcat "I:\\" User_Name)))     ; is T
(setq ChkPCName (dos_dirp (strcat "I:\\" PC_name)))           ; is NIL

 

(setq THEONETRUE (......)) ;;; HOW TO ASSIGN THE ONE TRUE

.... 


In that situation, I hope I'm correct in assuming that what you want to set into the THEONETRUE variable is the value in either PC_Name or User_Name [whichever is the True one], and not the result of ChkUserName or ChkPCName.  If so, try:

 

(setq THEONETRUE (cond (ChkUserName User_Name) (ChkPCName PC_Name)))

Kent Cooper, AIA
Message 6 of 11
hgasty1001
in reply to: Anonymous

Hi,

 

I can't made much sense of your request, as if it's for the value of the var THEONETRUE, you will always end up with T as the value, maybe this is what you need:

 

(setq THEONETRUE (if ChkUserName "ChkUserName" "ChkPCName"))

 

Gaston Nunez

 

 

Message 7 of 11
Kent1Cooper
in reply to: rkmcswain


@rkmcswain wrote:

So you have two variables, one of which will always be nil and the other will always contain a non-nil value?

 

(setq a nil b "value")
(if a (setq thetrueone a)(setq thetrueone b))

Or, in that situation [which I don't think is exactly what the OP is trying to do]:

(setq a nil b "value")

(setq thetrueone (cond (a) (b)))

Kent Cooper, AIA
Message 8 of 11
Gary_J_Orr
in reply to: Anonymous

you need to expand R.K.'s response for your situation:

 

given your statments:

 

"

I have one variable that is T and the other is NIL,

how to assign the one that is T to a variable.

sample...

(setq PC_Name (getenv "computername"))

(setq User_Name (getenv "username"))
(setq ChkUserName (dos_dirp (strcat "I:\\" User_Name)))     ; is T

(setq ChkPCName (dos_dirp (strcat "I:\\" PC_name)))           ; is NIL

 

(setq THEONETRUE (......)) ;;; HOW TO ASSIGN THE ONE TRUE"

 

 and R.K.'s response:

 

(if ChkUserName (setq THEONETRUE User_Name) (setq THEONETRUE PC_Name))

 

or you could roll over to a cond stmt to be able to set the first "T" value to the variable and have a failsafe in case neither is true that will set "THEONETRUE" to nil

 

(setq THEONETRUE (cond ((= T ChkUserName) User_Name) ((= T ChkPCName) PC_Name) (T nil) ))

 

 

-Gary

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 9 of 11
Kent1Cooper
in reply to: Gary_J_Orr


@Anonymous wrote:

....

or you could roll over to a cond stmt to be able to set the first "T" value to the variable and have a failsafe in case neither is true that will set "THEONETRUE" to nil

 

(setq THEONETRUE (cond ((= T ChkUserName) User_Name) ((= T ChkPCName) PC_Name) (T nil) ))

....


That's exactly what my first reply does with less code.  There's no need to check whether (= T ChkUserName), when the mere fact that ChkUserName is not nil is enough.  And there's no need to explicitly set it to nil if none of the conditions is True -- that will happen without spelling out a fallback condition, because the (cond) function will return nil if it gets to the last condition and none has been satisfied.

Kent Cooper, AIA
Message 10 of 11
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@Anonymous wrote:

....

(setq PC_Name (getenv "computername"))
(setq User_Name (getenv "username"))

(setq ChkUserName (dos_dirp (strcat "I:\\" User_Name)))     ; is T
(setq ChkPCName (dos_dirp (strcat "I:\\" PC_name)))           ; is NIL

.... 


.... try:

 

(setq THEONETRUE (cond (ChkUserName User_Name) (ChkPCName PC_Name)))


If you don't otherwise have any need for the variables ChkUserName and ChkPCName, but are using them only as intermediaries to find whether there are directories related to those Environment Variables, you can eliminate the middlepeople and do it a little more directly:

 

(setq THEONETRUE

  (cond

    ((dos_dirp (strcat "I:\\" User_Name)) User_Name)

    ((dos_dirp (strcat "I:\\" PC_name)) PC_Name)

  )

)

Kent Cooper, AIA
Message 11 of 11
Gary_J_Orr
in reply to: Kent1Cooper

yeah Kent...it's exactly what you posted (I was writing my response while you posted that one I believe since I had not seen yours yet)...
and true, you don't need the (= T...) but it may help the OP understand how it works.
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)

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

Post to forums  

Autodesk Design & Make Report

”Boost