In article ,   
   Hans Bezemer wrote:   
   >On 25-06-2025 09:21, Paul Rubin wrote:   
   >> Hans Bezemer writes:   
   >>> Fundamentally. I explained the sensation at the end   
   >>> of "Why Choose Forth". I've been able to tackle things I would never   
   >>> have been to tackle with a C mindset. ( https://youtu.be/MXKZPGzlx14 )   
   >>   
   >> I just watched this video and enjoyed it, but I don't understand how a C   
   >> mindset is different. In C you pass stuff as function parameters   
   >> instead of on the stack: what's the big deal? And particularly, the   
   >> video said nothing about the burning question of locals ;).   
   >>   
   >> It seems to me all the examples mentioned in the video (parsing CSV   
   >> files or floating point numerals) are what someone called   
   >> micro-problems. Today they much easier with languages like Python, and   
   >> back in Forth's heyday there was Lisp, which occupied a mindspace like   
   >> Python does now.   
   >>   
   >> I agree that Thinking Forth is a great book.   
   >   
   >It's hard to illustrate things with a multi-KLOC program IMHO. You can   
   >only illustrate principles by using examples that are "contained" in a way.   
   >   
   >But I'll try to illustrate a thing or two. Let's say you want to tackle   
   >a problem. And it doesn't go your way. You have to add this thing and   
   >that thing - and hold on to that value. You know what I mean.   
   >   
   >about to add. Take a look at getopt() - I think that's a good example.   
   >You can almost see how it grew almost organically by the authors hand.   
   >He never seemed to think "Hmm, maybe I'll make a separate function of it".   
      
   getopt is a design error in Forth filosofy. You are writing an interpreter   
   and Forth is the only interpreter, first commandment.   
      
    EXAMPLE:   
      
   : option? DROP C@ &- = ;   
   : handle-arg 1 ARG[] 2DUP option? IF handle-option ELSE handle-file THEN ;   
   : handle-args BEGIN ARGC 1 > WHILE handle-arg REPEAT intel-hex? ;   
      
   \ Execute help directly. We don't want any interference.   
   : -h help BYE ;   
      
   : -c arg-number DROP DECIMAL 1000 * frequency ! 1 multiple !   
    ARGC 1 <> ABORT" calculate requires 1 argument" ;   
      
   \ Note the `arg-number word is no good for multiple arguments.   
   : -m 1 ARG[] 2 <> ABORT" incorrect multiple args"   
    SHIFT-ARGS \ rid of -m   
    frequency DUP 4 CELLS + SWAP DO   
    0. 1 ARG[] >NUMBER 0<> 107 ?ERROR 2DROP   
    1000 * I ! SHIFT-ARGS   
    1 CELLS +LOOP 4 multiple !   
    ARGC 1 <> ABORT" multiple requires 4 arguments"   
      
      
   : main   
    defaults 0 multiple ! handle-args   
    multiple @ 0= IF ." specify -h, -c or -m " CR BYE THEN   
    init custom-action init-calibration-flash   
    doit   
      
   --   
   The Chinese government is satisfied with its military superiority over USA.   
   The next 5 year plan has as primary goal to advance life expectancy   
   over 80 years, like Western Europe.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|