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,323 of 117,927   
   Anton Ertl to dxf   
   Re: VALUE - the good, the bad and the ug   
   20 Mar 24 07:47:34   
   
   From: anton@mips.complang.tuwien.ac.at   
      
   dxf  writes:   
   >On 20/03/2024 4:21 am, Anton Ertl wrote:   
   >> Unfortunately, Forth-79 standardized VARIABLE to create an   
   >> uninitialized variable, and later standards kept this mistake.  So now   
   >> I always have to write something like   
   >>   
   >> VARIABLE name n name !   
   >   
   >What do you do when your application restarts?  The values assigned at   
   >creation-time have likely changed.   
      
   I typically restart the application by restarting the Forth system and   
   reloading the application source.   
      
   For settings where the application is restarted without reloading it,   
   an approach like the Unix data segment might be a good way: Have the   
   data space for all the variables collected in a compact memory block,   
   and, upon restart, copy the initial value from a memory block of   
   initial values (possibly in Flash or on disk).  This has the following   
   advantages:   
      
   1) Better source code:   
      
    a) The initial value is obvious with the variable, and not somewhere   
       else.   
      
    b) The programmer cannot forget to (re-)initialize a variable.   
      
   2) More efficient in both space and time:   
      
    a) Instead of having an initializing word with lots of stuff like   
      
         5 v1 !   
         bl v2 c!   
      
       etc., only a MOVE or READFILE is needed, saving space; yes, you   
       need the memory block with the initial data, but you also need the   
       initial data in this initializing word, which will therefore be   
       longer than the initial data.   
      
    b) Block copy tends to be faster in modern CPUs than doing the same   
    thing with single-cell (or, worse, single-char) stores.   
      
   As a refinement of this approach, variables initialized to 0 can be   
   stored in another section that is just ERASEd, no need to keep the   
   initial value of these variables around and to copy them (in Unix this   
   is the bss segment).   
      
   Of course this approach would require a way for the Forth system to   
   know the initial values of variables.  Unfortunately, the convenient   
   way to do this by providing the initial value to VARIABLE has not been   
   standardized, and no other way has been standardized, either.  But for   
   VALUE, one can take this approach.   
      
   - anton   
   --   
   M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html   
   comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html   
        New standard: https://forth-standard.org/   
      EuroForth 2023: https://euro.theforth.net/2023   
      
   --- 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