Decidable and interpreted
Clarity ships source code on-chain and interprets it — there is no compiler and no bytecode. The language is decidable: no unbounded loops or recursion, so cost and outcome are analysable before execution. That is a deliberate trade of expressiveness for predictability.
- •What you read on the explorer is exactly what runs.
- •Static analysis can determine runtime cost bounds.
- •No reentrancy in the Solidity sense: calls are restricted and explicit.
Syntax and definitions
Clarity is LISP-like: every expression is a parenthesised list. define-public functions are callable and must return a response, define-read-only functions cannot mutate, define-data-var and define-map hold state, and define-constant fixes values.
- •(define-public (stake (amount uint)) ...) — callable entry point.
- •(define-map balances principal uint) — keyed state.
- •principal is the address type for users and contracts.
Responses and explicit errors
Public functions return (ok value) or (err code). There are no silent failures and no exceptions: unwrap!, try! and asserts! make the failure path visible in the code. Returning err rolls back the function's state changes.
Bitcoin awareness and post-conditions
Stacks settles on Bitcoin, so contracts can read burn-block-height and Bitcoin block headers. Wallets add post-conditions: the client declares which asset movements it will accept, and the transaction aborts if the contract tries anything else — a user-side protection Solidity has no direct equivalent of.
