• v0.5.0 b4b1bfc055

    tklips v0.5.0 Stable

    michael released this 2026-11-05 21:40:57 +00:00 | 5 commits to master since this release

    tklips v0.5.0: files and streams, constants, help in the shell, random draws, and aggregates in rules, which also check much less work again after a change. The reference PDF documents the language as released.

    Breaking changes

    • pi and e are removed. Write the constants &PI and &E instead of (pi) and (e).
    • set returns the value it binds, _ included, instead of _. The shell and batch mode write that value as the result of a top-level set; (and (set o x) ...) goes on when x is true; and set as a fact predicate keeps the facts whose value is true. Where a program relied on the _, write (block (set x v) _).
    • Global variables cannot take a constant's name. (set PI 3) at top level fails with set: cannot shadow constant PI, and so do the other built-in constants: TAU, E, INT-MAX, INT-MIN, STDIN, STDOUT and STDERR. Rename such variables; parameters and variables inside functions and rules may still use these names.

    Language

    • Constants. (const NAME value) defines a constant at top level, with an upper-case name; it cannot be defined again. &NAME reads it everywhere, in function bodies, lambdas and rules included, unless a parameter or local variable shadows it. (const-list) lists them all. The built-in constants are PI, TAU, E, INT-MAX, INT-MIN, STDIN, STDOUT and STDERR. The new error codes are define/constant and define/scope.
    • Help. (? name) writes a function's signature and what it does, and where a user function was defined. It evaluates none of its arguments, so ? can head a call being written: (? text-pad-left 42 5). (?) lists every function and constant. (func-info f) gives the same as an object. The # lines right above a top-level func or const are its doc, and every built-in and standard library function has one.
    • Files, URLs and standard streams.
      • (io-open path fn (.mode read)) opens a resource, calls fn with its integer id, and closes the resource however fn ends, errors and interrupts included. (io-with (in a.txt) (out b.txt (.mode write)) body...) does the same around a body.
      • io-read-line, io-read, io-write and io-print read and write a resource. io-info and io-list inspect the open ones.
      • Ids 0, 1 and 2 are stdin, stdout and stderr. Files are opened inside the current directory, with mode read, write or append. URLs are read only.
      • Errors belong to the new io/ family: io/denied, io/not-found, io/not-accessible, io/closed, io/mode, io/read and io/write.
    • Random draws.
      • (random), (random end) and (random start end) draw a float in [0, 1), or a number in [start, end), an integer unless a bound is a float. (shuffle obj) gives the items of an object in a random order.
      • (seed n) replays the draws of a seed, (seed) sets a fresh one and returns it, and (seed-get) gives the seed in effect.
      • With .key, a draw is fixed by its key and the seed, and leaves the generator as it was.
      • The generators are xoshiro256** and SipHash-1-3, so a seed gives the same draws on every host. They are not cryptographic.
    • Standard library, new libraries:
      • file: file-read, file-write, file-append and file-each-line.
      • enum: enum, enum-str, enum-name, enum-has and enum-check, which builds and checks sets of named constants.
      • random: random-pick and random-sample.

    Facts

    • fact, fact-find, fact-find-read and fact-del-all find facts by their first written value through an index, instead of walking the whole relation.

    Rules

    • Aggregates. (*collect* (name expr) c...) always holds. It binds name to an object holding the values of expr, one for each way facts satisfy c..., or to (obj) when none do. The rule fires again when that object changes, so a rule with a fact upsert keeps an aggregate fact up to date: (fact total (.order &o) > (.sum (+ *prices))). A name already visible fails with rule: already captured <name>.
    • Chance. (*chance* p key...) holds with probability p, drawn with a key made of the rule's name and the keys, or every visible capture when no key is written. A new seed draws every condition again. Unkeyed random and shuffle, and seed, fail in rule conditions with not allowed in a rule condition, as the fact and io- built-ins do.
    • Faster checks. run and run-prepare look at a fired activation or a tracked support again only when a change concerns it. A rule whose relations did not change costs nothing. rule-stats counts these looks as (.checked n).

    Interactive shell

    • A top-level set writes the value it binds (see Breaking changes).

    Command line

    • --seed <n> starts random draws from the seed n. Without an integer after it, it fails with tklips: --seed needs an integer.
    • When the program comes from a file, stdin is the stream 0 that programs read.

    JavaScript module

    • The open(path, mode) option opens resources for io-open, and the stdin(max) option gives what stream 0 reads. The defaults:
      • Node opens files inside the current directory, fetches URLs with allowUrl, and reads its standard input.
      • A browser fetches every path, relative to the page.
    • What a program writes to stream 2 goes to the stderr option.
    • The seed option starts random draws from a seed, and reset goes back to it.
    • reset forgets the program's constants.

    Python module

    • The open, stdin and seed options, as in the JavaScript module. Stream 2 goes to stderr, and reset forgets the program's constants.
    • Evaluations nested 100 deep through Python functions fail with stack overflow, as in the JavaScript module; they could fail with the engine failed instead.

    SHA-256

    5675c463b1b5f767d792533c3db1cbd98b674ce30e55ca0d812851a5f3ebe443  tklips-v0.5.0-linux-x86_64
    0b61bee6a797a3bf86f5376cd6db9093cfdf0d9d0e056e53f5e49bbbdb03beec  tklips-v0.5.0.mjs
    4113a781321a5c3dec57a91e1db2ddcdf256160c951a55278141cd4b8495560c  tklips-v0.5.0.py
    112d0534cb72828fcb478660a9acaf5da8d56afb144dfc96d8daf483e6dd85fc  tklips-v0.5.0-reference.pdf
    
    Downloads