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 117,611 of 117,927   
   Krishna Myneni to okflo@teletyp.ist   
   Re: Examples for gforth's objects.fs   
   03 Oct 25 20:21:32   
   
   From: krishna.myneni@ccreweb.org   
      
   On 10/3/25 9:44 AM, okflo@teletyp.ist wrote:   
   > Hi,   
   >   
   > I am currently trying to digg deeper into gforth's object.fs.   
   >   
   > For that I would like to read some good object oriented forth code   
   > (preferred gforth's object.fs, but open to other good examples).   
   >   
   > Any recommendations of f.e. a bigger project, thas has public code?   
   >   
   > many thanks - okflo   
      
   Here, you will find an example of object-oriented code in Forth, written   
   for Bernd Paysan's mini-oof.4th.   
      
   https://github.com/mynenik/kForth-64/blob/master/forth-src/qm/epr-sim.4th   
      
   Some definitions of classes and inheritance are shown below --  I expect   
   these may be easily translatable to the object.fs declarations.   
      
   Cheers,   
   Krishna   
      
   --   
      
   \  Quantum Two-Particle State class and its methods   
      
   object class   
        complex var C1  \ amplitude of |11> component   
        complex var C2  \ amplitude of |10> component   
        complex var C3  \    "         |01> component   
        complex var C4  \    "         |00> component   
        method init-2p2s ( o -- ) ( F: z1 z2 z3 z4 -- )   
        method normalize ( o -- )   
        method exchange  ( o -- )  \ exchange particle labels   
        method P_up      ( o -- ) ( F: stheta ctheta -- P_up )   
        method M_up      ( o -- ) ( F: stheta ctheta -- C1' C2' C3' C4' )   
        method M_down    ( o -- ) ( F: stheta ctheta -- C1' C2' C3' C4' )   
   end-class Q2p2s  \ two-particle, bipartite quantum state   
      
      
   \  Text Graphic class and its methods   
      
   object class   
     2 cells var topLeft   \ col row   
     2 cells var dims      \ columns rows   
     2 cells var colors    \ foreground and background colors   
     4 cells var auxColors \ auxiliary colors   
        method init          ( ... o -- )   
        method get-height    ( o -- w )   
        method get-width     ( o -- h )   
        method set-fb-colors ( o -- )   
        method fill-area     ( color o -- )   
        method clear-area    ( o -- )   
        method draw          ( ... o -- )   
   end-class text-graphic   
      
   \  Three-angle selector widget class   
      
   text-graphic class   
       cell var pos         \ selector position   
     3 dfloats var theta[   \ angles (for pos=1 to 3)   
     3 dfloats var ctheta[  \ cos(theta_i)   
     3 dfloats var stheta[  \ sin(theta_i)   
       method assign-angles ( o -- ) ( F: deg1 deg2 deg3 -- )   
       method get-current-angle ( o -- ) ( F: -- deg )   
       method get-sincos    ( o -- ) ( F: sintheta costheta )   
   end-class selector3A   
      
      
   \  Two-light indicator widget class   
      
   text-graphic class   
       cell  var stateBits  \ bits 0 and 1 indicate status for each light   
       method set-lights  ( bits o -- )   
   end-class indicator2L   
      
   --- 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