Personal computing discussed

Moderators: SecretSquirrel, just brew it!

 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 3:40 am

Every since I've heard about the Forth programming language, I wanted to try it out to see what is like compared to various forms of Basic I have used in the post.

Well I have some experience with Basic starting with Ti Basic I really never did much with it. However I'm thinking about getting back into and actually learning and using a programming language, and I'm considering checking out gForth which is in the Manjaro Repositories.

Any tips or pointers on getting started?
 
just brew it!
Gold subscriber
Administrator
Posts: 51182
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 6:21 am

IIRC I tried it very briefly back in the early '80s. It was moderately popular back then, since it is lightweight and can be used interactively from the command line like BASIC. I don't know anyone who uses it for real projects any more; unless you come across a legacy device that happens to use it, I'd say it is more of an academic curiosity these days.

If you've ever used an RPN calculator you'll feel right at home. It is stack-based, so the statement syntax is of the form <operands> <operation>.
Nostalgia isn't what it used to be.
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 6:30 am

just brew it! wrote:
IIRC I tried it very briefly back in the early '80s. It was moderately popular back then, since it is lightweight and can be used interactively from the command line like BASIC. I don't know anyone who uses it for real projects any more; unless you come across a legacy device that happens to use it, I'd say it is more of an academic curiosity these days.

If you've ever used an RPN calculator you'll feel right at home. It is stack-based, so the statement syntax is of the form <operands> <operation>.

Doesn't NASA still use Forth for some things? I thought it still had a niche in space and related projects.
 
just brew it!
Gold subscriber
Administrator
Posts: 51182
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 6:46 am

whm1974 wrote:
Doesn't NASA still use Forth for some things? I thought it still had a niche in space and related projects.

It's possible. If so, it is probably because they are still using hardware that was designed in the '70s, or software ported from such hardware.

I've never encountered it at any of my day jobs. Aerospace seems to be largely C and C++ these days.

There was a big push to use Ada (a language developed and standardized by the US Defense Department) for government/military/aerospace development around the time I graduated from college, but it never achieved the dominance in that sector that its proponents predicted. (Trivia: The Open Source VHDL simulator GHDL is written in Ada.)
Nostalgia isn't what it used to be.
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 7:00 am

I was checking the RISC-V guys again and notice that gForth and several kernels written in Forth are available. gForth is also available for x86 Linux and Windows, as well as ARM platforms such as the Raspberry Pi.

It would be nice to write portable code that can at least be compiled to common platforms without modification.
 
srg86
Gerbil Team Leader
Posts: 242
Joined: Tue Apr 25, 2006 7:57 am
Location: Madison, WI

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 7:22 am

I think the biggest user of Forth was OpenFirmware. That was used as the "BIOS" on various RISC based machines, including New World PowerPC Macs. I'm not sure who still uses it though, especially since Apple switched to Intel and EFI.

I'm also not sure how much of it was written in Forth, maybe just the Shell?
Intel Core i7 4790K, Z97, 16GB RAM, 128GB m4 SSD, 480GB M500 SSD, 500GB WD Vel, Intel HD4600, Corsair HX650, Fedora x64.
Thinkpad T460p, Intel Core i5 6440HQ, 8GB RAM, 512GB SSD, Intel HD 530 IGP, Fedora x64, Win 10 x64.
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 7:32 am

srg86 wrote:
I think the biggest user of Forth was OpenFirmware. That was used as the "BIOS" on various RISC based machines, including New World PowerPC Macs. I'm not sure who still uses it though, especially since Apple switched to Intel and EFI.

I'm also not sure how much of it was written in Forth, maybe just the Shell?

Of course this is getting way ahead of myself, but maybe write a full blown desktop UNIX-like OS in Forth?
 
just brew it!
Gold subscriber
Administrator
Posts: 51182
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 7:37 am

whm1974 wrote:
I was checking the RISC-V guys again and notice that gForth and several kernels written in Forth are available. gForth is also available for x86 Linux and Windows, as well as ARM platforms such as the Raspberry Pi.

It would be nice to write portable code that can at least be compiled to common platforms without modification.

The issue isn't so much the portability of the code; C/C++, Python, Java, and many other current languages are portable, in the sense that properly written code will run on many different platforms and architectures (the ones you listed above and many more) without source code modifications. The problem for real-world use is the portability of the APIs and libraries that allow you to talk to the underlying OS to get actual work done.

I have not looked at recent Forth implementations, but I would be willing to bet that it is no better (and probably worse) than other more popular languages in terms of the APIs it exposes and portability of the interfaces.

Just to give one example... is there a portable way to write multi-threaded code in Forth? (Not sure, I'm leaving this as an exercise for the reader.)
Nostalgia isn't what it used to be.
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 7:42 am

just brew it! wrote:
whm1974 wrote:
I was checking the RISC-V guys again and notice that gForth and several kernels written in Forth are available. gForth is also available for x86 Linux and Windows, as well as ARM platforms such as the Raspberry Pi.

It would be nice to write portable code that can at least be compiled to common platforms without modification.

The issue isn't so much the portability of the code; C/C++, Python, Java, and many other current languages are portable, in the sense that properly written code will run on many different platforms and architectures (the ones you listed above and many more) without source code modifications. The problem for real-world use is the portability of the APIs and libraries that allow you to talk to the underlying OS to get actual work done.

I have not looked at recent Forth implementations, but I would be willing to bet that it is no better (and probably worse) than other more popular languages in terms of the APIs it exposes and portability of the interfaces.

Just to give one example... is there a portable way to write multi-threaded code in Forth? (Not sure, I'm leaving this as an exercise for the reader.)

It would be very likely that I would be biting off more then I can chew. It is also likely that I will have to learn C/C++ and Assembly at the same time.
 
just brew it!
Gold subscriber
Administrator
Posts: 51182
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 7:57 am

Not sure why you think you'd need to learn assembly. In any case, that definitely would not be portable!
Nostalgia isn't what it used to be.
 
notfred
Maximum Gerbil
Posts: 4478
Joined: Tue Aug 10, 2004 10:10 am
Location: Ottawa, Canada

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 8:23 am

Only Forth I've done was Sun SPARC OpenBoot. I really don't like RPN.
 
just brew it!
Gold subscriber
Administrator
Posts: 51182
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 8:33 am

notfred wrote:
Only Forth I've done was Sun SPARC OpenBoot. I really don't like RPN.

Postfix notation can seem pretty alien if you never used an HP calculator back in the day. You'd probably hate the dc tool too. :lol: I find it occasionally useful in shell scripts when bash's built-in arithmetic capabilities are inadequate.
Nostalgia isn't what it used to be.
 
notfred
Maximum Gerbil
Posts: 4478
Joined: Tue Aug 10, 2004 10:10 am
Location: Ottawa, Canada

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 10:10 am

Hadn't come across dc before, I'll stick to bc.
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 11:25 am

just brew it! wrote:
Not sure why you think you'd need to learn assembly. In any case, that definitely would not be portable!

Wouldn't I need to write some part of the kernel in assembly for each platform if I was trying to write a portable OS?
 
just brew it!
Gold subscriber
Administrator
Posts: 51182
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 11:45 am

whm1974 wrote:
just brew it! wrote:
Not sure why you think you'd need to learn assembly. In any case, that definitely would not be portable!

Wouldn't I need to write some part of the kernel in assembly for each platform if I was trying to write a portable OS?

Ahh, thought you were replying to my multithread comment.

Yes you would need to know some assembly to write an OS kernel. You might be surprised how little assembly is in the Linux kernel though! It is nearly all C.
Nostalgia isn't what it used to be.
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 5:21 pm

just brew it! wrote:
whm1974 wrote:
just brew it! wrote:
Not sure why you think you'd need to learn assembly. In any case, that definitely would not be portable!

Wouldn't I need to write some part of the kernel in assembly for each platform if I was trying to write a portable OS?

Ahh, thought you were replying to my multithread comment.

Yes you would need to know some assembly to write an OS kernel. You might be surprised how little assembly is in the Linux kernel though! It is nearly all C.

I think the hardest part of learning Forth is having to learn RPN at the same time as well.
 
just brew it!
Gold subscriber
Administrator
Posts: 51182
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 5:45 pm

whm1974 wrote:
I think the hardest part of learning Forth is having to learn RPN at the same time as well.

It really helps to mentally visualize the stack used to store the operands and results. To evaluate an expression you need to enter it "inside out" and use the stack to control order of operations instead of parentheses.

It's actually more compact than standard algebraic notation since no parentheses are needed (they are implied). One of the reasons HP calculators were so popular back in the day was that once you were proficient with RPN you could do calculations faster than on a standard calculator (fewer keystrokes).
Nostalgia isn't what it used to be.
 
Vhalidictes
Gold subscriber
Gerbil Jedi
Posts: 1775
Joined: Fri Jan 07, 2005 2:32 pm
Location: Paragon City, RI

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 6:11 pm

Wow, Forth. On that note I'm pretty sure I still have a working Commodore 128. I didn't find that the compact code / keystroke savings was worth the additional mental effort, but my coding days are long done.
 
Cuhulin
Gold subscriber
Gerbil First Class
Posts: 159
Joined: Sun Mar 02, 2003 12:52 pm
Location: Meridian, Idaho

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 6:46 pm

Forth? Now there's a name I haven't heard in a long time.

I did some forth programming roughly 40 years ago and I hated it. The other comments are right in saying it was a lot like programming HP calculators, but one tended to do smaller projects on a calculator. Using RPN on larger projects just gave me headaches. That may be due to me being lazy, liking to code like I write - from front to end - but if you are comfortable with it, why not give the language a try?
For Work: Corsair One Pro, i7-7700, 16GB, GTX 1080, Samsung 49KS8000 and 2xAsus 27" 4K, 2 x Sonos Play 5

For Play: Ryzen 5, MSI B350M, 8GB, Radeon 580 and building....
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Tue Oct 31, 2017 10:38 pm

Thanks guys. I installed Gforth and now I need to find a manual or whatever to learn it. Any good books?
 
Pancake
Gerbil First Class
Posts: 147
Joined: Mon Sep 19, 2011 2:04 am

Re: Anyone use Forth, or have experience with it?

Wed Nov 01, 2017 1:11 am

Vhalidictes wrote:
Wow, Forth. On that note I'm pretty sure I still have a working Commodore 128. I didn't find that the compact code / keystroke savings was worth the additional mental effort, but my coding days are long done.


Sweet. I have a probably working frame grabber for a C128 but no longer a C128 to plug it into.
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Wed Nov 01, 2017 1:41 am

Pancake wrote:
Vhalidictes wrote:
Wow, Forth. On that note I'm pretty sure I still have a working Commodore 128. I didn't find that the compact code / keystroke savings was worth the additional mental effort, but my coding days are long done.


Sweet. I have a probably working frame grabber for a C128 but no longer a C128 to plug it into.

The two computers I know of that used Forth for an OS or environment, were the Canon Cat and the Jupiter ACE. If I remember right, the ACE only had 4K of ram when other 8-bit systems were starting to come with a full 64K by default. :roll:
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Wed Nov 01, 2017 11:18 pm

Well I found the manual for Gforth here:
http://www.complang.tuwien.ac.at/forth/ ... x.html#Top
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Thu Nov 02, 2017 10:23 am

Well it looks like quite a few games were written in Forth such as Starflight:
https://en.wikipedia.org/wiki/Starflight

Now I'm wondering if we could do modern game development in Forth and use the SDL and Vulkan APIs?
 
just brew it!
Gold subscriber
Administrator
Posts: 51182
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Anyone use Forth, or have experience with it?

Thu Nov 02, 2017 10:46 am

whm1974 wrote:
Well it looks like quite a few games were written in Forth such as Starflight:
https://en.wikipedia.org/wiki/Starflight

Now I'm wondering if we could do modern game development in Forth and use the SDL and Vulkan APIs?

Probably not without a lot of additional effort to write wrapper APIs that are compatible with Forth. And in the end performance would probably suffer relative to a native C++ implementation, since I imagine there would be some computational cost to convert the data structures back and forth in the wrapper layer.
Nostalgia isn't what it used to be.
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Thu Nov 02, 2017 11:21 am

just brew it! wrote:
whm1974 wrote:
Well it looks like quite a few games were written in Forth such as Starflight:
https://en.wikipedia.org/wiki/Starflight

Now I'm wondering if we could do modern game development in Forth and use the SDL and Vulkan APIs?

Probably not without a lot of additional effort to write wrapper APIs that are compatible with Forth. And in the end performance would probably suffer relative to a native C++ implementation, since I imagine there would be some computational cost to convert the data structures back and forth in the wrapper layer.

Yeah unfortunately you are probably right. I wonder if someone(s) who mastered Forth very well could implement SDL and Vulkan in native ANS Forth?
 
just brew it!
Gold subscriber
Administrator
Posts: 51182
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Anyone use Forth, or have experience with it?

Thu Nov 02, 2017 11:42 am

whm1974 wrote:
just brew it! wrote:
whm1974 wrote:
Well it looks like quite a few games were written in Forth such as Starflight:
https://en.wikipedia.org/wiki/Starflight

Now I'm wondering if we could do modern game development in Forth and use the SDL and Vulkan APIs?

Probably not without a lot of additional effort to write wrapper APIs that are compatible with Forth. And in the end performance would probably suffer relative to a native C++ implementation, since I imagine there would be some computational cost to convert the data structures back and forth in the wrapper layer.

Yeah unfortunately you are probably right. I wonder if someone(s) who mastered Forth very well could implement SDL and Vulkan in native ANS Forth?

I can't imagine there's any commercial demand for that, so it would have to be someone as crazy as you are, who also understands Forth, SDL, and Vulkan, and has enough time on their hands to be willing to tackle it as a hobby project. :lol:
Nostalgia isn't what it used to be.
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Thu Nov 02, 2017 12:54 pm

just brew it! wrote:
whm1974 wrote:
just brew it! wrote:
Probably not without a lot of additional effort to write wrapper APIs that are compatible with Forth. And in the end performance would probably suffer relative to a native C++ implementation, since I imagine there would be some computational cost to convert the data structures back and forth in the wrapper layer.

Yeah unfortunately you are probably right. I wonder if someone(s) who mastered Forth very well could implement SDL and Vulkan in native ANS Forth?

I can't imagine there's any commercial demand for that, so it would have to be someone as crazy as you are, who also understands Forth, SDL, and Vulkan, and has enough time on their hands to be willing to tackle it as a hobby project. :lol:

I think would have to master ANS Forth well enough to write my own implementation of ANS Forth with enhancements and extended along with finding other Forth Masters willing and crazy enough to work with me. The later could be the hardest part.

Oh well I do have plenty of time on my hands, at least I would pick up some useful skills along the way.
 
just brew it!
Gold subscriber
Administrator
Posts: 51182
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Anyone use Forth, or have experience with it?

Thu Nov 02, 2017 1:03 pm

whm1974 wrote:
Oh well I do have plenty of time on my hands, at least I would pick up some useful skills along the way.

They'd be even more useful if they didn't involve Forth. :wink:

Interviewee: ...and I wrote a wrapper library for the entire Vulkan API...
Interviewer: <looks at interviewee intently>
Interviewee: ...to support games written in Forth.
Interviewer: Forth? Isn't that one of those obsolete languages like Fortran? OK, this interview is over... we'll let you know. The receptionist will see you out.
Nostalgia isn't what it used to be.
 
whm1974
Gerbil Elder
Topic Author
Posts: 5761
Joined: Fri Dec 05, 2014 5:29 am

Re: Anyone use Forth, or have experience with it?

Thu Nov 02, 2017 1:13 pm

just brew it! wrote:
whm1974 wrote:
Oh well I do have plenty of time on my hands, at least I would pick up some useful skills along the way.

They'd be even more useful if they didn't involve Forth. :wink:

Interviewee: ...and I wrote a wrapper library for the entire Vulkan API...
Interviewer: <looks at interviewee intently>
Interviewee: ...to support games written in Forth.
Interviewer: Forth? Isn't that one of those obsolete languages like Fortran? OK, this interview is over... we'll let you know. The receptionist will see you out.

Interviewee: I modernized and extended ANS Forth with my own implementation to do modern code development up to and including writing Operating Systems.

Who is online

Users browsing this forum: No registered users and 1 guest