Commands

Each command of ztcl has a page: its synopsis, what it gives, its options and subcommands, examples that run in the shell of the page, its errors, the capability that it needs, and how it differs from Tcl 8.6. A command with a capability has its name in a tag: a new interpreter does not have it until the host turns the capability on.

For agents, api.json has the same facts for each command, and llms-full.txt has the Markdown of each page.

Strings

  • string The commands for text: length, search, compare, change, and test.
  • tcl::prefix Matches a word to a unique prefix of a table, as a command does with its options.
  • append Adds each value to the end of the string in the variable, and gives the new value.
  • concat Joins the arguments with one space, after it removes the white space at the ends of each one.
  • format Makes a string from a template, as printf of C does.
  • scan Reads values from a string with a template of format.
  • split Makes a list: it cuts the string at each character of splitChars (white space by default).
  • join Makes a string of the elements of a list, with joinString (one space by default) between them.
  • regexp Finds the regular expression exp in string.
  • regsub Replaces the matches of exp in string with subSpec, and gives the new string.
  • subst Does the substitutions of Tcl on a string: $name, [script], and backslashes.
  • encoding channels Changes text to bytes and back.
  • binary Packs values into bytes and reads values from bytes, with a template of letters such as c (8 bits), s (16 bits, little endian), S (big endian), i and I (32 bits), w and W (64 bits), f and d (floats), a (bytes), and H (hexadecimal).
  • tcl_endOfWord The index after the end of the first word that ends after start, or -1.

Lists

  • foreach Runs a script for each element of one or more lists.
  • lappend Adds values as elements to the end of the list in a variable.
  • lassign Puts the elements of a list in variables, and gives the elements that are left.
  • ledit Replaces a range of elements of the list in a variable.
  • lfilter Gives the elements of a list for which a script gives true.
  • lindex Gives the element of a list at an index, or at a path of indexes into nested lists.
  • linsert Gives a list with elements put in before an index.
  • list Makes a list with each argument as one element.
  • llength Gives the count of elements of a list.
  • lmap Runs a script for each element of one or more lists, and gives a list of the results.
  • lpop Removes an element from the list in a variable and gives it.
  • lrange Gives the elements of a list from one index to another, as a list.
  • lremove Gives a list with the elements at some indexes removed.
  • lrepeat Makes a list with the same elements repeated a number of times.
  • lreplace Gives a list with a range of elements replaced by new elements.
  • lreverse Gives the elements of a list in the reverse order.
  • lsearch Finds the elements of a list that match a pattern.
  • lseq Makes a list of numbers in an arithmetic series.
  • lset Sets one element of the list in a variable, also in nested lists.
  • lsort Gives a sorted copy of a list.

Dicts and arrays

  • dict The commands for dicts: lists of keys and values with each key once.
  • array The commands for arrays.

Math

  • expr Computes an expression with the operators of C and the math functions.
  • incr Adds increment (1 by default) to the integer in a variable, and gives the new value.
  • tcl::mathfunc The functions of expr, each one also a command in this namespace.
  • tcl::mathfunc::trunc The math functions of Tcl 9.1: the functions of C99 acosh, asinh, atanh, cbrt, copysign, dim (fdim of C), erf, erfc, exp2, expm1, fma, gamma (tgamma of C), ldexp, lgamma, log1p, log2, logb, nextafter, remainder, and trunc, and the tests isfinite, isinf, isnan, isnormal, issubnormal, isunordered, and signbit.
  • tcl::mathop::lt The string order operators of Tcl 9.1: lt, gt, le, and ge.
  • divmod The quotient and the remainder of two integers of any size, as a list.
  • fpclassify The class of a number: zero, subnormal, normal, infinite, or nan.
  • frexp The fraction and the exponent of a double, as a list.
  • modf The integer part and the fraction part of a double, as a list.
  • remquo The remainder of remainder() and the low 3 bits of the rounded quotient with the sign of the quotient, as a list.
  • tcl::mathop Each operator of expr as a command: +, -, *, /, %, **, <<, >>, &, |, ^, ~, !, ==, !=, <, <=, >, >=, eq, ne, in, and ni.
  • noise3 Smooth noise of three coordinates, a float from -1 to 1, for shapes and textures.

Variables

  • set With a value, sets the variable and gives the value.
  • unset Removes variables.
  • global In a proc, links each name to the variable of the same name at the top level.
  • variable In a namespace, makes namespace variables and gives them values.
  • upvar Links a local name to a variable of a caller.
  • trace Runs a command when a variable is read, written, or unset, or when a command is renamed, deleted, or run.

Control flow

  • if Runs the body of the first condition that is true.
  • while Runs the command while the test, an expr expression, is true.
  • for Runs start once, then the command and next while the test is true, as the for of C.
  • break Stops the loop that runs it: while, for, foreach, lmap, or dict for.
  • continue Goes on with the next pass of the loop that runs it.
  • switch Runs the body of the first pattern that matches the string.
  • case The old form of switch -glob.
  • eval Joins its arguments as concat does and runs the result as a script.
  • uplevel Runs a script in the scope of a caller: 1 (the default) is the caller, and #0 is the top level.
  • apply Runs a lambda: a list of the arguments and a body, with an optional namespace.
  • time clock Runs the command count times (1 by default) and gives the mean time of one run in microseconds.
  • timerate clock Runs the command for a time (1,000 ms by default) and gives the time of one run, the count of runs, and the rate.

Procs and namespaces

  • proc Makes a command from a body of Tcl.
  • return Ends the proc and gives the value as its result.
  • tailcall Ends the proc and runs the command in its place, so that the stack does not grow.
  • rename Gives a command a new name.
  • namespace The commands for namespaces: groups of commands and variables with a name.
  • unknown The command that runs for a command name that does not exist.
  • coroutine Makes a command name and runs cmd until its first yield.
  • yield Stops the coroutine that runs it and gives the value to the caller.
  • yieldto Stops the coroutine and runs the command in the place of the caller.
  • coroinject Puts a command in a suspended coroutine.
  • coroprobe Runs a command now in a suspended coroutine, in the place where it waits, and gives its result.
  • tcl::unsupported::inject Puts a command in a suspended coroutine.
  • tcl::unsupported::corotype How a coroutine waits: yield or yieldto, or active while it runs.
  • walk A command of the runner of ztcl for its own tests.

Errors

  • error Gives an error with the message.
  • throw Gives an error with the error code type and the message.
  • catch Runs the script and gives its return code: 0 for a result, 1 for an error, 2 for return, 3 for break, and 4 for continue.
  • try Runs the body and then the first handler that matches its result.

Files and channels

  • chan channels The commands for channels: read, write, move, configure, and copy.
  • file file The commands for paths and files: names, tests, facts, and changes.
  • open channels Opens a file and gives a channel name.
  • close channels Writes what is left in the buffer and closes the channel.
  • gets channels Reads one line with no newline.
  • read channels Reads numChars characters, or all of the input to its end.
  • puts Writes the string and a newline.
  • flush channels Writes the buffer of the channel now.
  • eof channels 1 after a read reached the end of the input.
  • seek channels Moves the place of the next read or write.
  • tell channels The place of the next read or write, in bytes from the start.
  • fconfigure channels Gives or sets the options of a channel: -blocking, -buffering (full, line, or none), -buffersize, -encoding (utf-8, binary, ascii, unicode, or an encoding file of encoding dirs), -translation (auto, lf, crlf, or binary), and -eofchar.
  • fblocked channels 1 when the last read of a channel that does not block had no full line.
  • fcopy channels Copies from one channel to another.
  • source channels Runs the script in a file, and gives the result of its last command.
  • glob file The names of the files that match glob patterns.
  • cd file Changes the working folder, inside the root folder of the interpreter.
  • pwd file The working folder.
  • zipfs file The zip file systems under //zipfs:/.
  • socket socket Opens a TCP connection and gives a channel, or with -server makes a server that calls the command with a channel, an address, and a port for each new connection.

Events

  • after event With a script, runs it from the event loop after ms milliseconds and gives an id.
  • vwait event Runs the event loop until the variable is set.
  • update event Runs each event that is ready, and returns.
  • fileevent event Runs the script from the event loop when the channel is readable or writable.
  • tcl::Bgerror event The default handler of an error in a script that the event loop runs.

Interpreters and packages

  • interp interp Makes and runs child interpreters.
  • package Loads packages by name and version.
  • safe::interpCreate package The safe package 0.10 of the Tcl library (the Safe Base), which loads at the first call of one of its commands: a safe child with aliases into the parent for source, load, glob, encoding, exit, clock, and the file subcommands that read no file.
  • tclPkgUnknown package The handler of package unknown: sources the pkgIndex.tcl file of each folder of auto_path and of each folder in it, once.
  • tcl::tm::path package The module path of Tcl modules.
  • pkg_mkIndex package Writes the pkgIndex.tcl file of a folder, as Tcl does.
  • auto_mkindex package Writes the tclIndex file of a folder for auto_load, as Tcl does.
  • auto_load package Defines a command from auto_index, which the tclIndex files of auto_path and tclPkgSetup (the lazy pkgIndex.tcl form) fill.
  • history package The list of the commands of a session, as in Tcl: add, change, clear, event, info, keep, nextid, and redo.

Objects

  • oo::class Makes a class.
  • oo::define Changes the definition of a class.
  • oo::objdefine Changes the definition of one object, with the words of oo::define and class to change its class.
  • oo::copy Makes a new object with the class, the methods, and the variables of an object.
  • my In a method, calls a method of the same object, also one that is not exported.
  • self In a method, gives facts about the call: self or self object is the name of the object, self class the class of the method, self method the name of the method, and self next the next method of the chain.
  • next In a method, calls the method of the same name of the next class of the chain, such as the parent class, and gives its result.

Threads

  • thread thread The thread package: a thread is one interpreter that runs a script, with its own limits.
  • tsv thread Shared variables for threads: arrays that each thread of the process can read and change, with a lock for each command.
  • tpool thread Thread pools: a group of worker threads that run jobs.

The system

  • info Facts about the interpreter: its commands, procs, variables, and the call stack.
  • clock clock The time.
  • http package The http package 2.9.8 of the Tcl library, with package require http: an HTTP/1.1 client on the sockets of ztcl.
  • tcl::OptProc package The opt package 0.4.9 of the Tcl library, with package require opt: a proc whose words are checked against a description of flags and parameters.
  • platform::generic package The platform package 1.0.19 of the Tcl library, with package require platform: the system and the CPU as one identifier OS-CPU, such as linux-x86_64 or macosx-arm, from tcl_platform.
  • msgcat clock Message catalogs for text in more than one language, as the msgcat package 1.6.1 of Tcl.
  • exec exec Runs a program and gives its output.
  • pid exec The process id of the program, or of the processes of a pipeline.
  • exit Ends the program with the code (0 by default).

ztcl modules

  • ztcl::json JSON: parse to Tcl values, read one value with no full parse, check, and write with a schema.
  • ztcl::vt A terminal screen in memory: feed it the bytes of a program, and read its cells and its text.
  • ztcl::wasm Runs WebAssembly modules in the sandbox and the limits of the interpreter: decodes and validates a module, links its imports to Tcl commands, other instances, or WASI preview 1, and calls its exports with Tcl values.
  • ztcl::text Cuts a string into grapheme clusters, words, or sentences by the rules of Unicode 18.0.0 (UAX #29), and gives its display width in columns (UAX #11 and UTS #51).
  • ztcl::probe Records the values of a running script at a proc, a line, a command, a variable, or an error, with no change to the script, and gives the records back as dicts or JSON.
  • ztcl::tls socket A TLS 1.3 client: connects to host on port, runs the handshake, checks the certificate chain and the host name, and gives a channel.
  • ztcl::pty exec Runs a program in a pseudo terminal, for ztcl::vt and for tests of terminal apps.
  • ztcl::watch file Runs a script when a file or a folder changes.
  • ztcl::open launch Opens a URL or a file in the default app of the host.
  • ztcl::notify notify Shows a notification of the system.
  • ztcl::gc meter Gives the counts of the collector of the heap of the interpreter tree: the pauses, the time of the marks and the sweeps, the bytes of the heap, the bytes that the program allocated, and the resident set of the process.
  • ztcl::meter meter Counts the compute units, the time, the memory, and the I/O of threads and child interpreters, for a host that bills its customers.
  • ztcl::agent thread Runs an LLM agent loop in an isolated thread with no capability, which holds only the data and the tools that the host gives it.
  • ztcl::pdf Makes a PDF document: pages, text in embedded TrueType fonts, rectangles, lines, images, links, named places, the outline, and the document information.
  • ztcl::typeset Breaks paragraphs into lines with the total-fit algorithm of Knuth and Plass, hyphenates words with the patterns of Liang, measures text in TrueType fonts, and lays out Markdown into the pages of a PDF document.