Posted to tcl by bairui at Thu Jul 19 08:45:41 GMT 2018view raw
- # clojure style thread macro
- # By default, threads at first argument, otherwise at @@ designations
- proc -> {var args} {
- set body {}
- foreach script $args {
- if {[regexp @@ $script]} {
- set pos @@
- } else {
- set pos { }
- }
- set script "\[$script\]"
- if {$body eq {}} {
- set body [regsub $pos $script $$var]
- } else {
- set body [regsub $pos $script " $body "]
- }
- }
- tailcall subst $body
- }
- proc heredoc {doc} {
- # tailcall subst [join [lmap line [split [string trim $body] \n] {string trim $line}] \n]
- tailcall subst [-> doc {string trim @@} {split \n} {lmap line @@ {string trim $line}} {join \n}]
- }
- proc usage {argv0 argv} {
- set usageError [heredoc {
- \ ERROR: [file tail ${argv0}]
- \ ?--auto-update?
- \ --rolback PIPTYPE PIPPACKAGE
- }]
- puts $usageError
- }
- usage $argv0 $argv