Posted to tcl by Stu at Sat Oct 10 13:40:44 GMT 2020view raw

  1. # Remove blank lines and comment lines, add space-backslash to all lines but the last.
  2. # Useful for making big lists in code without all the unpleasant backslashes.
  3. #
  4. proc backslashify {blob} { return [join [lmap l [split $blob \n] { if {[regexp {^[[:space:]]*(#.*)?$} $l]} { continue } else { set l } }] " \\\n"] }
  5.  
  6.  
  7. set l [eval list [backslashify {
  8. val
  9.  
  10. $var
  11. # comment
  12. [dict create a b c d]
  13. ...
  14. }]
  15.