• v0.3.0 3661d23321

    tklips v0.3.0 Stable

    michael released this 2026-10-23 16:50:32 +00:00 | 28 commits to master since this release

    tklips v0.3.0 splits programs into sources with a standard library, handles errors as values, names built-in arguments, and gives rules test conditions and simpler patterns; the JavaScript module becomes asynchronous. tklips-v0.3.0-reference.pdf documents the language as released.

    Breaking changes

    • Capture patterns (fact-match, fact-match-read, rule patterns) capture into bare names: write (person name (.age a)) instead of (person &name (.age &a)). .age alone is short for (.age age).
    • No literals in capture patterns: write (person .sex (= &sex M)) instead of (person (.sex M)). A number in a pattern now fails with invalid variable name, and a text is a capture, so an old pattern with text literals matches more facts.
    • Strict functions: a user function or lambda without a rest parameter rejects arguments it has no parameter for, with <f>: expected at most <n> arguments, got <m> and <f>: unknown named argument <name>. Add a rest parameter (*rest) to accept them.
    • New built-in names: require, std, fail, try, catch and recovery. A function of one of these names must be renamed.
    • Error messages and output: built-ins with parameter names report <f>: missing argument <param> and <f>: expected at most <n> arguments, where they reported expected <n> arguments; an error raised inside a function is followed by its trace lines; the shadowing warning writes capture a shadows a variable, without &.
    • JavaScript API: eval, call, apply, run, runProgram, and a session's feed and end return Promises: await them. define, undefine, reset and session() stay synchronous.

    Language

    • (require source) imports a source once, in the scope where it is written, running its forms without echo; errors in it are located as lib.tk:2:1.
    • The standard library, written in tklips: (require (std text)) imports the text library, with text-pad-left, text-pad-right, text-center, text-lines, text-wrap, text-capfirst and text-capwords. (std text v0.3.0) names the copy of a given release.
    • Errors are values with a code (type/not-text, unknown/function, arg/arity…), a message, data and a trace:
      • (fail code message (.name value)…) raises one, its named arguments as data, and (fail e) raises a caught one again;
      • (try expr… (catch e handler…) (catch (e code…) handler…)) handles them, a code ending with / taking a whole family;
      • (recovery value) in a block, a try or a rule's actions ends the rest of the body with value, or a function's result on the error, when an error comes after it.
    • An error nothing handles is written with the calls it went through: in f, called at 3:1.
    • Built-ins take their arguments by position or by name: (str-sub s (.end 3)), (reduce xs &+ (.init 10)), (partial map (.fn f)), (range 10 (.step 3)), (run (.limit 5)), and likewise str-find, str-replace, str-repeat, slice, chunk, repeat, sort, filter, count, any, all, find, find-pos, group-by, partition, for-each, log and atan. str-sub and slice start at 0 by default.

    Rules

    • (*test* expr…) holds when its expressions are true, with the captures of the conditions before it: to compare patterns, (rule bigger (p x) (q y) (*test* (> &x &y)) > …), as an alternative of *either*, or as what every match of *every* satisfies. It can be *persist* or *track*.
    • An error in a rule's test or action can be handled by recovery in its actions, which ends that firing and lets run go on, or by a try around run.

    Command line

    • tklips main.tk runs a program file instead of stdin; tklips -i main.tk runs it, then opens the shell.
    • --allow-url lets require fetch http:// and https:// sources with curl; files are read only inside the current directory.
    • --stdlib <location> takes the standard library from another directory or URL; a release reads its own tagged copy by default.

    JavaScript module

    • A JavaScript function may return a Promise: the evaluation waits for it where the call stands, and the function may call back into its runtime meanwhile.
    • createRuntime({ resolve, read, stdlib }) says where require finds sources and where the standard library is; by default, paths are URLs, and Node reads files of the current directory.
    • TklipsError has code, data, trace and source; tklipsFail(code, message, data) makes an error a JavaScript function can throw with a code.

    SHA-256

    0462340c083f37e115d12f74f00f7926468cafad99ad16a7adc6f48590a34249  tklips-v0.3.0-linux-x86_64
    b9b12f85d113c9640f1bb6adf7a2caa17d91648c991ad3ce4dd695d925ae4674  tklips-v0.3.0.mjs
    8da22559b355325af6ab84af4d20726346f51feb3b1845b275ec229a29068f15  tklips-v0.3.0-reference.pdf
    
    Downloads