return if statement request
MairwunNx opened this issue · 2 comments
MairwunNx commented
I have seen similar syntactic sugar in some languages, for example Kotlin, I would like to see it in BosqueLanguage
, I think it would not be a bad idea for a language design.
Example:
function abs(x: Int): Int {
if(x < 0) {
return -x;
}
else {
return x;
}
}
If use return if statement:
function abs(x: Int): Int {
return if(x < 0) {
-x;
}
else {
x;
}
}
Example 2:
function absy(x?: Int): Int {
if(x == none) {
return 0;
}
return {
var! y = x;
if(y < 0) {
y = -y;
}
yield y;
}
}
If use return if statement:
function absy(x?: Int): Int {
return if(x == none) {
0;
}
else {
var! y = x;
if(y < 0) {
y = -y;
}
y;
}
}
hearot commented
I love the abs
example. Awesome!