|
Joined: Aug 2007
Posts: 334
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Aug 2007
Posts: 334 |
these are 2 simple little things that i think would be handy to have... idk how easy it is to implement it but i want it...
in if then else statements i want : ifodd: if X is an odd number ifeven: if X is an even number
This is not the signature you are looking for
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
You can already use the "is multiple of" operator ( //) directly in a condition, or you can use the modulus operator ( %) from inside $calc(). eg. if (2 // X) {
; X is even
} or if ($calc(X % 2)) {
; X is odd
}
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
Yet another way: if (X & 1) {
; X is odd
} & is the bitwise AND operator (not to be confused with &&)
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Jan 2003
Posts: 1,063
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 1,063 |
and another possible way:
if ($calc(X % 2) == 0) {
; is even
}
If it ain't broken, don't fix it!
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
And another: if ($right(X,1) isin 13579) {
; X is odd.
}
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 759 |
and another:
if ($and(X,1)) {
; X is odd.
}
$maybe
|
|
|
|
Joined: Oct 2003
Posts: 3,918
Hoopy frood
|
Hoopy frood
Joined: Oct 2003
Posts: 3,918 |
oh oh oh!
if ($calc(X / 2) == $int($calc(X / 2))) {
; X is even
}
or
if (. isin $calc(X / 2)) {
; X is odd
}
- argv[0] on EFnet #mIRC - "Life is a pointer to an integer without a cast"
|
|
|
|
Joined: Jun 2003
Posts: 5,024
Hoopy frood
|
Hoopy frood
Joined: Jun 2003
Posts: 5,024 |
Mentality/Chris
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Lol. So many ways, yet I think it would be helpful to have isodd or iseven built in anyhow. Usually, if something can be easily scripted, I wouldn't support adding it into mIRC itself. But checking for odd and/or even numbers shouldn't require knowing how to do the methods shown. Those are easy for someone who knows how, but those methods aren't obvious to new scripters, nor are they shown at all in the help file. Obviously, people can ask and be shown the way and maybe rememeber it for later. Still, having isodd/iseven makes sense to me.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Dec 2002
Posts: 503
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 503 |
I think having even more trivial /if conditions is superfluous.
As has been illustrated already in this thread, there are plenty of ways to do this already.
|
|
|
|
Joined: Oct 2003
Posts: 3,918
Hoopy frood
|
Hoopy frood
Joined: Oct 2003
Posts: 3,918 |
The point is that it's not "scripted". the original suggestion, the "is multiple of" (//) operator was implemented in to test iseven/isodd, and its as basic as it gets.
You can blame qwerty for everyone else posting their zany methods. I'm with Bekar, though, and believe there's no reason to add in an operator that's purpose is already superceded by another more general operator.
- argv[0] on EFnet #mIRC - "Life is a pointer to an integer without a cast"
|
|
|
|
Joined: Aug 2007
Posts: 334
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Aug 2007
Posts: 334 |
well thx for the suggestions/examples i guess
This is not the signature you are looking for
|
|
|
|
Joined: Jan 2004
Posts: 509
Fjord artisan
|
Fjord artisan
Joined: Jan 2004
Posts: 509 |
I would vote on which 1 is faster.
I generally think using a custom identifier is slower.
Suppose I made a custom identifier $calculate() based exactly on $calc().
If I used something like.
alias calculate { return $calc($1-) }
I guess the question is is making a non-custom identifier any negligibly faster than using a custom identifier.
For the $iseven or $isodd case, probably not.
And since there's so many ways to check for $iseven or $isodd, I would say a default identifier would have to be slower than using a simple custom identifier (especially if Khaled combined all the above examples in his C++ source for such an identifier).
So probably meaningless.
-Neal.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
A built in method (it's not an identifier, btw) would be faster than any custom identifier. Obviously, the difference in speed would be negligible, but it would definitely not be slower. The main benefit is that it's an obvious way of obtaining whether or not something is even or odd. Yes, the most common (I think) method right now is to use % to see... basically checking if the number can be evenly divided by 2. That's pretty easy to do and anyone with either a math background or who has scripted enough to know about it can do it. I still say having "isodd" or "iseven" would be good. Apparently, I'm outvoted on this, but it's up to Khaled in the end, so I'll still stand in favor of it and let him decide. And, for those stating that it can be done using other methods that are easy, so shouldn't be added... why then do we bother having isop, etc?
if ($nick isop $chan) {}
if ($nick($chan,$nick,o)) {}
That's four characters difference and results would do the same thing. Obviously, isop is better, but the point is that there is an alternate method that doesn't even increase the amount of script by very much. With the iseven/isodd check, the difference in script size is a lot more. So considering adding it would make finding odd/even more intuitive and shouldn't be difficult to add, I don't think the reasoning that it's possible in other ways is really that valid. Again, that's just my opinion and I seem to be in the minority. ![smile smile](/images/graemlins/mirc/smile.gif)
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
$nick() was added after isop, so it's not really an appropriate comparison. As for size: if (X & 1) ...
if (X isodd) ... So it's actually longer than the most efficient and one of the most intuitive ways of doing the check. Not that it really matters, but just figured I'd point it out since you mentioned code length.
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Oct 2003
Posts: 3,918
Hoopy frood
|
Hoopy frood
Joined: Oct 2003
Posts: 3,918 |
There is no custom identifier involved in the //, \\ or & operators, so none of that is relevant.
- argv[0] on EFnet #mIRC - "Life is a pointer to an integer without a cast"
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Before/after.... If $nick was first, would it be bad to add isop? Of course not, so the point still stands. Ok, ignore the length. I wasn't really trying to compare length by saying smaller is better. I was just pointing out differences in size in case someone did bring it up... basically saying that the isop example is close and we still have it. And, I was obviously mistaken in the size of the examples... I was going by memory (stupid idea for me) and because they were shown as 3 lines because of the brackets and what you want done if $true, I "remembered" it being larger than it was. I should have looked before talking about the length. Again, though... the length was just to curb any talk about length. I should have just left that out, I suppose. ![shocked shocked](/images/graemlins/mirc/shocked.gif) I still disagree about your examle being one of the "most intuitive" methods. I mean, from a person with little math background and little scripting/programming background, why in the world would they think that & (1 not 2) would give them whether or not something is even/odd? If it's intuitive, it would be obvious without having to figure it out or have it pointed out. & or % isn't intuitive at all without those backgrounds. "isodd" or "iseven" would be intuitive for just about anyone. I mean, you could walk up to a kid who knows evens and odds and ask, "If 10 iseven say Yes". The child would understand. That's intuitive. On the other hand, if you ask most people, "If 10 MOD 2 say Yes", they'd look at you like you had two heads. So, ignore what I metioned of length and just take in the rest.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
I was responding to LostShadow's comments about custom identifiers, where he said they'd be faster than a built in method. And, for anyone who wanted to, they could make a custom $isodd/$iseven identifier using a method of obtaining that. The point I was making is that a built in method would not be slower than the custom identifier method. LostShadows said it would be. It really had nothing to do with whether or not to add it. Just correcting what he said.
In any case, as I said, I know I'm in the minority for thinking adding it would be good. I understand that and accept it. Just pointing out my thoughts on it.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 759 |
You have a valid point for wanting the shortcut but not for needing it (I know you dont need it BTW). What I'm trying to say is shortcuts however handy they may sound at first it also promotes bad thinking. If you cant figure a way to check if a number is odd or even, even the most crappy if (. isin $1) method, then isodd/iseven wont help them any further because after that they'll be stuck on the next "mystery". Most of the current shortcuts actually shortcut something used on a regular basis that would feel repetitive having to repeat all the time. if (N & 1) or if (2 \\ N) is hardly repetitive.
$maybe
|
|
|
|
Joined: Jan 2004
Posts: 509
Fjord artisan
|
Fjord artisan
Joined: Jan 2004
Posts: 509 |
I do agree that custom identifiers are slower, hence my alias calculate { example for $calculate() being a clone of $calc(). But, if we combine these sources for the built-in identifier, $isodd().
alias isodd {
if ($calc(X % 2)) {
; X is odd
}
if (X & 1) {
; X is odd
}
if ($right(X,1) isin 13579) {
; X is odd.
}
if ($and(X,1)) {
; X is odd.
}
if (. isin $calc(X / 2)) {
; X is odd
}
}
Then, I would have to say, the built-in identifier is slower. The problem is I pasted the above in mIRC scripting, when in fact, Khaled codes identifiers in C++ or something. Therefore, if you used only 1 of the above code, for your custom--identifier, then it would be faster. But before that, it just simply depends on the code source. It's possible that a build-in identifier could be so complex (from checking all the possibilities) that simply using a custom identifier is faster. And I guess a built-in $isodd identifier, would not be as combined. You could code a non-built $isodd extremely complex, whereas a very simple custom-identifier could be faster. But of course, none of us could know that unless we see Khaled's built source.
|
|
|
|
|