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.