FoundationsExpressions Everywhere
Blorp by Example

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.

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

if-value.brp
label: String = if score >= 70:
    "passing"
else:
    "retry"

Statement-only Conditionals

An if used only for effects can omit else.

if-statement.brp
if score < 70:
    print("try again")

Loops Return Void

for and while are for repeated work; values inside loop bodies are discarded after evaluation.

loops.brp
for score in scores:
    print(score.to_string())

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

Try It

terminal
blorp run temperature.brp