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,697 of 117,927   
   Hans Bezemer to dxf   
   Re: portable or not? Volatile strings   
   24 Aug 24 13:23:29   
   
   From: the.beez.speaks@gmail.com   
      
   On 24-08-2024 04:58, dxf wrote:   
   > For the general case that's true.  OTOH 4tH is free to exploit what it has.   
   > The original ANS-Forth version tried using S" but it got complicated due   
   > to the dual-action word.  If standard compliance is the goal then options   
   > are limited.  OTOH a Gforth user not caring about compliance could exploit   
   > what he had and define things more succinctly:   
   >   
   >    : M"  \"-parse mem, ;   
   >   
   > (assuming he knew these words existed)   
      
   You're completely right (I assume because you've had some exposure to   
   4tH). There is no "ALLOT" in 4tH, because it has no dictionary. It has   
   segments for bytes, cells, words and constant strings.   
      
   Now *ONLY* 4tH "builtins" have access to the latter - and the segment   
   where the code resides is "read-only". What ," does is compile an "NOOP"   
   word with the address of the "string constant".   
      
   The "@C" word gets that address, copies the constant string to the   
   "bytes" segment and returns that address - which is accessible to the   
   programmer.   
      
   There is another way, which is to define words like:   
      
   OFFSET BRICK1   
      C"         "   
      C" ######  "   
      C"   ##    "   
      C"         "   
      
   Now "BRICK1" will hold the starting address in the "constant string"   
   segment. The "BRICK1" word will take any integer as an offset relative   
   to BRICK1, so "5 BRICK1" will return the ASCII value of the sixth   
   character after BRICK1.   
      
   Note C" has nothing to do with ANS-Forth C" and *only* allows for   
   printable characters to be inserted that way (sorry, no UTF-8). It does   
   *NOT* compile a terminator or count.   
      
   The thing is, however, you cannot add a "DOES>" definition to an "OFFSET".   
      
   Therefore the 4tH "CREATE" solution is the closest approximation you can   
   get in 4tH.   
      
   Hans Bezemer   
      
   --- 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