[Wish:] Wish introduce $ syntax to define a Constant
Posted: 08 Sep 2023, 00:46
Wish introduce &$ syntax to support creating anonymous and temporary variables.
Sometimes, we need to pass a VarRef to a function with ByRef parameters, but don't want the variable to be changed. For example:
[Code1:]
But currently, to make variables a,b,c,d,e unchangeable, we have to write like [Code2]. And [Code2] is totally equivalent to [Code1].
[Code2:]
Without this feature, we have to give every "unchangeable" variable a different alias every time func is called. After assigning each "alias variable", we should pass them to func. Obviously, naming again and again is boring and trivial. If someone doesn't come up with names for each variable each time, forcing them to give it a meaningless name is not doing anyone any favors.
But this feature can solve it. Every time we use &$, script will assign the right hand to a temporary variable without naming. The refs of $Var1 are different each time $Var1 is occurred. So we call them anonymous variable or temporary variable.
Also sometimes, we need simply pass values such as string or integer, to ByRef parameters just to make it run.
In this code below, $7... represents an anonymous and temporary variable.
[Code3:]
Without this feature, we have to produce five meaningless names for each integer above.
[Code4:]
As we can see, introducing this &$ syntax will become much more convenient.
Sometimes, we need to pass a VarRef to a function with ByRef parameters, but don't want the variable to be changed. For example:
[Code1:]
Code: Select all
f(&x1,&x2,&x3,&x4,&x5){
x1:=x2:=x3:=x4:=x5:=x1*x2+x3+x4+x5
}
a:=b:=c:=d:=e:=1
f(&a,&$b,&c,&d,&$e)
f(&$e,&c,&$b,&$a,&d)
f(&a,&b,&c,&$d,&e)
; .......................
[Code2:]
Code: Select all
f(&x1,&x2,&x3,&x4,&x5){
x1:=x2:=x3:=x4:=x5:=x1*x2+x3+x4+x5
}
a:=b:=c:=d:=e:=1
b1:=b,e1:=e
f(&a,&b1,&c,&d,&e1)
e2:=e,b2:=b,a2:=a
f(&e2,&c,&b2,&a2,&d)
d3:=d
f(&a,&b,&c,&d3,&e)
; .......................
But this feature can solve it. Every time we use &$, script will assign the right hand to a temporary variable without naming. The refs of $Var1 are different each time $Var1 is occurred. So we call them anonymous variable or temporary variable.
Also sometimes, we need simply pass values such as string or integer, to ByRef parameters just to make it run.
In this code below, $7... represents an anonymous and temporary variable.
[Code3:]
Code: Select all
f(&x1,&x2,&x3,&x4,&x5){
return x1:=x2:=x3:=x4:=x5:=x1*x2+x3+x4+x5
}
f(&$7,&$5,&$7,&$8,&$3) ; It will return 7*5+7+8+3=53
[Code4:]
Code: Select all
val:=0
f2(x,y)=>outputdebug(x)
f2(Var, $Var++)
;Var will not be influenced by Var++ this time and pass 0.