prelude: add an example for transform

main
magical 2023-12-19 04:49:17 +00:00
parent 3faf36c645
commit 89dcdeb553
1 changed files with 11 additions and 1 deletions

View File

@ -4,11 +4,15 @@ namespace import tcl::mathfunc::max
proc {#} args {}
# short aliases for common things
proc llen {lst} { return [llength $lst] }
proc slen {str} { return [string length $str] }
proc trim args { return [uplevel [concat string trim $args]] }
proc replace {str a b} { return [string map [list $a $b] $str] }
# sum and product
proc ladd {list} {
set t 0
foreach x $list { incr t $x }
@ -33,7 +37,13 @@ proc must_regexp args {
}
}
# transpose an array of strings
# transpose a list of strings
#
# % transpose {abc 123}
# a1 b2 c3
# % transpose a1 b2 c3
# abc 123
#
proc transpose strings {
set out {}
set C [slen [lindex $strings 0]]