Conditional expressions

Apr 13, 2010
298
7
60
The Hague
1569939448162.png


Am I the only one who finds this an odd design?

I mean, I know the expression is designed to return the exit status of the logical expression, and that 1==1 is very very true, but ...

Am I missing a hidden gem?
 
Last edited:

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,202
72
Albuquerque, NM
prospero.unm.edu
I asked about the odd return from %[[ ]] when it was first added. Rex said that he was thinking in terms of return codes: 0 generally means success, and nonzero is failure.

And indeed the documentation for %[[ ]] mentions "exit status", though I didn't connect that with ERRORLEVELs.
 
Apr 13, 2010
298
7
60
The Hague
Thank you for your reply, Charles.
Rex said that he was thinking in terms of return codes: 0 generally means success, and nonzero is failure.
Yes, he wrote that in the help-file. And I got that.

So?
We will come to love it with the years?

It is very confusing - that's what it is.
I wonder how many users are actually using it.

Okay, I think I feel a suggestion coming up...
 
May 20, 2008
10,573
78
Syracuse, NY, USA
It seems wrong to me.
Code:
v:\> echo %@if[%[[1==1]],1,2]
2

v:\> echo %@if[1==1,1,2]
1
To put it another way, %[[condition]] seems to have the same truth value as (NOT condition).

Where is %[[...]] documented?
Where is it documented that @IF accepts an integer as "condition" (and where is it's evaluation documented)?
 
Apr 13, 2010
298
7
60
The Hague
I have not been able to find it in the usual places of the helpfile. It is mentioned in the "What's new" for version 23.

Perhaps, if this feature has gone unnoticed because it wasn't documented properly, it's not too late to repair this.
 
May 20, 2008
10,573
78
Syracuse, NY, USA
I found it there too. IMHO, if it's going to stay as it is (TRUE -> 0) it should remain poorly documented. But in any case, what's it for? I can't think of a use for it that can't be done more easily otherwise.
 
May 20, 2008
10,573
78
Syracuse, NY, USA
Did you notice that all nonsensical conditional expressions give 0 (are true)?

Code:
v:\> echo %[[foo]] %[[5+3]] %[[c:\windows]] %[[0]] %[[1]]
0 0 0 0 0
 

rconn

Administrator
Staff member
May 14, 2008
11,910
133
This was added at the request of a corporate customer, and is definitely not going to be changed.

Perhaps if you gave me an idea of what you're really trying to do (other than misuse a special-purpose construct) I can suggest the right way to do it.
 
Apr 13, 2010
298
7
60
The Hague
Ehhhh.
I don't need a need.
You told me there was something new. (in the help)
I went ahead and checked it out. (not much documentation)
I tried to envision what the Almighty might have been thinking of when going out of his way to deliver this gem (we did not know about any corporate account).
I was hoping for an elegant way to pre-calculate a boolean value without if / iff and use it multiple times in subsequent tests without having to repeat the boolean expression.
And then the only the @IF appeared to be able to test that boolean, (if's need '%bValue==1' which kinda spoils it),
and then the expected return seemed reversed.
Sure. frustrating. What else?

Are you really going to blame me for misunderstanding?
If so, are you really surprised that I went ahead and experimented without asking ?
 

rconn

Administrator
Staff member
May 14, 2008
11,910
133
If you want me to change existing behavior (and break existing batch files & aliases), then you need an exceptionally compelling argument.

"I saw it in the What's New (from a couple of years ago) and though I don't have a need for it I didn't like the way it was implemented" doesn't rise to the level of compelling.