prelude: add an example for transform
parent
3faf36c645
commit
89dcdeb553
12
prelude.tcl
12
prelude.tcl
|
@ -4,11 +4,15 @@ namespace import tcl::mathfunc::max
|
||||||
|
|
||||||
proc {#} args {}
|
proc {#} args {}
|
||||||
|
|
||||||
|
# short aliases for common things
|
||||||
|
|
||||||
proc llen {lst} { return [llength $lst] }
|
proc llen {lst} { return [llength $lst] }
|
||||||
proc slen {str} { return [string length $str] }
|
proc slen {str} { return [string length $str] }
|
||||||
proc trim args { return [uplevel [concat string trim $args]] }
|
proc trim args { return [uplevel [concat string trim $args]] }
|
||||||
proc replace {str a b} { return [string map [list $a $b] $str] }
|
proc replace {str a b} { return [string map [list $a $b] $str] }
|
||||||
|
|
||||||
|
# sum and product
|
||||||
|
|
||||||
proc ladd {list} {
|
proc ladd {list} {
|
||||||
set t 0
|
set t 0
|
||||||
foreach x $list { incr t $x }
|
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 {
|
proc transpose strings {
|
||||||
set out {}
|
set out {}
|
||||||
set C [slen [lindex $strings 0]]
|
set C [slen [lindex $strings 0]]
|
||||||
|
|
Loading…
Reference in New Issue