rebRescue() in the C API returns an error, or null if no error... in which case your result is the value that's passed by pointer-to-pointer:
Value* result;
Value* error = rebRescue(&result, "append 123 456"); // illegal, fails
if (error) { // non-0 pointer value means not ~null~ antiform
/* handle error */
}
else {
/* result is valid */
}
But JavaScript doesn't have pointer-to-value semantics. So you have to use multi-returns.
I didn't know how they did that, so I looked it up. There are two ways. You can destructure an array:
function getValues() {
return [getFirstValue(), getSecondValue()]
}
const [a, b] = getValues() ; any names you want here
Or you can destructure an object, where you have to use the names of the fields as the same names as your destructure variables:
function getValues() {
return {
first: getFirstValue(),
second: getSecondValue(),
}
}
const {first, second} = getValues()
If you don't want to use the exact names, there's another syntax:
const {a: first, b: second} = getValues()
I don't know if naming multi-returns is super important, and have had bigger ambitions for antiform objects.
The StackOverflow question has someone prescribing that it's very important to pick the named version over the non-named one. I don't agree, and plan on using the array form for rebRescue()
The much bigger issue in my mind is forgetting to do the destructure, and getting back a value that's in-band as a plain array or object, when you really just forgot to destructure. Isotopes do a very good thing here, not seen in other languages...decaying to the first item by default, and generalizing moving the out-of-band into band via meta/quasi/etc. forms in order to write peer destructuring operators when you need to.
This is a repeat of JavaScript's issue with Promise, where if you forget to do an AWAIT then you wind up with a Promise by value that you didn't expect. But AWAIT is terrible for all kinds of other reasons, so we're not going down that road.