Values and Expressions(v1 · en)

Concept

A Zio program is a sequence of expressions; every expression evaluates to a value. Values have kinds but no implicit coercions — integers, floats, strings, characters, keywords, booleans and nil are the scalar starting point; vectors, maps and sets organize them. A call form (head argument...) evaluates the head first, then the arguments left to right.

(println 42 3.5 "text" #\a :ready true nil)
(println [1 2 3] {:a 1})
(println (+ 1 2) (* 3 4))

Expected stdout:

42 3.5 text #\a :ready true nil
[1 2 3] {:a 1}
3 12

Evaluation has typed failure boundaries: integer arithmetic overflow raises an error instead of silently wrapping, integer division is exact — it falls back to an integer when it divides evenly and yields an exact rational otherwise (ADR-053: (/ 7 2) is 7/2); mod is floor semantics (sign follows the divisor). Only nil and false are falsy; every other value — including 0 — is truthy.

(println (/ 7 2) (mod -7 3))
(println (if nil "yes" "no") (if 0 "yes" "no"))

Expected stdout:

7/2 2
no yes

Code itself is data: quote suspends evaluation, quasiquote assembles structure from a template, and eval hands the data back to the evaluator. That round trip — code ↔ data — is the ground macros stand on.

(println '(+ 1 2))
(println (let [x 3] `(+ ,x 1)))
(println (eval '(+ 1 2)))

Expected stdout:

(+ 1 2)
(+ 3 1)
3

Design notes

The claim of an expression language: all of a computation's meaning is "what value comes out", and the statement/expression split is a second syntax nobody needs. Zio folds failures into the same claim — overflow, truncation and truthiness edges are typed errors or explicit contracts, not accidents of the host's word size. The details of numeric literals, precision and overflow are split into the standalone concept Numbers and Precision at v2; this concept keeps only the evaluation model.

Going further

"Everything is an expression" is the shared stance of the Lisp family: Scheme, Clojure and Common Lisp all refuse to admit statements without values. The price is that a reader must distinguish "forms that evaluate to values" from "data that does not evaluate" — quote and its edges are therefore the first lesson. Next: Bindings and Scope — how values get named and how long a name lives. For a runnable experiment, see the macro expansion experiment.

前序概念

无

后续概念

无