mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-11 03:45:29 +03:00
26 lines
437 B
Plaintext
26 lines
437 B
Plaintext
# Test that branching statements can end with an assignment
|
|
type MyTree:
|
|
node { val, ~lft, ~rgt }
|
|
leaf
|
|
|
|
def main:
|
|
deep = 0
|
|
|
|
if deep:
|
|
n = 20
|
|
else:
|
|
n = 2
|
|
|
|
bend x = 1, h = 0:
|
|
when h < n:
|
|
y = MyTree/node { val: x, lft: fork(2 * x, h + 1), rgt: fork(2 * x + 1, h + 1) }
|
|
else:
|
|
y = MyTree/leaf
|
|
|
|
fold y:
|
|
case MyTree/node:
|
|
z = y.val + y.lft + y.rgt
|
|
case MyTree/leaf:
|
|
z = 0
|
|
|
|
return z |