s |
focus search bar ( enter to select, ▲ / ▼ to change selection) |
g e |
go to examples |
g m |
go to modules |
g o |
go to overview |
g r |
go to reference |
h |
toggle this help ( esc also exits) |
#must
foo :: (x: int) -> bool #must {}
- ensure caller receives return values marked with #must
. 1 2 3
/** from: https://youtu.be/CttIYXCUeVY?t=3515 */
must :: () {
Vector3 :: struct {
x, y, z: float;
}
Vector2 :: struct {
x, y: float;
}
producer :: (count: int) -> ^ Vector3 #must, ^ Vector2 #must, bool {
is_even := (count % 2) == 0;
return new [count] Vector3, new [count*2] Vector2, is_even;
}
r1 : ^Vector3;
r2 : ^Vector2;
r3 : bool;
r1, r2, r3 = producer(5); // this is valid
r1, r2 = producer(7); // this is valid
r1 = producer(9); // this generates compiler error: "disallowed by #must"
producer(9); // this generates compiler error: "disallowed by #must"
}
the problem that comes up is that sometimes you could ignore a return value that you actually really needed to pay attention to.
“Arguments and Return Values” YouTube, uploaded by Jonathan Blow, Mar 10, 2015, https://youtu.be/CttIYXCUeVY?t=3515 ⮌
the caller has to receive these values. if the caller does not receive these values, that’s an error.
“Arguments and Return Values” YouTube, uploaded by Jonathan Blow, Mar 10, 2015, https://youtu.be/CttIYXCUeVY?t=3568 ⮌
this is not for you to be all anally retentive and put #must
on every single return value in your api to make sure people check status codes. no. this is for very specific, “you droppped this resource on the floor kind of cases”.
“Arguments and Return Values” YouTube, uploaded by Jonathan Blow, Mar 10, 2015, https://youtu.be/CttIYXCUeVY?t=3805 ⮌
jailang
2019 pixeldroid
https://github.com/pixeldroid/jailang |
programming pages theme v0.5.21 (https://github.com/pixeldroid/programming-pages) |
s |
focus search bar ( enter to select, ▲ / ▼ to change selection) |
g e |
go to examples |
g m |
go to modules |
g o |
go to overview |
g r |
go to reference |
h |
toggle this help ( esc also exits) |