mIRC Home    About    Download    Register    News    Help

Topic Options
#135711 - 16/11/05 05:25 AM Just a suggestion.
SladeKraven Offline
Planetary brain

Registered: 19/12/02
Posts: 3547
Loc: Kent, England
From the help file:

Quote:

$v1 & $v2

Returns the first and second parameters of an if-then-else comparison. So, in the case of this comparison:

if (text isin sometext) { ... }

$v1 will return "text" and $v2 will return "sometext".


In an IF statement $v1 is always going to be filled and $v2 doesn't need to be although it can.

If $v1 is filled $v0 returns 1
If both $v1 and $v2 is filled $v0 returns 2

As you can see it checks to see how many parameters of the IF statement was used.

Just a suggestion.

-Andy

Top
#135712 - 16/11/05 01:05 PM Re: Just a suggestion.
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
I see what your saying, becuase $v1 and $v2 are the result of any comparision IF , $IIF and WHILE ( ) , its very dificult to then do anther comparision to see if they exist as that well erase the $v1 and $v2 frown
Still i dont see a use for $v0 greatly, i mean u could go $v [ $+ [ $v0 ] ] or $($+($,v,$0),2) which gets you the first or second value depending on how many were actually returned. But a simple $gettok($v1 $v2,1,32) if there simple words would be enough to also get it. If there more complexe maybe $vx($v1,$v2) using alias vx { return $iif($2 == $null,$1,$2) }, this of course could come up short with a true returned $v2 being $null, and it wouldnt be seen as returned.

After writting the above it suddenly hit me that it might be a case that $v2 is always retured, its just that sometimes its $null
A signle sided IF is like saying ok if Whatever is not $NULL then do it etc etc so $v1 is the Whatever and $v2 is the $NULL
ie if (x123) { } is the same as if (x123 != $null) { }

Top
#135713 - 16/11/05 01:18 PM Re: Just a suggestion.
FiberOPtics Offline
Hoopy frood

Registered: 05/02/04
Posts: 2019
Loc: Leuven, Belgium
I'm curious about what you would be doing with this $v0 identifier? You won't be able to do any if checking with it, as that will override the original $v1/2 identifiers, so basically...

Can you show some examples of what you would use $v0 for? Not something like: echo -a $v0 of course, but something practical.
_________________________
Gone.

Top
#135714 - 16/11/05 04:03 PM Re: Just a suggestion.
SladeKraven Offline
Planetary brain

Registered: 19/12/02
Posts: 3547
Loc: Kent, England
Code:
alias v0 {
  return %v0
}

alias moo {
  if (a == a) {
    var %v1 = $v1, %v2 = $v2
    if (%v1) inc %v0
    if (%v2) inc %v0
    echo -a You used $v0 parameters in your IF statement. 
    echo -a $iif(!%v2,$(%v1,2) = $v0 ,$(%v1, and %v2,2) = $v0)
  }
  unset %v0
}


Well using echo I can see what you both mean with the override because it would check the next IF statement.. frown

The only way I can stop this is storing $v1 and $v2 in a var if they exist which really isn't necessary.. Anyway this is what I came up with but I really can't see any use for it.

I was just thinking if $v1 and $v2 was both filled $v0 would return 2 else would return 1.

-Andy

Top
#135715 - 16/11/05 04:44 PM Re: Just a suggestion.
FiberOPtics Offline
Hoopy frood

Registered: 05/02/04
Posts: 2019
Loc: Leuven, Belgium
I still don't see how that showcases a use for $v0, you just showed a way to try to implement it. What I'm curious about is how you would use it, in a hypothetical situation where $v0 is already implemented and works the way you want it. I just want to see what benefit $v0 brings in an actual example, that would justify for it to be added in future releases. Obviously not the line "echo -a You've used $v0 parameters in your if statement", since you are the one that created it. You already know how many parameters there are. But as DaveC said, $v2 probably exists always, it just returns $null in cases where you only use 1 statement.

if ($3 != $null) echo -a $v0

What should that echo? 1 or 2?

You might say 2, but what should $v0 be when you put:

if ($3) echo -a $v0

In both examples, $v2 is $null, regardless of the fact if you specified 1 or 2 parameters.
_________________________
Gone.

Top
#135716 - 16/11/05 05:11 PM Re: Just a suggestion.
benjy355 Offline
Babel fish

Registered: 27/10/05
Posts: 54
Loc: Canada eh?
as far as i can tell he/she's just trying to get numbers returned only if $v1 or/and $v2 has something... I would suggest
Code:
alias iftrue {
var %i 0
if ($v1 != $null) inc %i
if ($v2 != $null) inc %i
return %i
}
Code:
 on *:Text........ {
say $iif($iftrue == 1, One, Two)
}

I don't know what you would use it for so thats just a usless example ^_^
_________________________
Chat NSN
My Server: sleepystickman.ircxpro.com

Top
#135717 - 16/11/05 05:23 PM Re: Just a suggestion.
FiberOPtics Offline
Hoopy frood

Registered: 05/02/04
Posts: 2019
Loc: Leuven, Belgium
Quote:
I don't know what you would use it for so thats just a usless example ^_^

That's why I'm asking for a useful example. I'm not saying it's a bad suggestion yet, I'm simply curious to what he had in mind originally that made him suggest this feature.

Btw, when you use an if statement, the $v1 and $v2 values are altered, so your iftrue alias makes no sense, since you're already corrupting the original $v1 and $v2. The %i that you are returning, doesn't correspond to the number of parameters used in your last if statement, since that last if statement is in your iftrue alias.

alias lol if (lol) return lol

//if (5 == 5) echo -a $lol $v1

Do you understand why that echos "lol lol"?
_________________________
Gone.

Top
#135718 - 16/11/05 07:13 PM Re: Just a suggestion.
benjy355 Offline
Babel fish

Registered: 27/10/05
Posts: 54
Loc: Canada eh?
awww
confuzing
poop
lol i think i know this one..... uhhhh
Code:
alias ifyes {
var %i 0
if ($1) inc %i
if ($2) inc %i
return %i
}

_____

on lebjbkblhlasdg {
if (omg isin $1-) {
$iif($ifyes($v1,$v2) == 2, say .......)
}

so on and so forth
_________________________
Chat NSN
My Server: sleepystickman.ircxpro.com

Top
#135719 - 16/11/05 07:21 PM Re: Just a suggestion.
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
If that if condition in the event is true then both $v1 and $v2 must be present.

I can't think of any situation where a peice of code would need to know whether a previous condition had used one or two operands besides situations where the scripter could hard-code it at the time.
_________________________
Spelling mistakes, grammatical errors, and stupid comments are intentional.

Top
#135720 - 16/11/05 07:26 PM Re: Just a suggestion.
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
An if (something) ... condition isn't the same as comparing with $null, it's a boolean check since it'll also fail if something is 0.

I don't think that makes the suggestion any more necessary, just pointing out that they're not the same thing.
_________________________
Spelling mistakes, grammatical errors, and stupid comments are intentional.

Top
#135721 - 16/11/05 07:59 PM Re: Just a suggestion.
FiberOPtics Offline
Hoopy frood

Registered: 05/02/04
Posts: 2019
Loc: Leuven, Belgium
I know that if (something) will be false if somethign is either: 0, $null, or $false.

That wasn't my point with the example that I used:

The "if ($3)" was simply an example of an if condition with 1 expression, and "if ($3 != $null)" an example of an if condition with two parameters, they weren't meant to be related in any way other than the fact that in both cases $v2 is $null.

I'll use another example so people aren't confused with what I'm saying:

if (5 != $null) echo -a $v0

if (10) echo -a $v0

The first example is supposed to be returning 2 according to the original requester's suggestion, however my point was that in both if conditions, $v2 is $null aka empty. In other words, knowing it has two operands doesn't really help with anything, as it could still be $null, which is the same situation where $v0 returns 1.
_________________________
Gone.

Top
#135722 - 16/11/05 09:35 PM Re: Just a suggestion.
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
tacking on to the bottom of the thread here, rather than repling.

I think I was wrong $v2 always being returned as $null since starbucks_mafia is right $if (0 != $null) is a true condition, so i guess it does return either $v1 or $v1 and $v2.

However I have thought up a situation where $v0 could be used (although im sure it could be worked around another way)

%all.options.on is 0 for false and 16 for true (16 being the total number of options)

The hashtable holds an items for each nick as follows
[email]-@nick[/email] : holds nick specific data (always exists)
[email]a@nick[/email] : holds option 'a' specific data for nick (exists only if he has option a)
[email]b@nick[/email] : holds option 'b' specific data for nick (exists only if he has option b)
etc etc to p

Code:
if (%all.options.on || ($hfind(hashtable,$+(*@,$nick),0,n) > 1)) { 
  if ($v0 == 1) {
    var %active.options = a b c d e f g h i j k l m n o p
  }
  else {
    var %active.options, %i = 1
    while ($hfind(hashtable,$+(*@,$nick),%i,n)) { var %active.options = %active.options $left($v1,1) | inc %i }
    var %active.options = $remtok(%active.options,-,1,32)
  }


if %all.options.on is 0 the OR is tripped and the total nmber of *@nick items is detected, this could be a number from 1 to 17, if tis 1 then no theres no optiosn for nick

if $v0 is 1 then the %all.options.on was not 0 but the value of $v1 does not represent the number of items in the hashtable, and the option string needs to be "a b c d e f g h i j k l m n o p"
if $v0 is 2 then the items in the hash table need to be pulled into the options string


OK OK you could write it with out it, but hey theres a possable use smile

Top
#135723 - 17/11/05 09:15 AM Re: Just a suggestion.
Mardeg Offline
Babel fish

Registered: 30/10/04
Posts: 73
Code:
alias v0 return $numtok($+($v1,$lf,$v2),10)

Not a real workaround, but just thinking (coding?) out loud...
Code:
if (%all.options.on || ($hfind(hashtable,$+(*@,$nick),0,n) > 1)) {
  goto $v0
  :0
  echo -a Something went horribly wrong and the comparison didn't even happen
  return
  :1
  var %active.options = a b c d e f g h i j k l m n o p
  return
  :2
  var %active.options, %i = 1
  while ($hfind(hashtable,$+(*@,$nick),%i,n)) { var %active.options = %active.options $left($v1,1) | inc %i }
  var %active.options = $remtok(%active.options,-,1,32)
}
 
_________________________
CSS email obfuscator

Top
#135724 - 17/11/05 11:01 AM Re: Just a suggestion.
Kelder Offline
Hoopy frood

Registered: 12/04/03
Posts: 701
Loc: Leuven, Belgium
What's wrong with just this code? I even left the unneeded orange code in to show where it should be, but the next while loop will give correct output even when this condition is false.
So, I don't really think rewriting decent code into worse code just to be able to use an unexistent identifier is a good reason to ask for that identifier smile

Code:
if (%all.options.on) var %active.options = a b c d e f g h i j k l m n o p
else[color:orange]if ($hfind(hashtable,$+(*@,$nick),0,n) > 1)[/color] {
  var %active.options, %i = 1
  while ($hfind(hashtable,$+(*@,$nick),%i,n)) { var %active.options = %active.options $left($v1,1) |   inc %i }
  var %active.options = $remtok(%active.options,-,1,32)
}


As for the rest of the thread:
var %a,%b | if (%a == %b) echo so $v0 is supposed to be 0?
var %a = 0 ,%b = 0 | if (%a == %b) echo so $v0 is supposed to be 2?
var %a | if (%a == 5) { } | else echo and $v0 is what now? 2? 1?

IMO there's only a *very* limited class of situations where you don't know if a test contains a 2 sided operand or not, and that's where you change the evaluation order to have a %var/$n/$identifier produce the test. In all other cases, you should know what you scripted, because, well, you just scripted it!

Top
#135725 - 18/11/05 12:12 AM Re: Just a suggestion.
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
Quote:
alias v0 return $numtok($+($v1,$lf,$v2),10)


^ I dont like this becuase $v1 or $v2 maybe $null or $lf (not in my example code) and would cause $v0 to return the wrong result.

However your example code for its use was a nicely layed out approch to a $v0 usage.

Top
#135726 - 18/11/05 01:24 AM Re: Just a suggestion.
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
Quote:
What's wrong with just this code?


Everything is if you bothered to read what i wrote. "(although im sure it could be worked around another way)" and "OK OK you could write it with out it, but hey theres a possable use"
The code i displayed is complety fictional I mad it up on the spot to display a usage of the theroretical $v0, The intent was to rather than just have $v0 being used to see how many sides tot he condition there were, it could also be used to define what PART of the whole IF was validated and made the IF true, as im sure you know if the %all.options.on is evaluated as true the following OR ($hfind(hashtable,$+(*@,$nick),0,n) > 1) is never preformed. While in this case that means nothing, it can be relevent if one or more of the sides of the OR condition was a custom identifier and left things in a different status.


Quote:
I even left the unneeded orange code in to show where it should be, but the next while loop will give correct output even when this condition is false.


Indeed its not needed where you put it, but then again your code fails to take into account that I NEVER closed the initial IF
Your code results in ONE code path remaining after its completion, mine has TWO, the two i speak of are...
(1) IF [ %all.options.on set OR $hfind(hashtable,$+(*@,$nick),0,n) > 1] was true I now have a correct %active.options, for later code of the inital {
(2) IF [ %all.options.on set OR $hfind(hashtable,$+(*@,$nick),0,n) > 1] was false no code inside the initial { well be performed

There is no easy way for your code to come together while excluding if nethier condition was true.

Quote:
So, I don't really think rewriting decent code into worse code just to be able to use an unexistent identifier is a good reason to ask for that identifier smile


I wrote that code from scratch to illustrate a possable use of a $v0, the code doesnt exist anywhere beyond here (it couldnt since $v0 doesnt exist)

Quote:
As for the rest of the thread:
var %a,%b | if (%a == %b) echo so $v0 is supposed to be 0?
var %a = 0 ,%b = 0 | if (%a == %b) echo so $v0 is supposed to be 2?
var %a | if (%a == 5) { } | else echo and $v0 is what now? 2? 1?


2, 2 & 2, The understanding as i saw it of what was the suggestion was that $v0 returns with the number of sides of the condition, not the status of if they were zero/$null/$false etc or not

ex: //if ($null == 1) { }
$v1 = nothing & $v2 = "1"
$v0 would need to return 2, even tho $v1 had no value

Quote:
IMO there's only a *very* limited class of situations where you don't know if a test contains a 2 sided operand or not, and that's where you change the evaluation order to have a %var/$n/$identifier produce the test. In all other cases, you should know what you scripted, because, well, you just scripted it!


Sometimes the conditions your testing in the IF themselfs alter the state of later conditions in the same IF, while I aggree with you I dont see a significant use of the value, i can see potential uses of it, in complexer IF and WHILE statments.

Top
#135727 - 18/11/05 12:34 PM Re: Just a suggestion.
Kelder Offline
Hoopy frood

Registered: 12/04/03
Posts: 701
Loc: Leuven, Belgium
Quote:
Everything is if you bothered to read what i wrote. "(although im sure it could be worked around another way)" and "OK OK you could write it with out it, but hey theres a possable use"
The code i displayed is complety fictional I mad it up on the spot to display a usage of the theroretical $v0,


Don't worry, I read it all. I just chose to do it anyway to comment on the suggestion. I'm still not fond of inventing very strange situations to force a new feature through. Yes you wrote it from scratch, but writing other code from scratch wouldn't have taken that much more time

Yes you are right that I didn't 'forget' the } you did, but it's really besides the point. I'll make a smaller change:
if ($v0 == 1) {
change to
if (!$v2) {
or
if (%all.options.on) {

Both do exactly what you want in this case, even in most other imaginary cases.


Maybe we need something more structural, like $lt that returns the sequence number of the last test executed, fex "if (%a || %b || %c || $true || %d) echo last one tested is test $lt", instead of changing operands to see what test fired.

Top
#135728 - 18/11/05 11:32 PM Re: Just a suggestion.
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
Quote:
Yes you are right that I didn't 'forget' the } you did


You dont read that carefully, I didnt "forget" as you say, I left it off on purpose, as i have already said the code paths of the initial IF were not ment to remerge following the shown code, only the 2 code paths of the different %active.options var cration were ment to. You cant just ignore that by saying I forgot the }.


Regardless I think your Idea of a $lt is a great idea better than $v0, would allow very complex ifs that could then split off based on $lt 's outcome.

Top
#135729 - 18/11/05 11:57 PM Re: Just a suggestion.
Mardeg Offline
Babel fish

Registered: 30/10/04
Posts: 73
Quote:
Quote:
alias v0 return $numtok($+($v1,$lf,$v2),10)

^ I dont like this becuase $v1 or $v2 maybe $null or $lf (not in my example code) and would cause $v0 to return the wrong result.

Indeed it could. $lf was just the first thing that came to mind. I doubt that any token separator would be flawless, and perhaps that could be the only reason for having a built-in $v0 identifier smile

I thought of using goto for a way around causing an if test of $v0 to trigger new $v1 and $v2, but I doubt "goto" makes a good case for getting a new built-in identifier added.
_________________________
CSS email obfuscator

Top