Named Parameter Assignment/Pass-By-Name:
passing values to optional parameters by name
[example]
Code: Select all
SampleFunction(var1, var2 := "default1", var3 := "default2") {
Msgbox % var1 . var2 . var3
}
SampleFunction("required string", var3:"optional param var3")
overload default operators for custom class objects
Code: Select all
Class Point {
__New(X, Y) {
this.X := X, this.Y := Y
}
;maybe prefix with a symbol when declaring for clarification? like @+ or a word like operator+
+(Point_obj) {
return new Point(Point_obj.X + this.X, Point_obj.Y + this.Y)
}
;operators ==, :=, -, ~=, !=... etc.
}
multiple functions of the same name, differentiated by param count
Code: Select all
Add(v1, v2) {
return v1 + v2
}
Add(v1, v2, v3) {
return v1 + v2 + v3
}
read-only variables that visible to all and resolved/replaced with their values at script auto-execute time
Code: Select all
;must be declared in AutoExecute section
#Define VAR_CONST_HEX 0xF00DFEED
#Define VAR_CONST_STR "FoodFeed"
return
SampleFunction() {
;no global or % resolve needed because references to variable are resolved to its value before function is run
Msgbox, VAR_CONST_HEX % VAR_CONST_STR
}
;would resolve to the following at runtime
SampleFunction() {
Msgbox, 0xF00DFEED % "FoodFeed"
}
functions that can be declared and called in active context
Code: Select all
SampleFunction() {
var1 := 100
sampleLammy := (x) => {return x++} ;maybe different syntax?
var1 := sampleLammy(var1)
;or
sampleLammy2 := (x) => {return x + var1} ;access to parent scope
var1 := sampleLammy2(250)
;and multline and re-assignment
sampleLammy2 := (x, y) => {
new_var := x * y ;lambda scope, non-static
return var1 / new_var
}
var1 := sampleLammy2(5, 2)
} ;once context falls out of scope, all lambdas are discarded
should be obvious for most, select code path based on expression contents
Code: Select all
;obviously for such a small number of options an 'if' would be fine, but for a large number of codepathes switch would help read-ability and possibly help performance for high traffic code pathes
SampleFunction(x) {
switch(x) {
5: ;maybe use [case 5:] instead
return "five"
"six":
return 6
"zero": ;fallthrough
default:
return 0
}
}
is value in range (compact), instead of using between and
Code: Select all
x := 55
if(x ~= 50..100 or x ~= 150..200)
return true
Code: Select all
Class myObj ...
x := new myObj()
if(x ~= myObj)
return true
Code: Select all
x := 5
if(x == 4,6,10)
return true