veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

diff

lib/diff.vk

lib/diff.vk Pure-Veko line-oriented LCS diff engine and unified diff formatter (--- a / +++ b). Ideal for test failure diagnostics, config previews, and veko fmt --check. Zero capabilities required.

DiffLine struct
signature
DiffLine = struct { op enum, text str, old_line i64, new_line i64 }

One entry in a computed line diff (op = .eq, .del, or .add).

signature
diff-lines = fn [old_text str, new_text str] block[DiffLine]

Computes a minimal line-by-line diff between strings old_text and new_text.

Executable Example
veko
use [diff]
ops = diff/diff-lines 'a\nb\nc' 'a\nx\nc\nd'
if (diff/equal? ops) [ err 'diff equal' ] else [ .ok ]
signature
equal? = fn [ops block[DiffLine]] bool

Returns true if ops contains no additions or deletions.

signature
format-unified = fn [old_name str, new_name str, old_text str, new_text str] str

Formats a unified diff string (--- old_name\n+++ new_name\n...) or '' when identical.

Executable Example
veko
use [diff]
u = diff/format-unified 'a.vk' 'b.vk' 'x = 1\ny = 2' 'x = 1\ny = 3'
if (not (str/contains? u '-y = 2')) or (not (str/contains? u '+y = 3')) [ err 'unified diff' ] else [ .ok ]