Jump to content
IGNORED

Happy Holidays in FORTH!


Switch1995

Recommended Posts

My favorite Christmas movie is Trading Places and I love the 80s tech in the movie.   Using this picture of the Telerate monitors that were in the back of the Duke's limo and in Eddie Murphy/Dan Akroyd's office for inspiration, I put together a holiday program in Turboforth 40 column mode.  I'll attach the code.  To run in Classic99, just copy the text and paste in TF after selecting option 2.  Happy Holidays!!

 

 

 

 

 

image.png

Trading Places.txt

Edited by Switch1995
Added video
  • Like 5
  • Thanks 1
Link to comment
Share on other sites

Wow it's great to see someone else working with Forth. 

This was nicely factored. 

 

I have a question. Do you have a reason for not using  ."   to type text?

 

It would look like this

: news6 ( -- addr len )
0 15 GOTOXY
   ." NEWS - HAPPY HOLIDAYS TO ALL        " 
CR
CR ." THE 99ERS OUT THERE!                " 
CR
CR ." WISHING YOU AND YOURS A             " 
CR
CR ." PEACEFUL AND JOYOUS SEASON          " 
CR
;

 

In many Forth systems it compiles the same code as you wrote ( S" and TYPE)  but it looks a little cleaner. 

 

Link to comment
Share on other sites

8 hours ago, TheBF said:

 

I have a question. Do you have a reason for not using  ."   to type text?

I've just started learning FORTH this year and could be wrong, but it seems like using S" TYPE gives more flexibility than ."  and so I'm trying to get into the habit of "always" using it for strings.   For example:  

 

: test S" Hello World!"

;

 

test 2DUP TYPE TYPE

 

btw, In my top post, I neglected to thank @Willsy and @Lee Stewart for their fantastic FORTH products and, more importantly, taking the time to document and teach those that follow.

Edited by Switch1995
typo
  • Like 3
  • Thanks 2
Link to comment
Share on other sites

4 hours ago, Switch1995 said:

I've just started learning FORTH this year and could be wrong, but it seems like using S" TYPE gives more flexibility than ."  and so I'm trying to get into the habit of "always" using it for strings.   For example:  

 

: test S" Hello World!"

;

 

test 2DUP TYPE TYPE

 

btw, In my top post, I neglected to thank @Willsy and @Lee Stewart for their fantastic FORTH products and, more importantly, taking the time to document and teach those that follow.

Congratulations on jumping into this strange world. 

Lee and Willsy have done a superb job of documenting their systems.

(I have been focused on trying to learn compiler design stuff so my docs are bit stale compared to the current system) 

 

In Forth we are free to use words as we see fit. So there is nothing wrong with what you coded.

 

Since you are in a learning mode I will share some stuff I have learned over the years.

 

In BASIC we don't think about this much but there are string variables and also string "literals"

 

10 PRINT "Hello World!" 

creates a string literal in BASIC. 

 

Your definition of TEST above also creates a string literal with S" . 

In both examples it is assumed that you never want to change the string in a running program.

(of course you could change it with Forth but you might corrupt the dictionary if you try it) 

 

Here is a simple definition of ."  in  Forth 

 

: ."  (  ccc" -- )  [COMPILE] S"    COMPILE TYPE ; IMMEDIATE


You can see that it is actually just replacing the word ."  with S" and TYPE. :) 

 

I you want to explore string variables you can use Willsy's string library. It lets you do what BASIC can do with strings.

However in my experience after having made these kind of libraries myself, most of the time they are not needed.

A few much simpler words is all we need for normal programs.

I will post some options over on the Fun with Forth thread. 

 

image.thumb.png.508055d560f67ee1cb2682cfb47b938a.png

 

 

  • Like 2
  • Thanks 3
Link to comment
Share on other sites

13 hours ago, Switch1995 said:

I've just started learning FORTH this year and could be wrong, but it seems like using S" TYPE gives more flexibility than ."  and so I'm trying to get into the habit of "always" using it for strings.   For example:  

 

: test S" Hello World!"

;

 

test 2DUP TYPE TYPE

 

btw, In my top post, I neglected to thank @Willsy and @Lee Stewart for their fantastic FORTH products and, more importantly, taking the time to document and teach those that follow.

 

In fbForth, that would be

: TEST S" Hello World!" ;

TEST COUNT OVER OVER TYPE TYPE
\ or
TEST DUP COUNT TYPE COUNT TYPE

 

because fbForth does not have 2DUP and defines S" to leave the address of a counted string rather than the address of a string followed by its length as with TurboForth and CAMEL99Forth.

 

Of course, you could define TEST as

: TEST S" Hello World!" COUNT ;

and 2DUP as

: 2DUP OVER OVER ;

 

to duplicate your TurboForth results.

 

...lee

  • Like 3
Link to comment
Share on other sites

On 12/17/2023 at 7:25 PM, Switch1995 said:

My favorite Christmas movie is Trading Places and I love the 80s tech in the movie.   Using this picture of the Telerate monitors that were in the back of the Duke's limo and in Eddie Murphy/Dan Akroyd's office for inspiration, I put together a holiday program in Turboforth 40 column mode.  I'll attach the code.  To run in Classic99, just copy the text and paste in TF after selecting option 2.  Happy Holidays!!

I liked the movie as well, and you did a great recreation of the telerate monitors, i did something similar but for news and weather, with some graphics, like the old local TV cable channel, and all in X/Basic. nice to see you using forth. I posted it on twitter, so you might get a bunch of more viewers in this thread. Happy holidays.

  • Like 3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...