Version 4 of Paragraphing

Updated 2003-11-18 12:14:54

if 0 {Richard Suchenwirth 2003-11-18 - By "paragraphing" I understand assigning blocks of code ("paragraphs", as in PL/1) to a variable, and building up the control flow by referencing these paragraphs, which replaces long open brace ... close brace blocks with a single "word". Simple example (find the length of the longest string from a list):}

 proc maxlen args {
     set singleList       {[llength $args]==1}
     set expandSingleList {set args [lindex $args 0]}

     if $singleList $expandSingleList

     set res [string length [lindex $args 0]]
     set findLongest {
         set l2 [string length $i]
         if {$l2 > $res} {set res $l2}
     }
     foreach i [lrange $args 1 end] $findLongest
     set res
 }

if 0 {Note that "paragraphs" have to be defined before they are used, so a top-down style is not so easily achieved. An advantage is that the variable names for paragraphs can contribute further to "self-documenting code", with a slightly stronger commitment than pure comments thrown in.

Like so often, I'm not sure how useful this is, but it certainly is not possible in C (well, one could, with preprocessor macros) or a number of other languages...


TV At least it doesn't clutter your function name space...


Arts and crafts of Tcl-Tk programming }