Shop OBEX P1 Docs P2 Docs Learn Events
Why Forth? — Parallax Forums

Why Forth?

JonnyMacJonnyMac Posts: 9,108
edited 2012-08-17 14:14 in Propeller 1
I have always enjoyed computer languages -- though that hasn't caused me to learn a bunch of them (I enjoy paintings, too, but I don't paint). I see some incredibly bright individuals promoting Forth for the Propeller and I wonder why. Sincerely. Should I learn it? It seems intriguing and if these bright people are using it, there must be good reasons. I visit the computer book section at B&N every time I go in and I don't remember seeing any books on Forth. If I decided to learn, where do I turn for guidance?
«13

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-08-09 08:55
    Where do you turn to for guidance? Don't you know you have already lost your way! :)
    Take a look at my Intro web page which is really meant for someone who has loaded Tachyon onto their system. Think of it as an interactive introduction.
    There are links at the bottom of the page for resources but Forth is not C, well what I mean is not the language of choice so books will be hard to find. For an MCU environment I couldn't wish for anything better (really).
  • Heater.Heater. Posts: 21,230
    edited 2012-08-09 09:02
    There was a printed book on Forth back in the early eighties or so, think I still have it somewhere around. Looks like this is it on line now:
    http://www.forth.com/starting-forth/

    I tried to get into it a few times over the years but it just gives me headache and in the end is not what I want to do. For the ultimate in fast code I want assembler if need be. For anything else I want something that is easy to write and easy to read a year or so later when I get back to it. Forth does not do that for me and I don't see what big other advantage it might offer.

    Coupled with the fact that almost no one in the world uses it, so it's hard to share your work, I'm not inclined to pursue it. There are many other interesting languages out there.

    Still as an educational exercise it is worth while to give it a once over. You never know what ideas it might stimulate in your mind.
  • Heater.Heater. Posts: 21,230
    edited 2012-08-09 09:07
    To give you an example of why I have no time for Forth this is from early in the book I linked above:
    To give you a sample of what a Forth application really looks like, here's a listing of our experimental application:
    
    
       ( Large letter F )
        : STAR 42 EMIT ;
        : STARS   0 DO  STAR  LOOP ;
        : MARGIN  CR 30 SPACES ;
        : BLIP MARGIN STAR ;
        : BAR  MARGIN 5 STARS ;
        : F    BAR BLIP BAR BLIP BLIP CR ;
    
    
    
    Well, it's understandable if you have read the book up to that point. But I don't want to spend more time than need be looking at such an ugly mess:)
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-08-09 09:19
    Heater. wrote: »
    To give you an example of why I have no time for Forth this is from early in the book I linked above:
    To give you a sample of what a Forth application really looks like, here's a listing of our experimental application:
    
    
       ( Large letter F )
        : STAR 42 EMIT ;
        : STARS   0 DO  STAR  LOOP ;
        : MARGIN  CR 30 SPACES ;
        : BLIP MARGIN STAR ;
        : BAR  MARGIN 5 STARS ;
        : F    BAR BLIP BAR BLIP BLIP CR ;
    
    
    
    Well, it's understandable if you have read the book up to that point. But I don't want to spend more time than need be looking at such an ugly mess:)

    Yep, it's an ugly mess, Forth lets you do that if you are inclined. It's all in the choice of names for the words and the STARS example is very simple I thought. If you type "8 STARS" that's what you get. But again, Forth is not just a "language" if you have read my Introduction page, it's a debugging and development tool loaded right into the chip, no assembler or "language" can give you that.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-09 09:56
    Starting Forth is still available from Amazon. I recommend it.

    I wrote a CNC controller in S8 Forth many years ago, before Zilog canned their barely-introduced Super 8 microcontroller (which had ENTER, EXIT, and NEXT native opcodes). I can't say it was painless, but it was a lot simpler to write and debug than the same program would've been in pure assembly, and I was able to cram a lot more functionality into the limited EPROM space available.

    -Phil
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-09 10:33
    I'm not incredibly bright...wait, I'm not one of THE incredibly bright individuals Jon is referring to but for some strange reason, I like using Forth.

    I like the immediacy of the environment, especially when playing with microcontrollers. Like Peter said, it's an interactive, immediate, fast interface to the hardware.
    16 pinout 16 pinhigh
    

    typed at the command line and the LED you have on pin 16 lights up.

    Have a new "word" you've been working on that you want to have run on its own cog?
    myword 3 cogx
    
    just started it on COG 3.

    Not working quite right?
    3 cogstop
    

    Made a bad word? You can "forget" it, edit it and load it again.

    "Starting Forth" and "Thinking Forth" are the 2 classic texts. Peter's write-up for Tachyon is very good. There are a couple of others I need to dig up references to.

    Want to run multiple propellers together? PropForth is probably the easiest way to do multi-prop development and especially testing. You can build a master/slave cluster as wide as you have pins to support. If you want to daisy chain them, you can go as deep as you want. (It's turtles all the way down!)

    Want to see what makes a Forth tick? You can pretty easily dig into the guts of it.

    Peter, in a matter of weeks (he IS one of the incredibly bright people Jon referred to), has come up with his version of a Forth that does what he needs/wants it to do. Pretty darn amazing!

    There's a learning curve, it does seem strange but it is fast, fun and interactive.
  • jazzedjazzed Posts: 11,803
    edited 2012-08-09 10:50
    Why Forth? So you can learn to talk like Yoda :)

    Forth is stack-centric; most other languages hide the stack.
    If you like RPN (post-fix expressions), you may like Forth.
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-08-09 11:29
    JonnyMac wrote: »
    incredibly bright individuals promoting Forth for the Propeller and I wonder why. Sincerely. Should I learn it? It seems intriguing and if these bright people are using it, there must be good reasons. I visit the computer book section at B&N every time I go in and I don't remember seeing any books on Forth. If I decided to learn, where do I turn for guidance?

    I don't know about the incredibly bright individuals, but I promote it because it is the ideal tool for work on micro controllers, and embedded systems, and real-time (time critical small systems, according to my personal needs. Its ideal for drivers. It has all the power and speed of assembler, and the easy of programming in a high level language. Its as simple as basic, bit not so slow; and is only limited by the hardware. It is (or can be) nearly the same on all hardware, differing only where it is tailored for the specific platform. If you learn forth once , it mostly applies to all implementations. If you code with hardware abstraction in mind, and you do drivers, the next layer stuff can be pretty much identical from one implementation to the next.

    Me, I'm lazy, yet impatient. I need stuff to be absolutely easy, and provide lots of instant gratification. I'm not so smart as most folks around here, I can't do stuff the hard way. If its not easy, its not going to get done by me anytime soon. And it better be fun. Forth is neat because it allows somebody like me to do a bunch of cool stuff where I can concentrate on the application I'm striving for, without getting bogged down by the tool. Of course, I was so impressed by the tool, that I got involved in the kernel development process; because I developed a vision for what the "perfect tool" would look like, and now I've found a group of folks that are helping me see that goal come true. So now the tool (and its associated processes) IS the application of focus. Pretty funny when I think about it. But after only a couple yours, I find before me a nearly (85%) perfect tool for my needs. Nothing else comes close.

    All the best books on forth are free (Brodie, Starting Forth, Thinking Forth are the traditional staring points). The tutorials, instructions and other online resources from several universities are also good sources and are free. Forth was one of the earliest 'net collaboration projects I encountered, and the similarities of this forum to that community was one of the things that attracted me to the stamp and the prop. If you need any help, nearly all the folks will try find you a solution or at least give you a smart Alec response. (Just like in the rest of the forums)

    The PROBLEM with forth is its TOO powerful. We can do absolute anything the processor is capable of, including destroying itself (if so capable). And its easy. You can get away with horrible code habits and still get a result, this was common in the past. (That's why I'm so big on requirements of best practices these days). There are no safeties or error checking unless YOU put it in your own darn self. I find this a bonus, the app either works perfectly, or blows up completely, so there are seldom hidden errors. Very easy to debug.

    If you know any other language, you have no need of forth; you can just use what you got. But it you need anything that forth offers, (interactivity, power, speed, compactness, extensibility, flexibility, simplicity, conciseness, a bunch of old men to look over your shoulder) then forth is a good choice, as it has all these thing in abundance.

    If you have any questions just ask. A dozen people will have the same question. If you can work an HP calculator you can code effective in forth. It takes about day to run through the tutorials and learn the basics, and only about 15 years to master.
  • RickInTexasRickInTexas Posts: 124
    edited 2012-08-09 13:39
    JonnyMac wrote: »
    I have always enjoyed computer languages -- though that hasn't caused me to learn a bunch of them (I enjoy paintings, too, but I don't paint). I see some incredibly bright individuals promoting Forth for the Propeller and I wonder why. Sincerely. Should I learn it? It seems intriguing and if these bright people are using it, there must be good reasons. I visit the computer book section at B&N every time I go in and I don't remember seeing any books on Forth. If I decided to learn, where do I turn for guidance?

    To distill it down to the most basic features:

    1) It's interactive, being an OS and a language you type a command (FORTH WORD) and it run immediately from a simple terminal.

    2) Define a new FORTH and it's immediately ready to use. No compile, link, upload needed.

    3) Very efficient both in code size and speed. Has been ports to virtually every micro back to 8080 to present.

    4) Supposedly at least 2-3x more productive than conventional languages like C. Opinions up to 10x.

    5) It's FUN to get the immediate gratification from natural flow w/o the usual compile, lik load etc.

    6) Proven mission-critical ability, used in aerospace and celestial telescope control.

    7) Still alive and actively developed. Look at Newmicros.com. ISOMAX Is real-time multitasking system based on FORTH. Can't personally vouch for the new stuff but they gave me great support on a 68HC11 board circa 1995 and are still in Dallas.

    To be complete why is it Not more popular with all this goodness?

    1) Stack-based RPN (think HP-41 et. al.) is foreign and non-intuitive to many.

    2) Not "cool" or in great commercial demand (46th) on one survey.

    Just try it, you're plenty bright enough and it well wort a couple hour even if you decide it's not for you.

    BTW Jon, I found Tanner's Electronics from you old Nuts and Volts columns, any other gems in the DFW area? I'm in Plano but will trek for cool tronix stuff. Too bad you got too cool for Texas, would have liked to meet you. JK about the cool stuff, I had a brief fleeting interest in the talent arena. Good luck in those endevours.
  • D.PD.P Posts: 790
    edited 2012-08-09 14:06
    Forth helps to remove the accidental complexity of the problem (compilers, linkers, loaders, libraries) so the engineer can focus on the inherent complexity. Forth allows the engineer to think in terms of the problem in its domain language not in terms of the syntax of the programming language. You build the forth to solve the problem, not cram the problem into the syntax.
  • David BetzDavid Betz Posts: 14,516
    edited 2012-08-09 14:27
    D.P wrote: »
    Forth helps to remove the accidental complexity of the problem (compilers, linkers, loaders, libraries) so the engineer can focus on the inherent complexity. Forth allows the engineer to think in terms of the problem in its domain language not in terms of the syntax of the programming language. You build the forth to solve the problem, not cram the problem into the syntax.
    Yes but that could be said of any interactive language not just Forth. For instance, Lisp or Python or Ruby. Of course, those languages are almost certainly too big to run efficiently on the Propeller.
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-08-09 14:44
    If you know any other language, you have no need of forth; you can just use what you got.

    It's not about need, it's about technical curiosity. I want to be a better programmer and keep my bag loaded with tricks; Forth seems worthwhile in that regard.

    @RickInTexas: When I moved back home to Los Angeles in 2006 it was not far from All Electronics, another popular supplier for hobbyists. Made a friend of mine from Austin jealous; I had Tanners in Dallas, I have All in Los Angeles.
  • D.PD.P Posts: 790
    edited 2012-08-09 14:54
    David Betz wrote: »
    Yes but that could be said of any interactive language not just Forth. For instance, Lisp or Python or Ruby. Of course, those languages are almost certainly too big to run efficiently on the Propeller.

    Exactly, with forth you build what you need to solve the problem (or reuse from other projects), nothing more, the kernel remains lightweight, fast, known and extensible.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-08-09 16:21
    I read through one of the forth primers and downloaded a forth compiler to play with. The RPN doesn't really bother me much. I've always prefered HP calculators that did RPN over other calculators that used parenthesis. However, I'm a bit confused about how to handle floating point, structs, objects and other features that most other languages support. I'm sure it can be done in forth, but seems like it would be quite awkward.
  • User NameUser Name Posts: 1,451
    edited 2012-08-09 16:44
    JonnyMac wrote: »
    I see some incredibly bright individuals promoting Forth for the Propeller and I wonder why.
    The smartest guy I ever worked with was a research scientist at IBM who was engaged in three-dimensional data storage in synthetic crystals. He was also the biggest fan of FORTH I've ever known. He said that no other programming language let him implement his brainstorms faster, and with less interference. I think that once your brain is oriented in that direction, it really can be a miraculous thing. The lightning-fast development of Tachyon Forth, by a single (albeit bright) individual, is a testament to the power of FORTH in the right hands. Of course you can also hang yourself with it. ;)
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-08-09 22:27
    http://jupiterace.proboards.com/index.cgi?board=programmingaceforth

    I find some of the FORTH Forums very helpful. This one supports the old Jupiter Ace computer (possibly the only computer released with FORTH packaged as its native language).
  • Heater.Heater. Posts: 21,230
    edited 2012-08-10 01:49
    D.P
    Forth helps to remove the accidental complexity of the problem (compilers, linkers, loaders, libraries)
    It does. But then adds the accidental complexity of having to think about a stack all the time which is not part of the problem I want to solve.

    Out of curiosity is there a Fast Fourier Transform in Forth we can look at. Just want to see what it looks like.
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-08-10 05:42
    Heater. wrote: »
    But then adds the accidental complexity of having to think about a stack all the time

    Some folks just can't get the stack part. The coolest thing is if you make ANY mistake, it usually results in a crash (until you level up a few times at least) so its like automatic debugging. Its either completely solid or it falls apart. Most other environments end up "hiding" errors by automagically doing something "for" you, those bugs are tough to find. Usually doesn't happen in forth, auto magic stuff is too expensive and gets in the way. This is not accidental, this is the whole point. Don't fight the tool!

    But if you even have to think about the stack (this guy uses 1 item and leaves 2, this guy uses 2 items and leaves 1) then you might be going about it wrong. This is supposed to be the easy part. I never even think about the stack beyond the number of items consumed and number of items deposited (unless I see under- or over-flow).

    But if you're a C guy, forth is probably the opposite of the way you walk.

    Brian has a list of forth materials at

    http://www.wulfden.org/downloads/Forth_Resources/
  • Heater.Heater. Posts: 21,230
    edited 2012-08-10 06:24
    Haha! That's my problem. I normally walk in the direction my face points:)
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-08-10 06:36
    C what happens when you try to even just find out about another language! Instant censorship. The alphabet of computer languages only needs the three first letters Assembler, Basic, and C for many people.......but not all...

    Okay guys, look at the thread title, the question please.

    Forth is a lousy language to teach and grade students on, unlike other languages where the syntax and structure is rigid saying "You must do it this way, yes, good, correct". So guess what gets taught then?
    Forth is more like a palette and canvas versus paint by numbers. So some may complain that there are no dots and you "have to" work out which way is best yourself. What a lousy language!
    You know what? The reason I love to use Forth is probably the extensibility, flexibility, interactivity, and productivity that I get which I have not found with conventional languages. Plus most of all Forth is FUN. Yes, FUN. Can I say it again, FUN.
    What happens when you have fun programming? You get a lot lot more done and faster, especially with all that feedback. You know guys, forget the manuals, forget the lint, forget the debuggers, just have FUN.
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-10 06:39
    Fun of forth you make, hmmm?

    Try forth not. Do forth, or do forth not. There is no try forth. :smile:

    ..and in closing, Yoda certainly knew the forth:

    Yoda: You must unlearn what you have learned.
  • RsadeikaRsadeika Posts: 3,837
    edited 2012-08-10 06:59
    IIRC, back in the late 70's or early 80's, their was some interest being generated about Forth. At that time it was being talked about, that Forth, as a language, fit between asm and C. So, Forth was closer to the "metal" than C, which I guess upset some of the C guys. Now, as it pertains to the Propeller, can Forth be used used in a similar, and effective way as PASM? So, maybe we can get away from the "shackles" of asm? I am all for a language that would have the power of asm, but would be a more intuitive language. I know, all the asm guys will say that asm is an intuitive language for them.

    Ray
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-08-10 07:12
    Rsadeika wrote: »
    IIRC, back in the late 70's or early 80's, their was some interest being generated about Forth. At that time it was being talked about, that Forth, as a language, fit between asm and C. So, Forth was closer to the "metal" than C, which I guess upset some of the C guys. Now, as it pertains to the Propeller, can Forth be used used in a similar, and effective way as PASM? So, maybe we can get away from the "shackles" of asm? I am all for a language that would have the power of asm, but would be a more intuitive language. I know, all the asm guys will say that asm is an intuitive language for them.

    Ray

    The Propeller is very different from any other micro and while it would be possible to get Forth to run at near assembler speeds on some micros I don't think the Prop is one of them. All bytecodes are pulled in from the hub memory and that takes time to do whereas PASM runs within its comparatively tiny 496 "words" of combined program and register space without hindrance. However as even my nascent VGA graphics demos hinted at we can get a lot of speed without having to have a dedicated cog running PASM for graphics routines. However Tachyon cannot replace PASM totally, it just makes it so much easier though to handle the majority of interfaces in the same language and environment as the application.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-08-10 08:11
    Dave Hein wrote: »
    I read through one of the forth primers and downloaded a forth compiler to play with. The RPN doesn't really bother me much. I've always prefered HP calculators that did RPN over other calculators that used parenthesis. However, I'm a bit confused about how to handle floating point, structs, objects and other features that most other languages support. I'm sure it can be done in forth, but seems like it would be quite awkward.
    It's odd that none of the forth proponents responded to my previous post. Maybe it's because I didn't ask a direct question, so let me rephrase my comment as questions.

    1. How do you handle floating point in forth? Is there a standard way to do this?
    2. How do you handle structs in forth? Is there a standard way to do this?
    3. How do you handle objects in forth? Is there a standard way to do this?

    It seems like forth has a couple of really nice features, which are execution from the command line and creating functions that can be called from the command line. I think this has been done with interpreted C also, but I don't have any experience with it,so I don't know it capabilities. It is certainly something that is done in bash, but once again I don't have much experience with that either.

    How does bash compare to forth? Can you do the same thing in bash that you can do in forth?
  • potatoheadpotatohead Posts: 10,261
    edited 2012-08-10 08:42
    I am curious about that answer too.

    My answer to "Why Forth?" is going to be that it makes a person think really differently! I've never forthed before, but I'm going to explore it some after reading that excellent book referenced above. The introductory material is golden. Some basic things were clarified for me, and I found some material on means and methods presented in clear ways that helped me see Forth better. --enough to want to write some programs to see whether or not it's for me.

    I suspect the answer to this question would be to actually encode the structure as words. Once the words are done, the structure is invoked by the use of them in a greater context. Want to modify the structure? Change the words. That's forthy, from what I now understand. Some memory would be defined as a word, and other words would use that one to index, select a member, etc...

    Instead of defining a structure that some language element understands, Forth gets extended. You write a program that understands the structure, and that program is invoked by the word used to name it, adding to the lexicon, which then allows for the higher level task to be described.

    That intrigues me. Mostly because I've not done it that way before, and man! Talk about portable. All one needs is a small Forth kernel. Take all of that, stuff it into that kernel, and suddenly a whole environment has been moved from one platform to another. Powerful, if you ask me. Different, weird, but powerful.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-08-10 08:45
    1) GNU Forth (see here) has built-in floating point. There have been other Forth versions with floating point as well.
    2) See this paper for one of a number of discussions on structures in Forth. Do a Google search for "structures Forth" for others.
    3) See this paper surveying a number of object support extensions to Forth.

    Note that Forth is a pretty low level language, particularly for implementations for embedded systems or microcomputers. Floating point, structures, and objects would all be extensions. Structures would be the easiest to implement since they could be handled similar to arrays with the variable name normally providing the address of a structure and the structure field name adding an offset. The usual operators would then load or store to that address.

    BASH and Forth are not really comparable other than they are both languages used for programming. BASH is a fairly high level language with a lot of built-in string manipulation, implicit memory management / garbage collection, etc. Forth is a pretty low level language, essentially an interactive assembly language interpreter for an integer-based stack machine. Forth was developed when almost all computers had the sort of memory sizes and capabilities now associated with medium-sized microcontrollers (16-bit, maybe 16K RAM).
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-08-10 08:50
    Dave, you mentioned floating point and immediately I turned off, the screen went blank. Floating point has been done to death in computer languages yet I have never needed floating point. How's that? I know the scales involved both on the input and the output so simple scaling of integers is all I have ever needed. No accumulation of floating point errors a la Patriot missile bug for me thank you. If I have a 12-bit ADC and it has to be scaled to an odd figure then this is easily handled with a multiply and a divide. But I am intrigued by your challenge only in trying to understand what you are trying to prove. You have a shiny red car and you are asking us in our blue cars why ours aren't red. Do they need to be?
    Give me a typical real-world example of how you use floating point, what structs and objects you have in mind. However this changes nothing as Forth just allows you to morph it into whatever you want, be it Floating point cruncher, Object Oriented programming, Fuzzy logic, etc. I even wrote a PLD compiler once in a single afternoon with just a single page of Forth source vs the serious and voluminous conventional language source that was my alternative (never was).
  • potatoheadpotatohead Posts: 10,261
    edited 2012-08-10 08:58
    When you say, "A single page of Forth" is that starting with the core words, or including a bunch of other words that you happen to have already defined?

    I'm asking, because it seems to me, just about anything ends up "A single page of Forth", done right. :)
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-08-10 09:14
    It was literally a single page of Forth on top of the existing kernel at the time, done right of course. It was for a multi-level PLD at the time and it even did the complex "twiggling" to burn it into the device too! ( The cost of the manufacturer's programmer and compiler for this just about made me faint).
Sign In or Register to comment.