Sign In/My Account | View Cart  
advertisement


Listen Print Discuss

Exegesis 7
by Damian Conway | Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13

Editor's note: this document is out of date and remains here for historic interest. See Synopsis 7 for the current design information.

Forbear, and eat no more.

As we saw earlier, a block overflow field ({VVVVVVVVV}) has the special property that it only overflows as much as necessary to fill the output lines generated by other block fields. That enabled us to create an overflowing column of text like so:


    print form
        :interleave, <<EOFORMAT,
            Name:
              {[[[[[[[[[[[[}
                              Biography:
            Status:             {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<}
              {[[[[[[[[[[[[}    {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
                                {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
            Comments:           {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
              {[[[[[[[[[[[}     {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
            EOFORMAT
        $name,
        $biography,
        $status,
        $comments;

without the first {VVVVVVVVV} field eating all the data out of $bio and leaving a large gap between the Status and the Comments.

That's a very handy feature, but restricting the "minimal height" feature to overflow fields turns out to be not good enough in the general case. For instance, suppose we had wanted the biography field to start at the first line of the output text:


    Name:             Biography:                            
      William           William Shakespeare was born on    
      Shakespeare       April 23, 1564 in Strathford-upon- 
                        Avon, England; he was third of     
    Status:             eight children from Father John    
      Deceased (1564    Shakespeare and Mother Mary Arden. 
      -1616)            Shakespeare began his education at 
                        the age of seven when he probably  
    Comments:           attended the Strathford grammar    
      Theories          school. The school provided        
      abound as to      Shakespeare with his formal        
      the true          education. The students chiefly    
      author of his     studied Latin rhetoric, logic, and 
      plays. The        literature. His knowledge and      
      prime             imagination may have come from his 
      alternative       reading of ancient authors and     
      candidates        poetry. In November 1582,          
      being Sir         Shakespeare received a license to  
      Francis           marry Anne Hathaway. At the time of
      Bacon,            their marriage, Shakespeare was 18 
      Christopher       years old and Anne was 26. They had
      Marlowe, or       three children, the oldest Susanna,
      Edward de         and twins- a boy, Hamneth, and a   
      Vere              girl, Judith. Before his death on
                        April 23 1616, William Shakespeare
                        had written thirty-seven plays. He
                        is generally considered the greatest
                        playwright the world has ever known
                        and has always been the world's most
                        popular author.

To do that, we would have required a call to form like this:


    print form
        :interleave, <<EOFORMAT,
            Name:             Biography:
              {[[[[[[[[[[[[}    {[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[}
                                {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
            Status:             {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
              {[[[[[[[[[[[[}    {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
                                {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
            Comments:           {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
              {[[[[[[[[[[[}     {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
            EOFORMAT
        $name,
        $biography,
        $status,
        $comments;

Note that the first line of the Biography field now has to be a block field, not a single-line field (as in previous versions). It can't be a single-line, because the Name field is a block field and that would leave a gap in the Biography column:


    Name:             Biography:                            
      William           William Shakespeare was born on    
      Shakespeare       
                        April 23, 1564 in Strathford-upon- 
    Status:             Avon, England; he was third of     
                        etc.

So it has to be a block field, to "keep up" with however much output the multi-line Name field produces. Unfortunately, starting the Biography column with a normal block field doesn't solve the problem either. In fact we get:


    Name:             Biography:                            
      William           William Shakespeare was born on    
      Shakespeare       April 23, 1564 in Strathford-upon- 
                        Avon, England; he was third of     
                        eight children from Father John    
                        Shakespeare and Mother Mary Arden. 
                        Shakespeare began his education at 
                        the age of seven when he probably  
                        attended the Strathford grammar    
                        school. The school provided        
                        Shakespeare with his formal        
                        education. The students chiefly    
                        studied Latin rhetoric, logic, and 
                        literature. His knowledge and      
                        imagination may have come from his 
                        reading of ancient authors and     
                        poetry. In November 1582,          
                        Shakespeare received a license to  
                        marry Anne Hathaway. At the time of
                        their marriage, Shakespeare was 18 
                        years old and Anne was 26. They had
                        three children, the oldest Susanna,
                        and twins- a boy, Hamneth, and a   
                        girl, Judith. Before his death on  
                        April 23 1616, William Shakespeare 
                        had written thirty-seven plays. He 
                        is generally considered the        
                        greatest playwright the world has  
                        ever known and has always been the 
                        world's most popular author.       
                                                           
    Status:                                                
      Deceased (1564                                       
      -1616)                                               
                                                           
    Comments:                                              
      Theories                                             
      abound as to                                         
      the true                                             
      author of his                                        
      plays. The                                           
      prime                                                
      alternative                                          
      candidates                                           
      being Sir                                            
      Francis                                              
      Bacon,                                               
      Christopher                                          
      Marlowe, or                                          
      Edward de                                            
      Vere

Normal block fields are remorseless in consuming all of their data. So the first Biography field absolutely will not stop formatting, ever, until your entire $biography string is gone.

What we really need here, is a kinder, gentler block field; a block field that formats minimally, like an overflow field. And we get that with yet another :height option: :height«minimal». Like so:


    print form
        :interleave, <<EOFORMAT,
            Name:             Biography:
              {[[[[[[[[[[[[}    {[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[}
                                {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
            Status:             {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
              {[[[[[[[[[[[[}    {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
                                {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
            Comments:           {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
              {[[[[[[[[[[[}     {VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV}
            EOFORMAT
         $name,
         :height«minimal», $biography,
         $status,
         $comments;

When this option is applied to a particular field (by placing it immediately before the field's data), that field only consumes as much of its data is is required to fill the output lines created by the other (non-minimal) fields in the same format. In this case, that means that the first Biography field only extracts as much data from $biography as is needed to fill the text lines created by the Name field.

Note that any kind of block field can be modified in this way: justified, numeric, currency, or verbatim.

Now is the jerkin under the line...

As some of the examples we've seen so far illustrate, formats frequently consist of a set of column titles, followed by the corresponding columns of data. And, typically, those column titles are underlined to make them stand out:


    print form 
      'Name              Bribe (per dastardry)',
      '=============     =====================',
      '{[[[[[[[[[[[}         {]],]]].[[[}     ',
      @names,                @bribes;

So form has an option that automates that process. For example, the payments example above could also have been written:


    print form 
      'Name              Bribe (per dastardry)',
      :under("="),
      '{[[[[[[[[[[[}         {]],]]].[[[}     ',
      @names,                @bribes;

The :under option takes a string and uses it to underline the most recently formatted line. It does this by examining the formats immediately before and after the :under. It then generates a series of underlines by repeating the specified underlining string as many times as required. The underlines are generated such that every field and every other non-whitespace literal in the preceding format has a underline under it and every field/non-whitespace in the next format has an "overline" above it.

For example, this call to form:


    print form
        '      Rank Name         Serial Number',
        :under("_"),
        '{]]]]]]]]} {[[[[[[[[[}     {IIIII}',
             @ranks,@names,          @nums;

prints:


          Rank Name         Serial Number
    __________ ___________  _____________
      Corporal Nym              CMXVII
    Lieutenant Bardolph          CCIV
       Captain Spurio           MMMCDX
       General Pompey             XI

The usual effect is that the auto-generated underlines always extend to the edges of both the preceding title and the following field, whichever is wider.

Many people, of course, prefer to draw the underlines themselves, as the results are then much easier to visualize when looking at the code. The :under option is most useful when we're constructing tables programmatically, with columns and column titles that are only known at run-time.

They come like sacrifices in their trim...

The default fill-with-spaces behaviour of fields is useful to preserve the vertical alignment of columns within a formatted text, but it could also potentially increase the size of form's output unnecessarily. For example, the following:


    print form 
        'To Do:',
        '   {[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[}',
            @todo;

might produce something like:


    To Do:
       Dissemble                                         
       Deceive                                           
       Dispute                                           
       Defy                                              
       Duel                                              
       Defeat                                            
       Dispatch                                          

That looks fine but, because each line is produced by the large left-justified field that is automatically filled with whitespace, the output contains several hundred more space characters than are strictly necessary (you probably didn't notice them, but they're all there – hanging off the right sides of the individual To-Do items).

Fortunately, however, form is smarter than that. Extraneous trailing whitespace on the right-hand side of any output line is automatically trimmed. So the above example actually produces:


    To Do:
       Dissemble
       Deceive
       Dispute
       Defy
       Duel
       Defeat
       Dispatch

Of course, if you really do need those "invisible" trailing whitespaces for some reason, form provides a way to keep them – the :untrimmed option:


    print form :untrimmed,
        'To Do:',
        '   {[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[}',
            @todo;

Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13

Next Pagearrow