• v0.2.0 2cbcbc4391

    tklips v0.2.0 Stable

    michael released this 2026-10-22 19:24:05 +00:00 | 39 commits to master since this release

    tklips v0.2.0 grows the language with text, number and collection built-ins, gives rules an explicit firing order and fact tracking, and ships the engine as a JavaScript module. The language reference for this version is attached as a PDF.

    Breaking changes

    • % is now rem, with the same behavior: (% 7 3) becomes (rem 7 3). The new mod is the floored modulo, with the sign of the divisor.
    • attrs returns an object's attributes as an object, (obj (.x 1)), instead of a list of (obj (.name x) (.value 1)). Use keyvalues for a list of (obj name value) pairs, and keys or values for the names or values alone.
    • fact-set and fact-update are removed, and so is the keyed form of fact-add ((fact-add rel key... > update...)). Write (fact-change id update...) for (fact-set id > ...) and (fact-update id > ...), and (fact rel pattern... > update...) for (fact-set rel pattern... > ...).
    • A call whose head is &name now calls what name holds: (&f 1) used to fail with unknown function: &f.
    • Many new built-in names (listed below) can no longer be defined with func. A &name reference to one of them where no variable of that name is visible, such as &last or &min, now gives the built-in's function value instead of failing with unbound variable. Variables of those names keep working where they are visible.

    Language

    • Texts: str-len, str-sub, str-find, str-starts, str-ends, str-split (at a separator, into characters or at whitespace, with .max), str-join, str-upper, str-lower, str-trim, str-ltrim, str-rtrim, str-replace, str-repeat, str<, str>, str<=, str>= and str-cmp. They take texts only and count characters, not bytes. str turns any value into a text, and num reads a number back, giving _ when the text isn't one.
    • Kinds: kind names any value's kind (int, float, str, none, list, obj, func), and is-int, is-float, is-number, is-str, is-none, is-list, is-obj and is-func test for one.
    • Numbers: floor, ceil, round and trunc return integers; abs, min, max, mod, cmp; pow, exact on integers; sqrt, exp, log (with an optional base), sin, cos, tan, asin, acos, atan (with atan2), (pi) and (e). A result that isn't a real number fails with not a real number. nears compares two numbers to 10 decimal places, or .digits.
    • Collections, on an object's items, keeping their positions: filter (without a predicate, it removes the holes), reverse, slice, concat, flatten, partition, zip, chunk and numbered. Giving new lists: sort (stable, with a comparator or a .key), unique, group-by, range (integers or floats, with .inclusive) and repeat. Giving one value: reduce, find, find-pos, any, all, count, first and last.
    • Attributes: keys, values, keyvalues, from-keyvalues and merge. items and attrs split an object in two, and (obj *i *a) rebuilds it.
    • (. obj key...) follows a path of keys, giving _ as soon as an entry is missing or a value on the way isn't an object.
    • Functions: call, map, compose, pipe and partial. Wherever a function is expected, its name works too, and (&f args...) calls the function a variable holds.
    • pprint writes a value in an indented form, one entry per line.

    Facts

    • fact-add always adds a fact. fact-change changes the fact with a given id. fact is the upsert by pattern: with > update... it updates the one match or adds the pattern and updates it; without, it adds the pattern only when nothing matches, and returns the id either way.

    Rules

    • (*after* name...) and (*before* name...), written among a rule's conditions, put it after or before other rules whenever both have activations pending.
    • *track* on a condition, or (*track*) for every condition of a rule, makes a firing own the facts it creates: once a tracked condition stops holding, the next run removes them, as CLIPS does with logical.

    Interactive shell

    • A result holding nested objects prints one entry per line, indented. Batch mode keeps every result on one line.

    JavaScript module

    • New: tklips-v0.2.0.mjs, one ES module with the engine compiled to WebAssembly, for Node 18+ and browsers. createRuntime() gives independent runtimes with eval, call, apply, run, reset, runProgram and interactive sessions. Values convert both ways, and errors throw a TklipsError.
    • define makes JavaScript functions callable from tklips as built-ins, with named arguments if asked for; undefine removes one.

    SHA-256

    4e4619692df2f7ff1fcfaffacde23a17ce8a1f18e05c96804139ce22423a305d  tklips-v0.2.0-linux-x86_64
    d184f6030d5fbcb2b480dd61f492fa75ccbbb5a73230a93cef8309b152c9fb68  tklips-v0.2.0-reference.pdf
    97140e6b455dcf98538394a72ef68c95a271ac30a8604f3e44b675ab1082fe57  tklips-v0.2.0.mjs
    
    Downloads