Starting Forth Example

Oforth examples. Feel free to post your own code.

Re: Starting Forth Example

Postby Doug » 29 Aug 2018 11:32

Hi Franck,

Thanks again for the useful comments on my code.

I can see that I need to remember to use a HOF where appropriate. HOFs seem to be one of the most "different" , but interesting and powerful, techniques compared to classic Forth.

Regards,
-Doug
Doug
 
Posts: 23
Joined: 20 Jul 2018 14:26

Re: Starting Forth Example

Postby Franck » 29 Aug 2018 13:33

In fact, some HOFs (which means Higher Order Functions, ie functions that take other functions as parameter or as return value) exist in Forth.
For instance :
- EXECUTE (an HOF that executes the xt sent as parameter).
- FIND
- CATCH
- TRAVERSE-WORDLIST

And it is possible to create new HOF.

But what make HOF really powerfull (and Forth does not have them as built-in features) are collections (Arrays, ...).

Also, blocks (or quotations in Forth) are very usefull to use HOF efficienlty and to not pollute the dictionary.

Franck
Franck
 
Posts: 161
Joined: 29 Oct 2014 19:01

Re: Starting Forth Example

Postby Doug » 30 Aug 2018 13:48

Franck,

I have rewritten #read-file using your suggestions. Except I defined #mapm (returns a mutable array) and used that, which could be a factor of #map. No other part of the program needed to be changed. The rewritten #read-file is much better. Thank you!

-Doug
Doug
 
Posts: 23
Joined: 20 Jul 2018 14:26

Re: Starting Forth Example

Postby Franck » 30 Aug 2018 18:51

You're absolutely right.
I will add the factor #mapm to the mapping package for the next release.

Franck
Franck
 
Posts: 161
Joined: 29 Oct 2014 19:01

Re: Starting Forth Example

Postby Doug » 29 Sep 2018 04:07

I updated the No Weighting (with Franck's help) and File Away! programs using some of the new features in Oforth v1.2.
Franck has provided an easy way to replicate the CREATE / DOES> idiom of Forth and it is used in No Weighting.
#parse-until is excellent for getting input from the keyboard console and it is used to improve File Away!

Regards,
-Doug
Doug
 
Posts: 23
Joined: 20 Jul 2018 14:26

Previous

Return to Oforth examples

Who is online

Users browsing this forum: No registered users and 0 guests

cron