RPGHacker / asar

(Now) official repository of the SNES assembler Asar, originally created by Alcaro
Other
204 stars 43 forks source link

add an error() function #328

Open mellonpizza opened 2 months ago

mellonpizza commented 2 months ago

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.

Alcaro commented 2 months ago

isn't that the assert command?

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

randomdude999 commented 2 months ago

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

Alcaro commented 2 months ago

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

we could add an assert() function, though

randomdude999 commented 2 months ago

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...