Simlplifies replacing invalid values in expressions.
The form is:
Consequent ?? Alternate
If Consequent resolves to invalid, then the alternate is executed and returned.
Note, just like with ternary, we have to ensure that the code for alternate is not executed, and that any evaluations required to facilitate the transpiled code DO NOT execute any potentially mutating code.
The following bs
a = user ?? new User("defaultName", m.itemId)
becomes
a = bslib.coalesce(user, {
"m": m
}, new function(scope)
m = scope.m
return new User("defaultName", m.itemId)
end sub)
function bslib_coalesce(consequentValue, scope, alternateFunc)
if alternate <> invalid
return return consequentValue
else
return alternateFunc(scope)
end if
end function
Simlplifies replacing invalid values in expressions.
The form is:
Consequent ?? Alternate
If Consequent resolves to invalid, then the alternate is executed and returned.
Note, just like with ternary, we have to ensure that the code for alternate is not executed, and that any evaluations required to facilitate the transpiled code DO NOT execute any potentially mutating code.
The following bs
a = user ?? new User("defaultName", m.itemId)becomes