From: ruvim.pinka@gmail.com   
      
   On 2024-10-05 19:52, Anton Ertl wrote:   
   > Ruvim writes:   
      
   >> What advantages do you see in *using* the to-based setters?   
   >   
   > Over using SET-... words?   
      
   I've compared the use of a to-based setter ("to foo") versus a separate   
   setter ("set-foo") in programs. (NB: not creating them, but only using)   
   I do not see any advantage of "to foo" over "set-foo" at the *source   
   code* level.   
      
   And I asked about advantages in this context. Do you see any advantages   
   in using (i.e., not declaration/creation) at the source code level?   
      
      
      
   >   
   > 1) It's a popular and convenient mechanism.   
      
   Agreed. But this says about knowledge and tools, not about using already   
   defined setters in the source code.   
      
      
   >   
   > 2) I can find out the setter from looking at the central word:   
      
   A separate setter for a word "foo" can be checked using only standard   
   words as follows:   
      
    "set-foo" find-name .   
      
   >   
   > ``vf .hm   
   > \ output:   
   > opt: $7F43EB229B98   
   > to: $7F43EB229BE0   
   > extra: $7F43EB229B60   
   >> int: noop   
   >> comp: default-name>comp   
   >> string: named>string   
   >> link: named>link ok   
   >   
   > Ok, $7F43EB229BE0 is not very informative, but I can still make use of   
   > that:   
   >   
   > $7F43EB229BE0 xt-locate   
   > struct-val.fs:88   
   > ...   
   > cell ' aligned ' @ !a-table wrap+value: value: ( u1 "name" --   
   u2 ) \ gforth-experimental   
   > ...   
   >   
      
   [...]   
      
   >> For example, it could be a defining word "val" that is used as "val x"   
   >> and creates the getter "x" and the setter "set-x".   
   [...]   
   >> \ Let's redefine the setter "set-x"   
   >> : set-x ( u -- )   
   >> dup 10 u> abort" too big value for x"   
   >> set-x   
   >> ;   
   >>   
   >> t{ 4 set-x x -> 4 }t   
   >> t{ 11 ' set-x catch 2drop x -> 4 }t   
   >>   
   >>   
   >> Could you show how to implement that in Gforth when the to-based setter   
   >> "to x" is used?   
   >   
   > : to-x ( u xt -- )   
   > >r dup 10 u> abort" too big value for x" r> >body ! ;   
   >   
   > to-table: x-table to-x   
   > ' >body x-table to-class: x-to   
   > 0 value x   
   > ' x-to set-to   
   >   
   > 4 to x x . \ prints "4"   
   > 11 to x   
   >   
   > The last line produces the following error:   
   >   
   > *the terminal*:13:7: error: too big value for x   
   > 11 to >>>x<<<   
   >   
      
   Thank you! As I see it, this interface is quite cumbersome for the   
   specified problem, because it forces us to use two intermediate data   
   objects: "to-table" and "to-class".   
      
      
      
   >> NB: the solution must not change the original "x", it must redefine "x".   
   >> The difference is that the new definition *can* be in a different word   
   >> list, in which case both definitions (old and new) can be used depending   
   >> on the context.   
   >   
   > Let's see. To make it easier to see what is going on I use a   
   > different name for the redefined word.   
   >   
   > 0 value y   
   > synonym z y   
   > ' x-to set-to   
   >   
   > 4 to y   
   > z . \ prints 4   
   > 11 to y   
   > z . \ prints 11   
   > 11 to z \ aborts with "error: too big value for x"   
   >   
   > For a bounds-checking TO I find this requirement strange, however.   
      
   Yes, for a bounds-checking TO you probably will define checking at once,   
   or redefine the word at once in the same word list.   
      
   But in some other cases I need to have access to both old and new words,   
   so I wanted to see what a Gforth-specific solution for a to-based setter   
   looks like.   
      
      
      
   --   
   Ruvim   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|