mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
Fix typos and improve clarity of or_return_operator
This commit is contained in:
+14
-16
@@ -2063,13 +2063,13 @@ or_return_operator :: proc() {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The above idiom can be transformed into the follow
|
// The above idiom can be transformed into the following
|
||||||
n1 := caller_2() or_return;
|
n1 := caller_2() or_return;
|
||||||
|
|
||||||
|
|
||||||
// And if the expression has no other, it can be used like this
|
// And if the expression is 1-valued, it can be used like this
|
||||||
caller_1() or_return;
|
caller_1() or_return;
|
||||||
// which is functionally equivalen to
|
// which is functionally equivalent to
|
||||||
if err1 := caller_1(); err1 != nil {
|
if err1 := caller_1(); err1 != nil {
|
||||||
return err1;
|
return err1;
|
||||||
}
|
}
|
||||||
@@ -2090,30 +2090,28 @@ or_return_operator :: proc() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The above idiom can be transformed
|
// The above idiom can be transformed into the following
|
||||||
y := caller_2() or_return;
|
y := caller_2() or_return;
|
||||||
|
|
||||||
// And if the expression has no other, it can be used like this
|
// And if the expression is 1-valued, it can be used like this
|
||||||
caller_1() or_return;
|
caller_1() or_return;
|
||||||
|
|
||||||
// which is functionally equivalen to
|
// which is functionally equivalent to
|
||||||
if err1 := caller_1(); err1 != nil {
|
if err1 := caller_1(); err1 != nil {
|
||||||
err = err1;
|
err = err1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a the other values need to be set depending on what the end value is,
|
// If a non-bare 'return' is required, then a normal 'if' can be used as it is
|
||||||
// the 'defer if' is can be used
|
// a lot clearer to read
|
||||||
defer if err != nil {
|
if z, zerr := caller_2(); zerr != nil {
|
||||||
n = -1;
|
return -345 * z, zerr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a non-bare return is required, then a normal if is a lot clearer
|
// If the other return values need to be set depending on what the end value is,
|
||||||
// and gets around the short circuiting
|
// the 'defer if' idiom is can be used
|
||||||
if z, zerr := caller_2(); zerr != nil {
|
defer if err != nil {
|
||||||
n = -z;
|
n = -1;
|
||||||
err = zerr;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n = 123;
|
n = 123;
|
||||||
|
|||||||
Reference in New Issue
Block a user