Jump to content

DavidC

Members
  • Content Count

    288
  • Joined

  • Last visited

Posts posted by DavidC


  1. On 5/16/2020 at 9:47 AM, TheBF said:

     

     

     

     

    Exercises:

    1. Write a program (a Forth word) that waits for a KEY and prints "TRUE" if a '1' is pressed and "FALSE" if any other key is pressed. Call your program "ONE?"

    2. Write a program that  loops and prints "HELP!" continuosly UNTIL any key is pressed. Call your program "HELP"

    3. Write a program the loops and prints "PRESS Q" continously until "Q" is pressed. Call your program WAITFORQ.

    4. BONUS: Write a program that loops forever waiting for the ascii key you give it as a parameter. 

                    Call the program WAITFOR. Usage:  65 WAITFOR (waits for "A")

     

    Show your work here. :) 

     

     

    This is a great idea!  I will work on these and post my results. Kind of like a interactive tutorial/book exercise where folks can get feedback from the teachers. I will try to come up with some answers within the next few days. When I get some alone time.. :)  

    • Like 2

  2. On 5/16/2020 at 9:47 AM, TheBF said:

     

     

    So if you come BASIC where the system is protecting you from mis-steps at every turn, Forth feels like chaos.

    Forth like Assembler lets you shoot yourself in the foot, in the head or anywhere you point the gun. :) 

     

     

    This sums it up perfectly.

    • Like 1

  3. It gets confusing. Quickly.  The deeper I dig the more confused I get.  That says more about me than it does about Forth.  I sort of get it, and I have those moments where it all makes sense..but they are fleeting. I think about it in my sleep and it is gone in the morning.   It all made sense...and then I forget what I was thinking.   


  4. 2 hours ago, Lee Stewart said:

    Regarding leaving DO LOOP early, there are times you may want to leave the loop with other conditions to continue the program without aborting. Enter, LEAVE .

    : MYWORD  ( n -- )   \ Execute loop n times or until <Enter> hit
       ( n ) 0 DO
          <do loop things>
          ?KEY 13 = IF           \ <Enter> hit?
             <do other things>   \ yup
             LEAVE               \ this is the last time through loop
          THEN
       LOOP  ;

     

    ...lee

    I had to change it to ?KEY 14, because I imagine just like you said, it is so fast that I couldn't release the <enter> key quick enough when I typed MYWORD <enter>.   And..just out of pure coinicidence ?KEY 14 is <F5> on my laptop...ALMOST <F4> hahaha!!. 

    • Like 1

  5. All right!!  I spent about a hour this afternoon after work, pulling my hair out but I finally am getting somewhere.  What I finally figured out was.. : LOOPY BEGIN KEY? 1 AND WHILE ." HELLO WORLD"  REPEAT ;     ( using turboforth )       this prints HELLO WORLD forever and ever until I press a EVEN numbered key.   2, 4, 6 ect.  COOL!   It's a start!    @Lee Stewart   I will try out your example.    I didn't want to look at any posts on here today until I figured SOMETHING out on my own, mission accomplished!    

    • Like 2

  6. Before you can write your own subroutines, you have to know how. This means, to be practical, that you have written it before; which makes it difficult to get started. But give it a try.  Mr. Moore quote. 

    • Like 1

  7. Just now, GDMike said:

    Just back up your screens, as nothing is worse than losing a formula that wasn't easy to come up with.

    Paper and pen, old school.  I asked about that on stupid facebook page and yes.  Notebook full of notes.  Just in case..


  8. Alright!  Now we are getting somewhere.   Awesome.  When it isnt late and I ( aint drinkin ) have time to dig deeper.. yes!  Put this in a block, with whatever my foolish code is and it will break.  It is a start, thank you! We all gotta start somewhere.  

    Screenshot 2020-05-11 at 9.43.11 PM.png

    • Thanks 1

  9. 1 minute ago, TheBF said:

    Turbo Forth doesn't have the word ?terminal.  It is telling you that in error message.

     

    I think you make it though.

    : ?TERMINAL  KEY? 2 = ;

     

     

     

    Ahhh, yes. Yes. I can make the word a word.....I keep forgetting that.  ( plus I don't know what I am doing ).  

    • Like 2

  10. 32 minutes ago, TheBF said:

    I suppose it would be wrong to leave out just how configurable Forth is.

     

    You are free to make DO/LOOP yourself in a different way if you really want to dig into how the compiler is built.

     

    Or you could just add ?BREAK to the existing LOOP routine like this.

    (tested with FbForth) 

    COMPILE is used for ordinary (non-immediate) Forth words.

    [COMPILE] is used to "compile" IMMEDIATE words.

     

    Now when you use LOOP in a definition it will first COMPILE the address of ?BREAK followed by the address of LOOP ;

    In other words you have changed the compiler!

     

    You could do the same thing with AGAIN, UNTIL and REPEAT.  If you made a block with these words in it, you could load it first for testing programs. Then all you loops would be "breakable".

    Then re-compile without the breakable loops and run at full speed.

    \ breakable loop
    
    : ?BREAK   ?TERMINAL ABORT" *BREAK*" ;
    
    : LOOP     COMPILE ?BREAK  [COMPILE] LOOP ;  IMMEDIATE 
    
    \ test it
    : STAR     42 EMIT ;
    : STARS ( n -- ) 0 DO  STAR  LOOP ;
    
    20000 STARS ( hit fctn 4 when you get tired of it)

     

    Note:For ANS Forth like CAMEL99 Forth change LOOP to:

    : LOOP    POSTPONE ?BREAK  POSTPONE LOOP ;  IMMEDIATE 

     

    So.....all that must be in a block?    Not immediate mode?  


  11. Questions about Forth and the f4 key on console or classic99..when I make a loop, you know..loop..how do I break the loop?  Does it have to be part of the WORD or is it stuck in forever loop until I shut the computer off?     Is there a f4 break key on a loop?    A simple : TEST DO ." HELLO " LOOP ;   it goes forever...how to stop it?


  12. Words are powerful tools.  Even more powerful when misused.   

     

    A harsh lesson, one that will be with you forever.  I cant say I never "f*cked up" when dealing with customers, In my business I deal with all kinds all day. I deal with the upper brass as well, my suppliers and sometime I say the wrong thing at the wrong time.   Sometimes...who am I kidding, all the time.. but...after 40 years, they know me.  Thats just Dave..lol.    But, it still happens, it is human nature to speak your mind.    consider it as..   Lesson learned. 


  13. My FG arrived today, and I am blown away by the amount of stuff on the pre-loaded card.  (Which I believe is downloadable from whtech) It has just about EVERYTHING!!  So cool.   RXB, XB 2.6, The different flavors of Fourth...the list goes on and on...THIS IS AWESOME!!!

    • Like 1

  14. 2 hours ago, BillO said:

    Cool.  It will be interesting to see what this machine can really do.  The basic unit is almost useless, yet very easy on the eye (I'm a gearhead).  I don't know what TI were thinking with their base BASIC and the limited RAM.  I guess it was meant to be a teaser so you'd part with more money to get the stuff needed to make it useful.

    With the CF7 and the FinalGrom you will be surprised at what this machine can do.  Especially with the geniuses on this forum.  It truly is amazing.   

×
×
  • Create New...