Expressions Everywhere
Blorp uses expressions for return values and ordinary decisions.
Last Expression Returns
A function body returns its final expression when the return type is not Void.
pure func double(n: Int) -> Int:
n * 2
`if` As A Value
if can produce a value when every branch produces a value of the same type.
label: String = if score >= 70:
"passing"
else:
"retry"
Statement-Only Conditionals
An if used only for effects can omit else.
if score < 70:
print("try again")
Loops Return Void
for and while are for repeated work; values inside loop bodies are discarded after evaluation.
for score in scores:
print(score)
Example
temperature.brp
pure func classify(temp: Int) -> String:
if temp < 50:
"cold"
else if temp < 80:
"warm"
else:
"hot"
func main(args: List[String]) -> Void:
print(classify(72)) -- prints: warm
Try it
terminal
blorp run temperature.brp