Adam Cameron
function pow(required numeric base, required numeric exponent) {
return base ^ exponent
}
// control - normal call
writeOutput(pow(2,3)) // 8
writeOutput("<hr>")
//using array
operandsAsArray = [2,3]
writeOutput(pow(...operandsAsArray)) // 8
writeOutput("<hr>")
// using struct
operandsAsStruct = {
base = 2,
exponent = 3
}
try {
writeDump(pow(...operandsAsStruct)) // splat
} catch (any e) {
writeDump([
type = e.type, // Application
message = e.message // The BASE argument passed to the pow function is not of type numeric.
])
}
function argTypeCheck(x, y) {
writeDump([
arguments = arguments,
"x.type" = x.getClass().getName(),
"x.key" = x.getKey(),
"x.value" = x.getValue()
])
}
st = {
x = 2,
y = "three"
}
argTypeCheck(...st) // WTaF
https://trycf.com/gist/062dfa6d4651304929c6e144588fd8bf/acf2021?theme=monokai
Result:
https://i2.paste.pics/d098bdd981455e4a5db9f5395e860092.png▾
Adam Cameron