ztcl::code write
Makes or replaces a file.
ztcl::code write FILE TEXT
Description
Writes TEXT to FILE as UTF-8, and makes its folders.
Returns
FILE: new, N lines, or FILE: N lines, was M.
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 write sub/e.txt "x\ny\n"
sub/e.txt: new, 2 lines
% ztcl::code write b.txt "x"
b.txt: 1 line, was 3
Errors
% ztcl::code write b.txt
write FILE TEXT
-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