Jump to content

Photo

Forth: A Brief Primer (#2)

forth primer tutorial

39 replies to this topic

#26 Willsy OFFLINE  

Willsy

    River Patroller

  • Topic Starter
  • 2,996 posts
  • Location:Uzbekistan (no, really!)

Posted Sun May 14, 2017 6:19 AM

TF should have said "ERROR: TOM. not found" - that would have helped you.

There's a bug in TF somewhere.

#27 Sinphaltimus OFFLINE  

Sinphaltimus

    Stargunner

  • 1,781 posts
  • Distracted at the Keyboard
  • Location:Poconos, PA

Posted Sun May 14, 2017 8:46 AM

You typed a word that does not exist in the dictionary: TOM.

 

What you intended was:  TOM .

 

...lee

 

 

I see - Spaces are gonna kill me.

Thanks.



#28 Willsy OFFLINE  

Willsy

    River Patroller

  • Topic Starter
  • 2,996 posts
  • Location:Uzbekistan (no, really!)

Posted Sun May 14, 2017 9:46 AM

No they won't. The space is really the only bit of syntax in Forth. It's what separates words, same as English. Unlike basic you don't need to learn which things need parenthesis or commas or semi-colons or colons. And if you don't like how a word works you can change it!

#29 mizapf OFFLINE  

mizapf

    River Patroller

  • 2,437 posts
  • Location:Germany

Posted Sun May 14, 2017 10:05 AM

I see - Spaces are gonna kill me.

Thanks.

 

Agoraphobia - the fear of (open) spaces: https://en.wikipedia...iki/Agoraphobia



#30 Willsy OFFLINE  

Willsy

    River Patroller

  • Topic Starter
  • 2,996 posts
  • Location:Uzbekistan (no, really!)

Posted Sun May 14, 2017 10:12 AM

^^^^^ 😊

#31 Sinphaltimus OFFLINE  

Sinphaltimus

    Stargunner

  • 1,781 posts
  • Distracted at the Keyboard
  • Location:Poconos, PA

Posted Sun May 14, 2017 12:19 PM

I have a bunch of questions specific to Turboforth so I'm going to ask here instead of going on a wild goose chase.

I need to learn the base system before I can move ahead with programs.

 

Am I to understand that a block is a disk file area where words get stored for multiple programs?

And using the  EDIT function allows me to see the currently loaded BLOCK?

 

I read notes on how to change the default block and manually load one you want. What about listing available blocks and seeing the contents?

Is it OK to assume that each new block contains no words except the default definitions that come with TF?

Or is the only thing available being the built in functions that define words?

How do I save programs? (Words) So that after a power cycle I can get back to TF with TOM Dick Harry And Dice-Roll still available?

Where can I find a list of all the syntax. For instance ! , . : ; etc...
Where can I find a list of words that come with TF (if any) and how can I see and view the functions of all words currently available (including ones I wrote etc..)? 

Am I to understand that a finished program will in essence become a word? 

Right now my biggest challenge is picturing all this in my head and not knowing how to see it on the screen, the stack, the words, the word definitions etc...
I'm wanting a way to visualize or see the stack so I can better understand everything that is going into it and how it changes when needed.

Am I to understand that TF only ever works from the top of the stack ever? That variables are the only things that need the stack to get reorganized (search the stack, move to top work from there)?

How big can the stack get and are there trimming functions to minimize the stack size? Which in turn I think will save ram.

How do I know how much ram I'm using?

 

So many more but that's it for now.

 

I know, I'm over thinking this. i can't help it. This is so strange.  Oh wait, is there a compiler for forth so that others can run forth created programs without forth?
What about forth programs to Cartridge? How does that work?



#32 Sinphaltimus OFFLINE  

Sinphaltimus

    Stargunner

  • 1,781 posts
  • Distracted at the Keyboard
  • Location:Poconos, PA

Posted Sun May 14, 2017 5:21 PM

I guess my real question is, where do I find the manual for Turbo Forth v1.2?



#33 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,234 posts
  • Location:Silver Run, Maryland

Posted Sun May 14, 2017 6:09 PM

Mark is probably answering you as I write, but the TurboForth manual is available on his website, http://turboforth.net.

 

...lee



#34 Willsy OFFLINE  

Willsy

    River Patroller

  • Topic Starter
  • 2,996 posts
  • Location:Uzbekistan (no, really!)

Posted Sun May 14, 2017 6:12 PM

Please start here for blocks info:

http://turboforth.ne...als/blocks.html

There is a *ton* of info on the TurboForth web site.

To find out how much memory you have type MEM on the command line. It displays three numbers:

1) amount of free memory in 8k expansion
2) amount of free memory in 24k expansion
3) total amount of free memory

To see all the words that TF has type WORDS

Also go to the language reference on the TF website. They are all documented.

That should keep you going for a while.

I'll try and post a YouTube video about blocks when I have a chance. In the meantime heres an old one I did back in 2011 with TF V1.0



#35 Willsy OFFLINE  

Willsy

    River Patroller

  • Topic Starter
  • 2,996 posts
  • Location:Uzbekistan (no, really!)

Posted Sun May 14, 2017 6:22 PM

Owen also does some block stuff in this video:



#36 Sinphaltimus OFFLINE  

Sinphaltimus

    Stargunner

  • 1,781 posts
  • Distracted at the Keyboard
  • Location:Poconos, PA

Posted Sun May 14, 2017 7:14 PM

Sweet, thanks!

#37 Sinphaltimus OFFLINE  

Sinphaltimus

    Stargunner

  • 1,781 posts
  • Distracted at the Keyboard
  • Location:Poconos, PA

Posted Mon May 15, 2017 4:45 AM

Just to put it out there, my interest is to see if i can rewrite my Zombi game in Forth and compare the final compiled version performance against what I currently have. I'm hopeful I can save a lot of ram AND get much better performance in TF. And since I'm using TidBit, the elimination of line numbers should make it easier to breakdown and convert. But I do define and use a lot of variables. So I'll be exploring ways to eliminate the need to do so. I've gotten side tracked from other projects so this week I'll allocate the proper time for each. TF will probably be limited to a few hours a week as I've started a self paced Computer Science course (non degree course) to learn other languages as well. First course is SQL. Something I've been meaning to learn for many years, then Java then C etc.. All while keeping the TI relevant and trying to get my side business off the ground while keeping my day job.. 


Edited by Sinphaltimus, Mon May 15, 2017 4:46 AM.


#38 Willsy OFFLINE  

Willsy

    River Patroller

  • Topic Starter
  • 2,996 posts
  • Location:Uzbekistan (no, really!)

Posted Mon May 15, 2017 4:48 AM

Post me a link to your zombie game. I'll take a look at it.

#39 Sinphaltimus OFFLINE  

Sinphaltimus

    Stargunner

  • 1,781 posts
  • Distracted at the Keyboard
  • Location:Poconos, PA

Posted Mon May 15, 2017 8:57 AM

Post me a link to your zombie game. I'll take a look at it.


http://atariage.com/...s/?fromsearch=1

There's also the "gotcha" in that I'm merging in compressed graphics from Wilhelm's tools. But I can probably return to pure code for that when the time comes.

#40 TheBF OFFLINE  

TheBF

    Chopper Commander

  • 249 posts
  • Location:The Great White North

Posted Mon May 15, 2017 6:28 PM

My 2 cents for Sinpahltimus is to get a text editor or word processor and try writing what the different parts of the game do in your own words.
Try not to think in basic, but chop the game up into the different sections of code that need to do specific stuff and say it in English.
 
The secret to good Forth programs is very well demonstrated by Willsy's Primer #3.
It takes some practice to stop thinking the way that BASIC forces us to think.
 
For example I re-did a version of the denile program the way I would do it and here is the main routine called RUN:

: RUN        ( -- )
             2 SCREEN
             CHANGE-CHARS
             CLEAR  .PYRAMID .STARS .MOON .RIVER
             HONK RESTORE-CHARSET 
             ;

2  SCREEN is CALL SCREEN(2). So you know I changed it to a night scene.
 
The Forth word '.' (dot) prints a number so some people put a DOT in front of words that put stuff on the screen.
Now you understand what this program does pretty much right away.  And it's because it was "factored" into small pieces.
 
Oh and I had to add the stars and a moon in a night scene. :-)

 
And the .RIVER word is actually a loop that does all the action with the water and star twinkling and exits if you hit a key.
It looks like this:

Hope this helps.

: .RIVER     ( -- )
             INIT-WAVES  
             BEGIN
               100 MS
               .WAVES
               3 TWINKLES
               KEY?
             UNTIL ;

Attached Files


Edited by TheBF, Mon May 15, 2017 6:42 PM.






Also tagged with one or more of these keywords: forth primer tutorial

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users