1. Values are thunks; $ forces
Teaches: description-vs-value, $ (ADR-0007)
Every value in bang is a thunk — a description of a computation, not the
computation run. Writing a never runs anything; only $a (force) runs
it to a value.
This program allocates a TVar, writes read a - 30 into it, then reads it
back — inside an atomically block so the read/write pair is one
transaction. Notice read a - 30 parses as (read a) - 30: effect
operations parse at application precedence, so they compose with arithmetic
the way you'd expect from reading it left to right.
atomically (let a = new 100; z = write a (read a - 30) in read a)Expected output (bang run stdout):
70Run it yourself:
curl -fsSL https://raw.githubusercontent.com/phibkro/bang/main/tools/install.sh | sh
bang run examples/effect-op-arith/main.bang