asar icon indicating copy to clipboard operation
asar copied to clipboard

add an error() function

Open mellonpizza opened this issue 1 year ago • 4 comments
trafficstars

I've encountered situations where I'd like to create a function but it requires certain invariants to be upheld in the arguments, or else the output would be undefined and it would make most sense to throw an error, but there is currently no way to do this. I figure a reasonable solution would be to add an error() function which functionally can be identical to the error directive, with 1 string argument.

mellonpizza avatar Aug 20 '24 14:08 mellonpizza

isn't that the assert command?

assert 2+2 == 4, "your math sucks"

Alcaro avatar Aug 20 '24 14:08 Alcaro

asar's functions are (currently) eagerly evaluated. even the ternary function evaluates all arguments first. this is why we needed to add safediv(). this might be changing in 2.0, but definitely not before that

trillllian avatar Aug 20 '24 14:08 trillllian

oh right, you're writing a function. can't put asserts in that

we could add an assert() function, though

Alcaro avatar Aug 20 '24 14:08 Alcaro

and what do you propose its signature is? assert(condition, error_message, value_if_no_error)? that looks janky, and then the value branch needs to also not throw any errors if the condition isn't fulfilled...

trillllian avatar Aug 20 '24 14:08 trillllian