-
tklips v0.5.0 Stable
released this
2026-11-05 21:40:57 +00:00 | 5 commits to master since this releasetklips 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
piandeare removed. Write the constants&PIand&Einstead of(pi)and(e).setreturns the value it binds,_included, instead of_. The shell and batch mode write that value as the result of a top-levelset;(and (set o x) ...)goes on whenxis true; andsetas 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 withset: cannot shadow constant PI, and so do the other built-in constants:TAU,E,INT-MAX,INT-MIN,STDIN,STDOUTandSTDERR. 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.&NAMEreads 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 arePI,TAU,E,INT-MAX,INT-MIN,STDIN,STDOUTandSTDERR. The new error codes aredefine/constantanddefine/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-levelfuncorconstare 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, callsfnwith its integer id, and closes the resource howeverfnends, 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-writeandio-printread and write a resource.io-infoandio-listinspect the open ones.- Ids
0,1and2are stdin, stdout and stderr. Files are opened inside the current directory, with moderead,writeorappend. URLs are read only. - Errors belong to the new
io/family:io/denied,io/not-found,io/not-accessible,io/closed,io/mode,io/readandio/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-appendandfile-each-line.enum:enum,enum-str,enum-name,enum-hasandenum-check, which builds and checks sets of named constants.random:random-pickandrandom-sample.
Facts
fact,fact-find,fact-find-readandfact-del-allfind facts by their first written value through an index, instead of walking the whole relation.
Rules
- Aggregates.
(*collect* (name expr) c...)always holds. It bindsnameto an object holding the values ofexpr, one for each way facts satisfyc..., or to(obj)when none do. The rule fires again when that object changes, so a rule with afactupsert keeps an aggregate fact up to date:(fact total (.order &o) > (.sum (+ *prices))). A name already visible fails withrule: already captured <name>. - Chance.
(*chance* p key...)holds with probabilityp, 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. Unkeyedrandomandshuffle, andseed, fail in rule conditions withnot allowed in a rule condition, as the fact andio-built-ins do. - Faster checks.
runandrun-preparelook 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-statscounts these looks as(.checked n).
Interactive shell
- A top-level
setwrites the value it binds (see Breaking changes).
Command line
--seed <n>starts random draws from the seedn. Without an integer after it, it fails withtklips: --seed needs an integer.- When the program comes from a file, stdin is the stream
0that programs read.
JavaScript module
- The
open(path, mode)option opens resources forio-open, and thestdin(max)option gives what stream0reads. 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.
- Node opens files inside the current directory, fetches URLs with
- What a program writes to stream
2goes to thestderroption. - The
seedoption starts random draws from a seed, andresetgoes back to it. resetforgets the program's constants.
Python module
- The
open,stdinandseedoptions, as in the JavaScript module. Stream2goes tostderr, andresetforgets the program's constants. - Evaluations nested 100 deep through Python functions fail with
stack overflow, as in the JavaScript module; they could fail withthe engine failedinstead.
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.pdfDownloads