is it Forth to discuss? - Page 1
Forum section: electronics / general

author: Vtile
author_rank: Super Contributor
timestamp: March 28, 2017, 01:22:49 pm
content: With quick searh I couldn't find anything forthwhile on this topic. Do someone still use Forth to program things. I wonder, the underlying concept and structure of forth is really tempting. It seems to be like gods gift to empedded programming (where it kind of did born).There seems to be a few compilers (for us who aren't cooking own) for ie. arduino.

author: borjam
author_rank: Unknown
timestamp: March 28, 2017, 01:51:16 pm
content: I used it many years ago, an awesome languageThe main reference you can find is the webpage of the now defunct Forth Interest Group (www.forth.org).

author: Vtile
author_rank: Super Contributor
timestamp: March 28, 2017, 02:30:49 pm
content: Yep, the 100% modularity of it is really tempting. I need to cut my teeth on it, I just need to find a programming cable for the arduino nano.Code:11= +2

author: rstofer
author_rank: Super Contributor
timestamp: March 28, 2017, 02:33:03 pm
content: I wouldn't consider Forth a blessing for embedded programming but, then, opinions vary. I'm not sure how to write an RTOS is Forth. Heck, I'm not even sure how to write an interrupt handler.What I do like about it is the ability to build programs from the bottom up. I think that's about the only way they can be built.MANY years ago ('80), I was visiting a disk drive manufacturer. They did all their testing in Forth because they could simply add a new test to lower level code already known to work. Literally, it was as simple as typing a single command string to create an entirely new test pattern.I'm pretty sure Forth is a dead issue. There are still pockets of folks using it, the same as there is with BASIC.

author: Vtile
author_rank: Super Contributor
timestamp: March 28, 2017, 02:39:36 pm
content: Quote from: rstofer on March 28, 2017, 02:33:03 pmWell as far as I understand it you do not need to write RTOS on Forth as it is already RTOS by nature. The interrupt handler might be interesting, but if it can be written on ASM it should be possible on Forth. Yes, I'm rookie what comes to "baremetal" programming (or any non-niche programming in general).

author: borjam
author_rank: Unknown
timestamp: March 28, 2017, 02:52:15 pm
content: Quote from: rstofer on March 28, 2017, 02:33:03 pmTimes have changed. Forth offered the possibility of running the whole development system in an 8 bit processor with some KB of RAM. Other approaches demanded a separate compiler and debugger, an ICE, etc.But still Forth has some advantages of its own depending on what you want to do. You program by extending the language instead of just writing functions. Many years ago I saw an awesome example on an issue of Dr Dobbs Journal. By extending the language it was possible for a non-programming engineer to write a program to operate some machinery.http://collaboration.cmc.ec.gc.ca/science/rpn/biblio/ddj/Website/articles/DDJ/1989/8902/8902e/8902e.htmRegarding the RTOS, it was quite easy to write a multitasking kernel in Forth. I wrote one for the HD6303 back in 1991. Again, it worked by extending the language, and I added a new type of function definition: a task.A task had an "initialization section" and a "task body". When the whole thing was compiled, everything was stored in memory so that it would be copied to an EPROM.During the boot process, the kernel created the process control blocks in RAM, and executed the "initialization section" of each of the processes, giving control to the "task body" which would be the main program for each task. It was a simple round robin approach, but I could have added priorities and real time constraints.The Forth system I used, which was a version of fig-Forth running on a TDS9092 board, included support to write interrupt routines in Forth. But of course in a 8 bit processor at 1 MHz it was better to write the interrupt handlers in assembly. I actually wrote small assembly language routines to catch interrupts that needed a timely service, and those handlers registered the event description together with a timestamp in an event queue, to be serviced by the higher level code with lesser time constraints.Nowadays you could do some of that work in Python running on a Raspberry Pi, with the same advantage of interactive debugging and testing, but back in 1990 that was unthinkable!And, unlike my friends at the university writing a multitasking kernel for an Intel 8031 in the classical way (assembly), I did not use an in circuit emulator. Just a serial terminal and a bunch of hex dumps after executing code blocks from the command line.QuoteWas it Maxtor? I think I saw them mentioned in a magazine.

author: borjam
author_rank: Unknown
timestamp: March 28, 2017, 02:54:02 pm
content: Quote from: Vtile on March 28, 2017, 02:39:36 pmNo, Forth was not a RTOS, although some Forth implementations included some kind of RTOS built in. But as I said the language gave you some nice facilities if you wished to implement your own multitasking or even RTOS on top of it.

author: eugenenine
author_rank: Frequent Contributor
timestamp: March 28, 2017, 03:01:21 pm
content: Been playing with flashforth a little myself, on the PIC.

author: Howardlong
author_rank: Super Contributor
timestamp: March 28, 2017, 03:02:41 pm
content: I got quite into Forth in the early 80s. I already had a fairly reasonable background in assembly language so it was an obvious way to go. The various BASIC based machines of the time were pretty slow, and in comparison Forth by its very nature encourages you to write your code in an efficient manner that can be easily and quickly be compiled or interpreted.When you first encounter it, it looks daunting, but it's really quick to get over the initial learning curve and become quite proficient. I did however find it incredibly difficult to teach to people without machine/assembly language experience.I remember writing a Breakout in an afternoon on a Jupiter Ace once as a demonstration as to what could be achieved in a short time frame. Some acquaintances of mine took Forth and altered it for use as a real time spacecraft OS which was still in use in the last decade. It ticks a lot of boxes for resource-constrained systems.

author: Vtile
author_rank: Super Contributor
timestamp: March 28, 2017, 03:08:01 pm
content: Interesting, really interesting.Quote from: borjam on March 28, 2017, 02:52:15 pm. ..But Raspberry Pi isn't embedded, but a PC with ARM processor!!

author: borjam
author_rank: Unknown
timestamp: March 28, 2017, 03:17:25 pm
content: Quote from: Vtile on March 28, 2017, 03:08:01 pmIt depends on how you use it!

author: Vtile
author_rank: Super Contributor
timestamp: March 28, 2017, 03:23:42 pm
content: Quote from: borjam on March 28, 2017, 03:17:25 pmBy running some linux derived general OS.The "once clear " line (note the scientific wording) between embedded and general computers have gone.

author: borjam
author_rank: Unknown
timestamp: March 28, 2017, 03:35:15 pm
content: Quote from: Vtile on March 28, 2017, 03:23:42 pmBy running some linux derived general OS.The "once clear " line (note the scientific wording) between embedded and general computers have gone.Well, it's kinda blurry. Would you say that QNX qualifies as an embedded OS? VxWorks?

author: Vtile
author_rank: Super Contributor
timestamp: March 28, 2017, 03:45:51 pm
content: Quote from: borjam on March 28, 2017, 03:35:15 pmWell, it's kinda blurry. Would you say that QNX qualifies as an embedded OS? VxWorks?Can you retype it to your device from design papers?

author: Gibson486
author_rank: Frequent Contributor
timestamp: March 28, 2017, 04:31:37 pm
content: I could see why you would like this if you coded in assembly and you only had 512 bytes of memory space....other than that, I do not see that as a gift to embedded programming. To each his own.

author: Vtile
author_rank: Super Contributor
timestamp: March 28, 2017, 04:42:12 pm
content: Quote from: Gibson486 on March 28, 2017, 04:31:37 pmWhy only then, if your system is not fully bloated IOT mini PC. what makes the Forth something comparable as a curse?

author: jnz
author_rank: Frequent Contributor
timestamp: March 28, 2017, 05:14:21 pm
content: Quote from: rstofer on March 28, 2017, 02:33:03 pm100% agree. Not only is forth dead, but unless you're familiar with it and the utterly stupid concept of "reverse polish notation" where 3 6 + is the command for 3+6 (small rant, WTF, you have all the right characters and demanded the wrong order? C was developed only a little after forth, one is CLEARLY superior). Basically, there are a few people using and recommending forth but no one seriously suggesting it get rolled into even low end ARM projects. IMO for embedded, the last nail in the coffin for forth was 32bit processors under $5.Quote from: Vtile on March 28, 2017, 02:39:36 pmThat's exactly right. Forth is platform independent assembly. That's all. It's directly dealing with the stack and managing that to get things done a single step at a time but seriously... Unless your entire program is written in ASM and you need bleeding edge speed or control over every single cycle, what is the point?To all those ideas of people using it as an interpreter - LOL - OK, look, if you can code in Forth to run some machine - you could have EASILY learned another language. To say, I can't code, but I can write in forth is to say, "nah, I can't take you to the mall, but I drive rally cars in competition".Quote from: Gibson486 on March 28, 2017, 04:31:37 pmExactly.On this forum it was suggested to me to run a forth interpreter instead of a domain specific language, but I would be the ONLY person I know in my life that could ever write those forth scripts, even the other programmers I know would stumble at that, it's just so obscure. I'm glad I found a lightweight javascript interpreter instead of spending even more than a day on forth.

author: Vtile
author_rank: Super Contributor
timestamp: March 28, 2017, 05:30:19 pm
content: Forth must be really good as it greates so much hatred in assumed C growd.Makes me even more tempted to start to fiddle with forth. Besides I actually feel that HPs RPN calculators are a gods gift for a mankind.My brain myst be NOT Wired.

author: joeqsmith
author_rank: Super Contributor
timestamp: March 28, 2017, 05:32:24 pm
content: I used Miller Microsystems Forth back in the early 80s with it's Turtle graphics. Borland's Turbo Pascal would run circles around it.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 28, 2017, 05:40:05 pm
content: Quote from: Vtile on March 28, 2017, 05:30:19 pmDefinitely worth a play. I did alot of FORTH in the 1980s and every now and again I get the urge to build a Jupiter Ace or equivalent... (maybe with a souped up display)...... however IMHO FORTH programs become a bit of a nightmare as they scale and with the advent of more powerful computers and the possibility of testing code on a host platform, emulation etc and C compilers that produce tight code the advantages of C meant I hung up my FORTH boots a while back.(I still have an RPN calculator to scare the kids)

author: Vtile
author_rank: Super Contributor
timestamp: March 28, 2017, 05:44:01 pm
content: Quote from: NivagSwerdna on March 28, 2017, 05:40:05 pmNice. The RPL is also so nice language as a bastard child of Lisp and Forth.

author: jnz
author_rank: Frequent Contributor
timestamp: March 28, 2017, 05:50:33 pm
content: Quote from: Vtile on March 28, 2017, 05:44:01 pmDon't take any offense to this... But are you trying to solve a problem? Or are you trying to be a code hipster?

author: Vtile
author_rank: Super Contributor
timestamp: March 28, 2017, 06:02:12 pm
content: Quote from: jnz on March 28, 2017, 05:50:33 pmHeh, No I don't have any problem in hand to solve. I'm also trying to avoid being a code hipster.I just find the basic concept of Forth really neat and fascinating, more so than C ( the one that is closest to the religion after ++ ), ObjPascal, (Visual)Basic(.net), ASM (the anticrist), Python etc. The bonus is that it doesn't have brackets, were they curly or not.

author: Vtile
author_rank: Super Contributor
timestamp: March 28, 2017, 08:09:43 pm
content: I think I start my journey of poking around with Forth and Arduino Nano that have have been garhering dust on my desk with AmForth.https://youtu.be/gFE6oK7jkq4?t=6m24sIt is just so, uh.

author: westfw
author_rank: Super Contributor
timestamp: March 29, 2017, 05:56:42 am
content: I find Forth sort-of nice if you want/need a semi-interactive thing with a parser.Being able to have appropriate action just HAPPEN when you type/send "<bunch of standard math/etc expression stuff> MYFUNC <with possible looping>", without having to deal with your own string handling, or parsing, or expression evaluation, can be great. If that's what you need to do.Other than that, Forth seems unpleasantly mired in 1970s-era language philosophy. And a particular subset of that philosophy where you didn't have cross-compilers or even cross-assemblers, and loading your code involved 30-minutes in a UV-eraser and 5 minutes in a separate device programmer, if you were lucky. So you needed to fit everything on your target system. And it's actually rather ugly. I mean, redefining the meaning of standard functions isn't "clever"; it's pretty close to "evil", and if the language allows it, that is NOT a 'feature' !

author: gmb42
author_rank: Frequent Contributor
timestamp: March 29, 2017, 11:53:59 am
content: For those interested in Forth on embedded systems jcw over atJeeLabshas made a series of posts on using Forth on his newJeeNode Zero.

author: Vtile
author_rank: Super Contributor
timestamp: March 29, 2017, 04:52:58 pm
content: ^^ Thanks. I'll look it up.Here is somesort of Forth Standard page. The official ISO standard is from 1997.http://forth-standard.org/

author: rstofer
author_rank: Super Contributor
timestamp: March 29, 2017, 05:56:19 pm
content: Quote from: westfw on March 29, 2017, 05:56:42 amThat sounds a lot like interactive BASIC with RPN.Other than that, Forth seems unpleasantly mired in 1970s-era language philosophy. And a particular subset of that philosophy where you didn't have cross-compilers or even cross-assemblers, and loading your code involved 30-minutes in a UV-eraser and 5 minutes in a separate device programmer, if you were lucky. So you needed to fit everything on your target system. And it's actually rather ugly. I mean, redefining the meaning of standard functions isn't "clever"; it's pretty close to "evil", and if the language allows it, that is NOT a 'feature' !Self-modifying code was fairly common in the '60s. I thought we tried to get away from that with the Harvard Architecture and the way GCC puts code and data in different segments and enforces access rights.I do like the idea of the inverted pyramid coding. Always building on things that were written before. In a way, I find it kind of elegant. But I don't think I'll spend any more time with it. I had enough of that when I was programming an HP48GX calculator. It wasn't Forth but it was pretty close.

author: Vtile
author_rank: Super Contributor
timestamp: March 29, 2017, 07:21:46 pm
content: I think I start to see some pitfals on Forth, but still it will be really interesting language / development environment in many cases.Definedly not a language for writing a graphical and windowed OS, but something that interacts or controls the environment and even more so in cases where you do not have a full understanding of it and you learn by doing. Also interesting aspect is the fact that the toolchain is on the device itself so you don't need to hunt down the proper OS and virtual machine 20 years from now, just plug in terminal and keep programming (in case of some real world long living devices).For me what makes it tempting also is that I can easily hack around the uC, which I'm not too familiar with or I don't have comp. science education/background which would restrict me to favor certain architecture or philosophy. The one similar feature of mentioned RPL programming is the ability to test around in normal environment and when working solution is found repeat the same command sequence between program delimers to use next time needed.Also one thing which puts me away on the ie. Arduino C -environment is the peripheral libraries it turns the development a really boring action of "filling the whitespace in worksheet with functions". I don't want to file a report to communicate with computer, I want to talk with it!Definedly not a solution for everything.

author: David Hess
author_rank: Super Contributor
timestamp: March 29, 2017, 07:34:53 pm
content: Open Firmwarefrom Sun Microsystems used Forth for processor independent device drivers among other things. Unfortunately the world moved to UEFI.

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: March 30, 2017, 04:57:16 pm
content: I recently decided I needed a small extension language for my microcontroller projects and decided to implement a Forth interpreter and compiler. I wrote it entirely in ARM assembly language for the Cortex-M parts and the whole thing is around a thousand lines of code. It's not as fast as compiled C, but I wanted it to be able to do quick and dirty things with an interactive command line. It fulfills that purpose quite well, but I wouldn't want to write anything larger than a few dozen lines in it as it starts to look like unreadable gobbledygook very quickly.After using it for a few months, I've rethought my decision and have decided to write a Scheme interpreter instead. Languages like Scheme seem to fit my way of thinking better than Forth does.As for the historical perspective, Forth's heyday (if it ever had one) was probably in the late 70s through the mid 80s. Open Firmware is probably the most well-known mainstream use of Forth. Other than that it's rarely used now, and most people who weren't around back then have never heard of it. It did have a reputation as a "hippy" language back in the day.

author: Vtile
author_rank: Super Contributor
timestamp: March 30, 2017, 06:06:55 pm
content: Quote from: Sal Ammoniac on March 30, 2017, 04:57:16 pmThank you for the insights.I needed to googe about scheme (Lisp) and found on the wiki: "Scheme Steering Committee calls it "the world's most unportable programming language""I read similar comment about early Forth implementations. (IIRC someone somewhere spoke similarly on the C compilers of the 80s with all sorts of partial implementations) It would be interesting to know what it status would be if it would have beeninventedhacked together in some "cool place" like Bell Labs or in MIT instead of beeing some hackjob of entrepreneur.

author: borjam
author_rank: Unknown
timestamp: March 31, 2017, 12:07:43 pm
content: I don't understand some angry reactions at it. Or yesI used it for several years and it did a great job. Back in the old days it had several advantages. Now, as some have pointed out, resources are not so scarce and you don't really need to run a complete development environment in a tiny processor.That said.There are several free versions in source form. The old fig-Forth implementations are available for several old processors, and Mitch Bradley, the main author of Open Firmware as far as I know, has a Forth implementation in C available on Github.https://github.com/MitchBradley/cforth

author: rstofer
author_rank: Super Contributor
timestamp: March 31, 2017, 03:10:06 pm
content: In the early years (prior to '80), I did a lot of work with one-off 8085 designs. First code to bring up was a simple Intel Monitor that would allow me to load other programs, read and write memory, etc. Low level stuff but easy to get running. Page 33 et seq here:http://www.retro.co.za/ccc/8080/SDK-80/MCS-80%20System%20Design%20Kit%20Users%20Guide.pdfThe second (and sometimes last) thing to bring up was Palo Alto Tiny Basic:https://en.wikipedia.org/wiki/Tiny_BASICThe advantage was the ability to write more complex diagnostics in a somewhat higher level language. The interpreter was ROM resident so only the application code needed to be downloaded. Later, PATB was modified to use the CP/M Operating System for file storage.FORTH came along about the same time and there were several incantations of full blown BASIC. FORTRAN came along as did C but the real programming environment came with UCSD Pascal. Real, serious, business programs were being written in Pascal right up until UCSD cancelled all the licenses.https://en.wikipedia.org/wiki/UCSD_Pascal

author: guenthert
author_rank: Frequent Contributor
timestamp: April 02, 2017, 04:09:14 pm
content: I still have a weak spot for FORTH. The simplicity is quite elegant, the inner interpreter seems 'discovered' rather than 'invented'. Creating a FORTH system (similar to Lisp, applications are typically delivered as 'whole world' system, i.e. one image containing user and system code) is easy - you can do it, give it a try (well, pick an early, small version, not ANS Forth). Unfortunately, it's so easy everyone who ever programmed in FORTH created their own system. While Lisp might not scale to projects with dozens of programmers, FORTH doesn't scale beyond teams with member count greater than one. Collaboration in FORTH typically means someone shares his/her code and someone elsere-implementsit with his/her improvements.It's great fun though, if you need to start from scratch. Perfectly suited for a 70's-80's retro computing project with a few KiB of RAM; otherwise just forget about it. It's a grand idea whose time has come and gone.

author: legacy
author_rank: Super Contributor
timestamp: April 03, 2017, 10:59:15 am
content: Quote from: guenthert on April 02, 2017, 04:09:14 pm

author: Vtile
author_rank: Super Contributor
timestamp: April 03, 2017, 07:59:07 pm
content: Quote from: guenthert on April 02, 2017, 04:09:14 pmNo.