Lexical closures
Functions capture the environment where they are defined. Interactive redefinitions do not rewrite existing closures.
(define make-adder
(fun (base)
(fun (value) (+ base value))))
Write ordered policies over typed inputs, require approval for risky tools, and inspect deterministic outcomes. Your code runs entirely in the browser and is never sent to a server.
Choose an example, edit the code, then press ⌘+Enter to run it.
read-all
void
void
Yin is more than a syntax toy: its interpreter and type checker share one thoroughly tested language specification.
Functions capture the environment where they are defined. Interactive redefinitions do not rewrite existing closures.
(define make-adder
(fun (base)
(fun (value) (+ base value))))
Arguments, return values, and assignments are checked before execution, with precise source locations for errors.
IntFloatBoolStringAny(U Int Float) expresses multiple possibilities under explicit subtype rules.
Construct typed records, inherit fields transitively, and read them without sacrificing static types.
(record Point [x Int] [y Int])
(define point (Point :x 10 :y 20))
(field point :x)
Read, measure, and combine fixed vectors with precise element types and checked bounds.
(define values (append [10 20] [30 40]))
(length values)
(at values 3)
Narrow unions, destructure immutable data, and combine typed collection and string operations.
(match (parse-int "42")
[(Int value) (+ value 1)]
[(Bool _) 0])
Represent expected failure as typed data and handle every success and error path before execution.
(match (fetch true)
[(Ok value) value]
[(Err message) (report message)])
Decode untrusted JSON into a closed source type, handle structured errors, and export the same contract as JSON Schema.
(match (decode-json Request text)
[(Ok request) (handle request)]
[(Err error) (field error :path)])
The JVM reference host checks installed capabilities, requires explicit write approval, and records a hash-chained trace that can be replayed without repeating effects.
yin --guard policy.yin --host host.json --trace run.jsonl
yin --replay run.jsonl
The JVM contract profile rejects ambient effects and binds the exact policy, input, and structured decision with SHA-256 digests.
yin --contract-check policy.yin
yin --contract-run policy.yin --input request.json