From: do-not-use@swldwa.uk   
      
   On 29/04/2024 17:22, Paul Rubin wrote:   
   > dxf writes:   
   >> For reasons one can only speculate Forth Standards have by and large ignored   
   >> numeric string output.   
   >   
   > There is the <# ... #> machinery. Does that count?   
      
   It's a nice idea but the restrictions around it and the specified   
   implementation render it unsuitable for building upon it if you want to   
   write portable software. Faults with it are:   
      
   - the pictured output buffer (POB) may be transient, can be corrupted by   
    the system e.g. being moved or overwritten   
   - POB contents are built up from right to left, making concatenation   
    user hostile   
   - only one buffer available to the programmer   
   - cannot set POB size   
   - buffers not nestable   
   - POB contents can only be accessed by #> which terminates things   
   - system words such as .S may use the POB, thus hindering debugging   
   - the system need not check the POB for overflow   
      
   Some of these can be improved in a Forth system but software using the   
   improvements may not be portable between systems.   
      
   I've written my own version of <# etc, with the '#' replaced by '~',   
   that does not have the above problems. It has:   
      
   new-buffer ( "name" xt ca u ~buf-size -- ) create a new format buffer   
   <~ ( -- ) open a format buffer   
   ~> ( -- ca u ) get contents of the current buffer, can be added to (has   
    synonym ~@   
   ~><~ ( -- ca u ) get contents of buffer, close it and open another   
   ~hold ( ch -- ) with synonym ~c+   
   ~holds ( ca u -- ) with synonym ~+   
   ~fill ( n ch -- )   
      
   ~w ( n -- ) set a field width   
   ~r ( +n -- ) set field width and right justify next conversion   
   ~l ( -n -- ) set field width and left justify next conversion   
   ~uc ( -- ) set upper case   
   ~lc ( -- ) set lower case   
   ~d ( d -- ) convert signed double integer   
   ~i ( n -- ) convert signed integer   
   ~ud ( ud ) convert unsigned double integer   
   ~ui ( u -- ) convert unsigned integer   
   ~s ( ca u -- ) hold string subject to any justification etc   
   ~c ( ch -- ) hold character subject to any justification etc   
      
   I've used these as primitives for integer sprintf implementations   
   intending (when I get time and interest) to extend it to a floating   
   point sprintf   
      
   --   
   Gerry   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|