std/cl

模块 zio.cl — Common Lisp shape compatibility layer · 6 个符号

CL-shaped names for the zio reader: dolist/prog1/prog2/ignore-errors, plus the core when-let/if-let re-exported so one require covers the set.

The forms this file USED to define — defvar/defparameter/defconstant, defun with paren lambda-lists, flet/labels — are native core forms now (ADR-044 + L1 增补注, 2026-11-18): requiring this module is no longer needed for them, and this file no longer shadows any special form (special forms are reserved words; a macro may not expand over one).

This is a SHAPE compatibility layer, not Common Lisp: the reader is zio's, the evaluation model is zio's, and each doc below states the CL difference that matters for that form. Load with

(require :std.cl)

resolving std/cl.zio inside a granted module root (--lib-dir or ZIO_PATH pointing at the directory that contains std/).

NOT implemented, by design (zio has no mechanism for them):

  • setf (zio assigns with def/set!; no generalized places),
  • tagbody/go (no go tags),
  • return-from (no named-block mechanism; use functions or loop/recur). Multiple values ARE core now (values / multiple-value-bind / …); the flet/labels spellings are native special forms with CL semantics (flet isolation, labels self/mutual recursion, CL lambda-list params).

概览

dolist

(defmacro dolist [binding & body] …)

(dolist [x coll] body...) — run body once per element of coll with x bound to it, in order; returns nil. The binding must be a two-element vector ([x coll]), following dotimes' shape. CL's (dolist (x coll) ...) uses a paren list and an optional result form — the result form is not carried (dolist is nil-valued here); a non-vector or wrong-arity binding is refused.

(dolist [x [1 2 3]] (println x))
; 打印 1 2 3,返回 nil

prog1

(defmacro prog1 [expr & body] …)

(prog1 expr body...) → expr's value — evaluates expr FIRST, then body left to right, and returns expr's value. expr is evaluated exactly once (a gensym'd slot).

(prog1 :first (println "side"))
; 打印 side,预期 :first

prog2

(defmacro prog2 [first-expr second-expr & body] …)

(prog2 expr1 expr2 body...) → expr2's value — evaluates expr1 for effect, then expr2, then body, returning expr2's value.

(prog2 (println "one") :second (println "three"))
; 打印 one three,预期 :second

ignore-errors

(defmacro ignore-errors [& body] …)

(ignore-errors body...) → body's value, or nil on ANY error — CL ignore-errors shape. zio's with-handlers declines when its handler returns a value, so the working shape here is the try/catch expansion: (try (do body...) (catch any nil)). The error object is NOT returned — the handler discards it (zio binds the error message string to error inside a catch, but ignore-errors returns nil exactly like CL) — and the error is swallowed: no condition escapes.

(ignore-errors (error "boom"))
; 预期 nil
(ignore-errors 1 2)
; 预期 2

Re-exports from core

when-let

(def when-let …)

when-let/if-let live in the bootstrap core (they are stdlib, not CL only); binding them here under the module's own env lets std.cl export the pair, so one require covers the whole CL-shaped set.

if-let

(def if-let …)

无文档。