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,559 of 117,927   
   Travis Bemann to Travis Bemann   
   Re: Lisp problem   
   21 Jun 24 00:30:54   
   
   From: tabemann@gmail.com   
      
   On 6/20/24 23:11, Travis Bemann wrote:   
   > On 6/4/24 05:53, albert@spenarnc.xs4all.nl wrote:   
   >> A glaring disadvantage of Forth against lisp, that the result   
   >> of lisp is ready to be reused. One hardly use this example as   
   >> an application, more of a component.   
   >> Forth just dumps the results on the screen.   
   >   
   > This sort of thing is part of why I created zeptoscript, a high-level,   
   > dynamic language built on top of zeptoforth.   
   >   
   > For instance, in zeptoscript, one can do:   
      
   Correction, I forgot a DROP:   
      
   zscript-list import   
      
   : split { string delimiter -- parts }   
      0 { parts }   
      begin   
        string delimiter 1 ['] = bind find-index if { index }   
          0 index string >slice duplicate parts cons to parts   
          index 1+ string >len over - string >slice to string   
          false   
        else   
          drop \ Forgotten word   
          string duplicate parts cons rev-list>cells   
          true   
        then   
      until   
      
      
   : add-gaps { parts -- parts-with-gaps }   
      parts >len { len }   
      len 0> if   
        len 1- 2 * 1+ make-cells { parts-with-gaps }   
        parts parts-with-gaps 1 [: { part index parts-with-gaps }   
          part index 2 * parts-with-gaps !+   
        ;] bind iteri   
        parts-with-gaps   
      else   
        0cells   
      then   
      
      
   : insert-bits { parts -- parts-with-bits }   
      parts >len { len }   
      len 0> if   
        parts add-gaps { parts-with-gaps }   
        s" 0" s" 1" { 0bit 1bit }   
        0 { variants }   
        1 len 1- lshift 0 ?do   
          parts-with-gaps duplicate { these-parts }   
          len 1- 0 ?do   
            j i rshift 1 and 0<> if 1bit else 0bit then   
            len 1- i - 2 * 1- these-parts !+   
          loop   
          these-parts variants cons to variants   
        loop   
        variants rev-list>cells   
      else   
        0cells   
      then   
      
      
   : variants-with-bits { string -- strings }   
      string [char] . split insert-bits [: 0bytes join ;] map   
      
      
   >   
   > With this you get:   
   >   
   > s" foo.bar.baz.quux" variants-with-bits [: type space ;] iter   
   > foo0bar0baz0quux foo0bar0baz1quux foo0bar1baz0quux foo0bar1baz1quux   
   > foo1bar0baz0quux foo1bar0baz1quux foo1bar1baz0quux foo1bar1baz1quux  ok   
   >   
   > (Without the line wrap, of course.)   
   >   
   > VARIANTS-WITH-BITS of course returns an array rather than a string, and   
   > can easily be fed into something other than [: TYPE SPACE ;] ITER   
   >   
   > This kind of thing is hard to do well in Forth, but with zeptoscript I   
   > get a high-level language which while having the flavor and syntax of   
   > Forth, enabling easily working with high level data structures (in this   
   > example I work with arrays, byte arrays, and lists, including nested ones).   
   Travis   
      
   --- 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