beetlebug▾
/

ztcl::code script

Runs a script one command at a time and prints the result of each command.

ztcl::code script TEXT

Description

Runs each command of TEXT at the global level, with the subcommands on the path of the global namespace, so grep x calls ztcl::code grep x. Prints the result of each command at once, unless the result is empty or the command sets a variable, defines a proc, prints, or is a loop or an if. An error stops the script. ztcl code runs its script with this subcommand.

Returns

An empty string.

Examples

Each example of this page runs after package require ztcl::code # A folder with three files, outside a git tree. set dir /tmp/ztcl-ref-code-[pid] file delete -force $dir file mkdir $dir cd $dir proc put {path text} { set ch [open $path w] puts -nonewline $ch $text close $ch } put a.zig "const std = @import(\"std\");\n\npub const Point = struct {\n x: i32,\n\n pub fn len(p: Point) i32 {\n return p.x;\n }\n};\n" put b.txt "one\ntwo\ntwo\n" put c.md "# Title\n\n## Part\n\ntext\n" # The tests use no model. set ::ztcl::code::backend {http ""} set ::ztcl::code::llm_url http://127.0.0.1:9/v1/chat/completions .

% ztcl::code script "set n 2\nshow b.txt \$n+1"
2	two

Errors

% ztcl::code script "set x \{"
the script has an open brace, quote, or bracket
-errorcode ZTCL CODE USAGE

Facts

Capability
file. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.2