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,060 of 117,927   
   Paul Rubin to dxf   
   Re: quotations   
   08 Feb 25 23:41:38   
   
   From: no.email@nospam.invalid   
      
   dxf  writes:   
   > quotations ... strike me as being wrong in every way, not least   
   > because they are intended to feature prominently, stuffed in one's   
   > face.  I don't understand the appeal at all.   
      
   I never got the impression they were supposed to be so prominent, though   
   I guess one could program in a style that uses them heavily.  My first   
   Forth program used a lot of XT's but in retrospect, it was rather   
   unidiomatic.   
      
   The following sort of follows an idiom for Python GUI programs.  You   
   have a function MAKE-BUTTON that puts a button on the screen.  The   
   button has a label, and it calls a function when you press it.  This   
   is using the notation from Anton's post but I haven't tested it.   
      
      : make-button ( a u xt -- ) ... ;   
          \ a u is the label, xt is the action   
      
   Now you want to draw buttons for a numeric keypad:   
      
      : make-action ( n -- xt ) [n:d ." You pressed " . ] ;   
      : make-label ( n -- a u )  \ make a string like "5" in the dictionary   
           here { a } 1 chars allot  '0' + a c! a 1 ;   
      
      : keypad ( -- ) 10 0 do   
                         i make-label i make-action make-button   
                      loop ;   
      
   Now there will be buttons labelled "0", "1", ... "9", and and when you   
   press one, it will print "you pressed 5" or whatever for that button.   
      
   I think the idiomatic old-school Forth alternative to this would be an   
   OOP-like approach, but the above is probably more concise, and to some   
   of us more intuitive.   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca