mIRC Home    About    Download    Register    News    Help

Print Thread
#60031 12/11/03 07:29 PM
Joined: Oct 2003
Posts: 313
S
Sais Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
I would expect:

//var %a = $true | if (!(%a)) { echo -a true } | else { echo -a false }
//var %a = $false | if (!(%a)) { echo -a true } | else { echo -a false }

to give the same results as:

//var %a = $true | if (!%a) { echo -a true } | else { echo -a false }
//var %a = $false | if (!%a) { echo -a true } | else { echo -a false }

However the former gives:

true
true

while the latter gives

false
true

What I was expecting to be able to do was to use !(%a && %b). I could just use (!%a || !%b), but I think the former is clearer, and should be possible.


Sais
#60032 12/11/03 09:39 PM
Joined: Sep 2003
Posts: 70
M
Babel fish
Offline
Babel fish
M
Joined: Sep 2003
Posts: 70
This is not a bug. Based entirely upon what you said, ! is somethign that alters a condition, not a "boolean operator" (like && and ||, though these things don't exactly have names).

mIRC's behaviour can be accounted for easily this way: mIRC sees a condition of %something or $something as a condition in the sense of isop or isnum. So the ! will invert it. It sees an odd little expression that doesn't really mean anything like (%a) as an odd little expression that doesn't really mean anything and can be left alone. mIRC handles these things by making them always true. Because (%a) is not a condition in the sense of isop or isnum, the ! doesn't mean anything either. So the ! is part of the odd little expression that doesn't really mean anything and is always true.

Anyway, fixing your so-called "bug" would not improve the functionality of mIRC at all since you can invert all meaningful conditions.

Last edited by madewokherd; 12/11/03 09:39 PM.
#60033 12/11/03 10:21 PM
Joined: Oct 2003
Posts: 313
S
Sais Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
I don't consider (%a) to be meaningless. If I were to write

if ((%a) ) { echo -a true }

that would be meaningful - it would have the same meaning as if I had only had the one set of parens.

So why is !(%a) not meaningful? (%a) ought to evaluate to the same thing as %a does. In the case of (%a || %b) it would be necessary to include the parentheses.

In my opinion, !(%a && %b) is more readable (and hence better coding) when you want to negate the 'and', and is semantically different to (!%a || !%b), even if it gives the same results. _Clarity_ in code is as useful as correct code.


Sais
#60034 13/11/03 12:51 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
This would be a feature suggestion (although, afair, it has been suggested in the past, you can try Search to make sure) because it seems that the ! prefix was designed this way. Help file:

You can use the ! prefix in front of variables and identifiers in an if-then-else statement to negate a value. The following statements are equivalent.

It doesn't say anything about using this prefix with expressions inside brackets, it's only meant to work with identifiers/variables.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#60035 13/11/03 01:21 AM
Joined: Sep 2003
Posts: 70
M
Babel fish
Offline
Babel fish
M
Joined: Sep 2003
Posts: 70
I still think it's perfectly reasonable that mIRC acts this way, but I'll be more careful to look from the help and test things this time.

There are three things that you need to keep straight here: comparisons, boolean operators for expressions, and logical operators. The second sort are never given a name in the help; I only call them logical operators so I can talk about them as distinct from the previous sort, which ARE referred to in the help.

Comparisons are the following:
Code:
%a == %b
%a !== %b
$nick isop $chan
$0
%a
!%a

Comparisons are not the following:
Code:
(%a == %b)
(%a)
!(%a)

Comparisons are only the v1, v2, etc and the boolean operator for expressions. Boolean operator for expressions are the following:
Code:
== in %a == %b
!== in %a !== %b
isop in $nick isop $chan
$0 in $0
%a in %a
!%a in !%a

If you really wanted to, you could consider the $ or % or !% on its own to be the boolean operator--functionally, it doesn't matter. You can invert a boolean operator for expressions by adding a ! to the beginning of it (unless it already has one). This only works for the operators for expressions. You cannot invert (%a) because (%a) isn't an operator in this sense. Only %a with no parenthesis is.

Your logical operators include only parenthesis (), &&, and ||. These can only be used on comparisons. ! is not a logical operator, nor is it described as one. The help only says,
Code:
To negate an operator you can prefix it with an ! exclamation mark.

and the help does not refer to &&, ||, or the parenthesis as operators at all.

I'm not sure I understand your theory entirely, but if I do, it would mean that (($me) isop ($chan)) is the same as ($me isop $chan), which it is not. There is nothing saying you can put parenthesis around any part of the conditional part of an if statement and let it have the same meaning.

I would consider !(%a && %b) less readable than (!%a) || (!%b). Putting the first into words, it says "the inverse of true if and only if both of a and b are true," while the second one is "true if and only if either a or b is false". For anyone who understands simple boolean logic very well, as someone who uses these terms often should, these statements are the same, and the second statement is simpler.

Last edited by madewokherd; 13/11/03 01:24 AM.

Link Copied to Clipboard