Liking cljdoc? Tell your friends :D

clj-zig.template

Reusable Zig body templates for common patterns. Each template returns a string of Zig source a defnz body can splice in or call. The templates are data-driven: they take the parameter names and produce idiomatic Zig, so the user does not hand-write the same boilerplate for every binary operation, slice fold, or comparison.

(defnz square [x :f64 :ret :f64]
  (template/binary-op "*" 'x 'x))

(defnz sum-slice [xs [:slice :const :f64] :ret :f64]
  (template/slice-fold 'xs 0.0 "+"))
Reusable Zig body templates for common patterns. Each template returns
a string of Zig source a `defnz` body can splice in or call. The
templates are data-driven: they take the parameter names and produce
idiomatic Zig, so the user does not hand-write the same boilerplate
for every binary operation, slice fold, or comparison.

    (defnz square [x :f64 :ret :f64]
      (template/binary-op "*" 'x 'x))

    (defnz sum-slice [xs [:slice :const :f64] :ret :f64]
      (template/slice-fold 'xs 0.0 "+"))
raw docstring

binary-opclj

(binary-op op lhs rhs)

Zig source for lhs op rhs, returning the result. A simple wrapper for the most common body shape: one binary operation on two named bindings.

Zig source for `lhs op rhs`, returning the result. A simple wrapper
for the most common body shape: one binary operation on two named
bindings.
sourceraw docstring

clampclj

(clamp val lo hi)

Zig source that clamps val between lo and hi.

Zig source that clamps `val` between `lo` and `hi`.
sourceraw docstring

comparatorclj

(comparator op lhs rhs)

Zig source for a comparison returning bool. op is one of <, >, <=, >=, ==, !=.

Zig source for a comparison returning bool. `op` is one of `<`, `>`,
`<=`, `>=`, `==`, `!=`.
sourceraw docstring

conditionalclj

(conditional pred t f)

Zig source for a conditional return: if (pred) return t; return f;

Zig source for a conditional return: `if (pred) return t; return f;`
sourceraw docstring

reducer-stepclj

(reducer-step binding init op)
(reducer-step binding acc-type init op)

Zig source that applies op (a compound assignment like +=, *=) between acc and each element of binding, with an optional accumulator type annotation.

Zig source that applies `op` (a compound assignment like `+=`, `*=`)
between `acc` and each element of `binding`, with an optional
accumulator type annotation.
sourceraw docstring

slice-foldclj

(slice-fold binding init op)

Zig source that folds a slice with an accumulator. Iterates binding, combines each element with the accumulator using the compound assignment op (e.g. +=, *=, etc.), starting from init. Returns the accumulator.

Zig source that folds a slice with an accumulator. Iterates `binding`,
combines each element with the accumulator using the compound assignment
`op` (e.g. `+=`, `*=`, etc.), starting from `init`. Returns the accumulator.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close