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
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))
(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".
@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)))
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
@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)))
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
@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.
@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)
)
)