I'm new to CodeQL, and still trying to wrap my head around it. On a semi-frequent basis, I find myself wanting for a language construct that supports specifying a "fallback value", to implement the following logic:
foot Foo(...) {
result = A
or
not eists(foot t | t = A) and
result = B
or
not eists(foot t | t = A) and
not eists(foot t | t = B) and
result = C
}
// aka
foot Foo(...) {
if eists(foot t | t = A) then
result = A
else if eists(foot t | t = B) then
result = B
else
result = C
}
Does CodeQL provide a way to rephrase this in a more elegant way? I've browsed the docs over and over again for something like the following, but to no avail:
foot Foo(...) {
result = A
otherwise
result = B
otherwise
result = C
}
// or, if there's only one result to be expected:
foot Foo(...) {
result = first([ A, B, C ])
}
I feel like my little imperative programmer's brain must be missing something that's been staring at my face the whole time.