set website https://world-playground-deceit.net/ set location Hérault, France set email [email protected]
Welcome to my wiki page, where I present some of my Tcl stuff and thoughts.
My miscellaneous Tcl utilities are here and they contain:
% proc* p {-flag {-opt foo} x args} {
puts [lmap v {flag opt x args} {string cat "$v=[set $v]"}]
}
% p 1 a
flag=0 opt=foo x=1 args=a
% p -opt bar -flag 1 a
flag=1 opt=bar x=1 args=a
% p -flag
flag=0 opt=foo x=-flag args=
% # Relatively constrained overhead
% proc p1 {x} {}
% proc* p2 {-flag {-opt foo} x} {}
% timerate {p1 1}
0.127049 µs/# 7870986 # 7870986 #/sec 1000.000 net-ms
% timerate {p2 1}
0.794317 µs/# 1258943 # 1258943 #/sec 1000.000 net-ms% atexit push {puts "hello world"}
% atexit push {puts [clock format [clock seconds]]}
% atexit push {global env; puts "env: $env(HOME)"}
% atexit pop {puts "hello world"}
% exit
Wed Jul 14 14:27:58 CEST 2021
env: /home/user% set v {1 2}
% eval [quasiquote {
set w {3 4}
eval [quasiquote {
puts "`$v `@$v `[list {*}$v 3]` `@[list {*}$v 3]`"
puts "``$w ``@$w ``[list {*}$w 5]`` ``@[list {*}$w 5]``"
}]
}]
{1 2} 1 2 {1 2 3} 1 2 3
{3 4} 3 4 {3 4 5} 3 4 5
% puts [format_paragraph {**Lorem __ipsum__ dolor** sit --amet--, consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum} indent 4 width 70]
Lorem ipsum dolor sitamet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
% set argv {-opt1 -opt2 foobar myarg}
% set argc 4
% set opts [autocli \
{opt1 {flag "Opt1 description"} opt2 {param default PARAM_NAME "Opt2 description"}} \
"Program name" \
"Short description" \
{{SYNOPSIS1_ARG1 [SYNOPSIS1_ARG2...]} {SYNOPSIS2_ARG1 SYNOPSIS2_ARG2}} \
{"Long description as a list of indented and formatted paragraphs"
" with some **markup**"}]
opt1 1 opt2 foobar
% set argv
foobar
% usage stdout
NAME
Program name - Short description
SYNOPSIS
Program name [OPTION]... SYNOPSIS1_ARG1 [SYNOPSIS1_ARG2...]
Program name [OPTION]... SYNOPSIS2_ARG1 SYNOPSIS2_ARG2
DESCRIPTION
Long description as a list of indented and formatted paragraphs
with some markup
OPTIONS
-opt1
Opt1 description
-opt2 PARAM_NAME
Opt2 description
Defaults to "default".
-help
Print this help message and exit.
# List all mountable hotplugged disks/partitions
% exec lsblk -nproNAME,TYPE,HOTPLUG,FSTYPE,MOUNTPOINT | awk {$2 ~ /^(part|disk)$/ && $3 == 1 && NF == 4 {print $1}}
/dev/sdd1
/dev/sde
/dev/sde2
/dev/sde1
% parse [exec lsblk -nproNAME,TYPE,HOTPLUG,FSTYPE,MOUNTPOINT] {
{[~ {^(part|disk)$} $1] && $2 == 1 && $NF == 4} {
lappend ret $0
}
END {return $ret}
}
/dev/sdd1 /dev/sde /dev/sde2 /dev/sde1% wjson::write stdout \
[wjson::object \
[dict create \
foo [wjson::string {\bar"}] \
num [wjson::number 123] \
arr [wjson::array \
[list \
[wjson::bool 1] \
[wjson::bool 0] \
[wjson::null]]]]]
{
"foo": "\\bar\"",
"num": 123,
"arr": [
true,
false,
null
]
}along with a lot of small but useful stuff (functional, metric/binary unit conversion, terminal emulator formatting, Lispy stuff, dict and list additions, etc...).
Some Tcl based projects:
Other stuff in separate Wiki pages:
Here are my current thoughts about Tcl itself: https://world-playground-deceit.net/blog/2024/why_tcl.html
And some other, more specific "problems" I identified during my Tcl journey:
Note: mostly inactive as a serious Tcl programmer since I became infatuated with CL; still using it as a scripting language for its superior string handling, nice dictionary API or event loop.