home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.forth      Forth programmers eat a lot of Bratwurst      117,927 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 116,866 of 117,927   
   albert@spenarnc.xs4all.nl to dxforth@gmail.com   
   Re: Reverse SCAN SPLIT   
   10 Oct 24 10:00:02   
   
   In article <5c65a8f1fdfc3e9937a825842fe23dc2758f48ef@i2pn2.org>,   
   dxf   wrote:   
   >Earlier I mentioned scanning in reverse.  Here's an implementation.   
   >   
   >[undefined] dxforth [if]   
   >: \CHAR ( a u -- a2 u2 c )  1- 2dup + c@ ;   
   >[then]   
   >   
   >\ As for SCAN but scan from end   
   >: SCAN< ( a u c -- a2 u2 | a 0 )   
   >  >r over swap begin dup while \char r@ = until 1+ then   
   >  rot drop rdrop ;   
      
   Compare that with the meticulously designed, exhaustedly specified   
   and eminently useful -- $/ -- .   
   After 40 years it has not taken over the world ...   
      
   NAME: $/   
      
   STACKEFFECT: sc c --- sc1 sc2   
      
   DESCRIPTION: []   
      
   Find the first c in the string constant sc and split it at that   
   address. Return the strings after and before c into sc1 and sc2   
   respectively. If the character is not present sc1 is a null string   
   (its address is zero) and sc2 is the original string. Both sc1 and sc2   
   may be empty strings (i.e. their count is zero), if c is the last or   
   first character in sc .   
   (sc is c-addr len )   
      
      
   The subtle difference between an empty string (a-add 0 ) and   
   a null-string ( 0 0 ) allows you to handle empty lines in a file   
   gracefully.   
      
      
   >   
   >\ As for SPLIT but scan from end. Latter string is topmost.   
   >: SPLIT< ( a u c -- a2 u2 a3 u3 )   
   >  >r 2dup r> scan< 2swap 2 pick /string ;   
      
   If you go for SPLIT< from end define SCAN< .   
   I have named it $\   
      
   Get the name of an executable from the source file:   
   "aap.frt" &. $\ 2DROP TYPE   
   aap OK   
      
   These words are elementary and should be defined in the core   
   in assembler, possibly (Intel) taking advantage of the string   
   words.   
      
   SSLAS0:   
           POP     AX      _C{ char}   
           POP     CX      _C{ count}   
           MOV     BX,CX   
           POP     DI      _C{ addr}   
           OR      DI,DI   _C{Clear zero flag.}   
           MOV     DX,DI   _C{ Copy}   
           CLD             _C{ INC DIRECTION}   
           REPNZ     SCASB   _C{ Compare BYTE}    <<<<<<<<<<<   
           JZ      SSLAS1   
      
      
      
   Groetjes Albert   
   --   
   Temu exploits Christians: (Disclaimer, only 10 apostles)   
   Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall   
   Art For Home, Office And Garden Decor - Perfect For Windows, Bars,   
   And Gifts For Friends Family And Colleagues.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca