mIRC Home    About    Download    Register    News    Help

Print Thread
/var with no equals sign #177387 24/05/07 11:21 AM
Joined: Dec 2002
Posts: 580
N
NaquadaServ Offline OP
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
Ok, nobody shoot me for saying this is a bug, please...

We were off topic here, so I moved this to the proper forum...
Originally Posted By: Collective
Not really a bug when you use invalid syntax smile


Also, the reasons for [ ] and $eval working are different. The [ ] brackets evaluate %b early whereas $eval just serves as 'padding' (for want of a better word). Something like $abs(%b) or $null %b would have the same effect (seperating the %var from the comma is the issue, IIRC).

If it's invalid syntax, it should present me with such an error, since it doesn't I can only suspect that originally mIRC supported this and that only after adding support for multiple variables in a single /var (reason the comma followed by a variable is an issue), did this become a "bug". wink

I don't think something should work, but only work some of the time, to me that's a bug. As a fix, it would be nice if multiple variable support was disabled when no equal sign preceeds /var %var.

I wouldn't complain about this if /set and /var had the same syntax. I personally like it better without an equal sign, and could care less about multiple variables in a single /var (I'd probably feel differently if there were variable types).

Code:
var %x = 1, %y = 2
; Oh no! One character longer, what ever will I do now :)
var %x 1 | var %y 2


NaquadaBomb
www.mirc-dll.com
Re: /var with no equals sign [Re: NaquadaServ] #177389 24/05/07 12:18 PM
Joined: Dec 2002
Posts: 2,021
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,021
Originally Posted By: NaquadaServ
I don't think something should work, but only work some of the time, to me that's a bug. As a fix, it would be nice if multiple variable support was disabled when no equal sign preceeds /var %var.

I wouldn't complain about this if /set and /var had the same syntax. I personally like it better without an equal sign, and could care less about multiple variables in a single /var (I'd probably feel differently if there were variable types).


As demonstrated by qwerty in that thread, you don't need to be
setting multiple variables for the command to break when not
using =. Maybe it should just show error, but I ask, why not
just use the proper syntax? It seems to work perfectly when
used properly, go figure.


Originally Posted By: qwerty
//var %a $str(a,%b)

Re: /var with no equals sign [Re: NaquadaServ] #177391 24/05/07 12:26 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
Yes, i agree with this, /var and /set should works with the same syntax and as for the equal sign, Om3m explain when you need to have one or not here :
http://forums.mirc.com/ubbthreads.php?ubb=showflat&Number=176028&page=2#Post176028


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: /var with no equals sign [Re: Wims] #177394 24/05/07 01:10 PM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
/set can't set more than 1 variable at a time, from v4.0:
Quote:
40.Added variable support:
/set [-q] <%var> [value]
/unset [-q] <%var> [%var2] ... [%varN]
/unsetall
/inc [-q] <%var> [value]
/dec [-q] <%var> [value]
Can be edited in Variables section in remote dialog.

When support was added to leave off the '/set' in v4.5:
Quote:
55.You can now use an = (equal sign) to assign values to
variables.

%x = 5 + 1
%x = 5 - %y
%x = %x * 2
%x = %z / $2
%x = %x % 3

Can only perform a single operation in an assignment
at this time. You can also still do /set %x 5 + 1.

The context of using the '=' to assign a value to the variable was introduced.

But this still only allowed for one variable to be assigned at a time.

/var has always been able to set multiple variables at a time, from it's introduction in v5.6:

Quote:
99.Added support for local variables by using the /var command:

var %x = 1, %y, %z = $me

Local variables can only be used in the alias in which they
were created and are destroyed when the alias terminates.

There have been subsequent fixes:

v5.61:
Quote:
67.Fixed /var bug which may have caused a gpf if /var was used
incorrectly.

v5.71:
Quote:
62.Improved /var, now handles identifiers containing commas better
though note that you should use the equal sign in the definition,
eg. /var %x = etc.

And one addition in v5.80:
Quote:
94.Added /var -s switch to show local variable being set.

But as is shown above, the documentation has always stated the requirement of the '=' when assigning a value.

The fix in v5.71 even re-iterates the requirement for the '=', and the context of the bug highlights the possibility of parsing issues with values containing comma's.

The ability to assign a value without an '=' in the '/var' command has always been a happy-accident.

Re: /var with no equals sign [Re: Bekar] #177395 24/05/07 01:49 PM
Joined: Dec 2002
Posts: 580
N
NaquadaServ Offline OP
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
Originally Posted By: Bekar
The ability to assign a value without an '=' in the '/var' command has always been a happy-accident.


Would it kill anyone's scripts if it also worked (100% of the time) without the equals? I'm not the only person who does this, I see /var with no equals all the time in scripts written by other people, and why not, it usually works. smile

BTW, thanks for the revision history, I was curious. smile


NaquadaBomb
www.mirc-dll.com
Re: /var with no equals sign [Re: NaquadaServ] #177396 24/05/07 01:53 PM
Joined: Dec 2002
Posts: 2,021
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,021
Well they're wrong too lol. I don't see a problem with using it without the = if it works but noone should complain about it when they're not using the proper syntax and it doesn't work. Also, it already works 100% of the time, when used properly. I'm sure there is a perfectly good reason for requiring it.

Re: /var with no equals sign [Re: NaquadaServ] #177401 24/05/07 02:46 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Just because you see a lot of people using incorrect syntax doesn't make it a good thing. If you don't like having problems, then always use proper syntax and you'll have no problems at all.


Invision Support
#Invision on irc.irchighway.net
Re: /var with no equals sign [Re: Riamus2] #177406 24/05/07 03:02 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
Yes but if the syntax of /var and /set were the same, it will avoid some confusion.my point of view is that /var should not exist if /set can set more than one %var at the same time, like /var can :

/set -l %var value ,%var1 value1

i think too that if mirc can /Var %var = "date would require = sign" ,he could /var %var "date would require = sign" , no ?


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: /var with no equals sign [Re: Wims] #177408 24/05/07 03:09 PM
Joined: Dec 2002
Posts: 2,021
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,021
Originally Posted By: Wims
Yes but if the syntax of /var and /set were the same, it will avoid some confusion.


Thinking back, I can't recall having any confusion about this whatsoever and I'm thinking that most don't have any confusion either. Just put the stupid = in there. What's the big deal?

~ Edit ~

Also, if you think about it, /var %var is more like describing the temporary (soft?) meaning of %var to the currently executing script, where /set %var is permanently (hard?) setting %var with the provided data. So using the equal sign with /var makes perfect sense really.

Re: /var with no equals sign [Re: RoCk] #177411 24/05/07 03:17 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
i don't have problem with = because i put it when i need to put it. But i think it will be usefull to have /set can set mote than one variable smile


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: /var with no equals sign [Re: Wims] #177412 24/05/07 03:19 PM
Joined: Dec 2002
Posts: 2,021
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,021
True, I've always thought it would be nice to have that ability.

Re: /var with no equals sign [Re: Wims] #177417 24/05/07 03:39 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Using a single command to set multiple variables is pretty ugly though and hurts readability. Not to mention that the increased complexity of parsing slows the command down. With something as fundamental as setting a variable speed is vital.

The reason /var has this ability but /set doesn't IMO is that /var's primary reason for existing is as a declarative function to create local variables and optionally give them an initial value. To actually change the value of variables within a script it makes sense to use /set or the %var = value syntax because it is typically far more readable to set each variable a line at a time, and most importantly it is also much faster.

For instance, it's not at all unlikely that someone might wish to set a single value to something like "hello, %place". Without the = this will create two variables whereas the scripter only intended to create one with %place being evaluated. Of course it's possible that ", %blah =" could appear in a string too, but a lot less likely. The equals sign also ties in very nicely with the %var = value syntax which is more intuitive than the older /set method.

Oh and in case you're wondering about the speed hit suffered by /var's more complex parsing. Here's my benchmark code:
Code:
alias varbench {
  var %i = $iif($int($1), $v1, 50000), %j = 0, %start = $ticks
  while %i {
    var %i = %i - 1, %j = %j + 1
  }
  echo -a %j iterations using /var took $calc($ticks - %start) ms
}

alias eqbench {
  var %i = $iif($int($1), $v1, 50000), %j = 0, %start = $ticks
  while %i {
    %i = %i - 1
    %j = %j + 1
  }
  echo -a %j iterations using % $+ var = value syntax took $calc($ticks - %start) ms
}

alias setbench {
  var %i = $iif($int($1), $v1, 50000), %j = 0, %start = $ticks
  while %i {
    set %i %i - 1
    set %j %j + 1
  }
  echo -a %j iterations using /set took $calc($ticks - %start) ms
}


From that code I found that:
%var = value syntax is approximately 27% faster than /var
/set is approximately 25% faster than /var

Last edited by starbucks_mafia; 24/05/07 03:55 PM.

Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: /var with no equals sign [Re: Wims] #177418 24/05/07 03:40 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
I'd prefer /set to be left alone. It's exactly its simplicity that makes it more reliable than /var. Even if /set was made to accept multiple variables more reliably than /var, I'd still prefer this 'fix' to be applied to /var instead. Why not to both? Because I find it quite handy that *whatever* you enter after the variable name in /set is guaranteed to be evaluated as in any other command (even if you enter math expressions, provided you use the -n switch, which btw /var lacks). Making /set accept multiple vars would mean you could no longer do things like
/set %a blah, %b
and have %a set to "blah, <value of %b>". This may not sound like a big deal, but I've needed this sort of functionality more often than I've needed to set multiple global variables. Others may have different needs of course.

Last edited by qwerty; 24/05/07 03:56 PM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: /var with no equals sign [Re: starbucks_mafia] #177420 24/05/07 04:05 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Another (perhaps bigger) contributor to /var's slowness is that it's a sort of internal alias for /set -l (you can see that if you alias /set itself; /var calls that alias). mirc does that on few occasions, eg this is the reason why $iif() is notoriously slow, compared to /if - /else.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: /var with no equals sign [Re: qwerty] #177427 24/05/07 05:50 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
It may be partly responsible but I'd have expected %var = value to suffer aswell if the command-rerouting were a major factor. Especially since it seems mIRC doesn't even search for a /var alias which would be the only other thing which might set the two methods apart.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: /var with no equals sign [Re: starbucks_mafia] #177429 24/05/07 06:25 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Good point, it didn't occur to me to check whether "%var = <value>" also calls /set (which in retrospect makes sense). Having noticed that %var = is at least as fast as /set (in fact, ever so slightly faster), I dismissed that possibility, remembering what an apparently similar approach did to $iif(). It may be, however, that mirc replaces "%var = " with "set %var" or "set -l %var" at an early stage during parsing, so no extra commands are called (like they are called in $iif() for example).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: /var with no equals sign [Re: RoCk] #177438 24/05/07 07:21 PM
Joined: Dec 2002
Posts: 580
N
NaquadaServ Offline OP
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
Originally Posted By: RoCk
Also, if you think about it, /var %var is more like describing the temporary (soft?) meaning of %var to the currently executing script, where /set %var is permanently (hard?) setting %var with the provided data. So using the equal sign with /var makes perfect sense really.[/i]


If you say so... confused


NaquadaBomb
www.mirc-dll.com
Re: /var with no equals sign [Re: NaquadaServ] #177439 24/05/07 07:25 PM
Joined: Dec 2002
Posts: 2,021
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,021
I was being facetious, but the more I read it the more I like it. grin

Re: /var with no equals sign [Re: NaquadaServ] #177525 26/05/07 03:58 PM
Joined: Dec 2002
Posts: 580
N
NaquadaServ Offline OP
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
Originally Posted By: NaquadaServ
As a fix, it would be nice if multiple variable support was disabled when no equal sign preceeds /var %var.

I retract this statement, mostly because I can't see why parsing with multiple variables (and no equals sign) would be any more difficult.

Code:
var %aa = $a(1, 3), %bb, %cc, %dd, %ee = 0, %ff = %aa
var %aa $a(1, 3), %bb, %cc, %dd, %ee 0, %ff %aa

The key first step would be to "tokenize" the commas that are outside of parentheses. The second step would be to toss away or ignore the equals sign (if someone used one). smile

Edit: Or as a second step, add an equals sign if missing and continue parsing normally. I like the other way better though. smile

Last edited by NaquadaServ; 26/05/07 04:07 PM.

NaquadaBomb
www.mirc-dll.com