Posted to tcl by bairui at Thu Jul 19 08:45:41 GMT 2018view raw

  1. # clojure style thread macro
  2. # By default, threads at first argument, otherwise at @@ designations
  3. proc -> {var args} {
  4. set body {}
  5. foreach script $args {
  6. if {[regexp @@ $script]} {
  7. set pos @@
  8. } else {
  9. set pos { }
  10. }
  11. set script "\[$script\]"
  12. if {$body eq {}} {
  13. set body [regsub $pos $script $$var]
  14. } else {
  15. set body [regsub $pos $script " $body "]
  16. }
  17. }
  18. tailcall subst $body
  19. }
  20.  
  21. proc heredoc {doc} {
  22. # tailcall subst [join [lmap line [split [string trim $body] \n] {string trim $line}] \n]
  23. tailcall subst [-> doc {string trim @@} {split \n} {lmap line @@ {string trim $line}} {join \n}]
  24. }
  25.  
  26. proc usage {argv0 argv} {
  27. set usageError [heredoc {
  28. \ ERROR: [file tail ${argv0}]
  29. \ ?--auto-update?
  30. \ --rolback PIPTYPE PIPPACKAGE
  31. }]
  32. puts $usageError
  33. }
  34.  
  35. usage $argv0 $argv
  36.