6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 7:06 am

All times are UTC




Post new topic Reply to topic  [ 144 posts ]  Go to page 1, 2, 3, 4, 5 ... 10  Next
Author Message
 Post subject: What is Forth?
PostPosted: Tue Feb 14, 2006 12:17 am 
Offline

Joined: Thu Jul 07, 2005 12:34 am
Posts: 23
Location: Minnesota
Hi,
I have heard alot about Forth on this site as I'm programing a 6502 based computer. What is Forth exactly and what is it used for :?:


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 14, 2006 4:59 am 
Offline

Joined: Sun Jul 10, 2005 3:18 pm
Posts: 8
The simplest (and likely insulting) answer is that it's a programing language and -- not surprisingly -- it's used to program computers. There are several people on these forums who are very knowledgeable about forth, and they can probably tell you a lot about it. I just started learning it so I'll give you my impressions and what I understand -- perhaps incorrectly -- about its history. Forth was created by Charles Moore during the 70s and was a very minor language through most of that decade. However, when microcomputers came on to the scene in the late 70s, Forth gained popularity very quickly because it was powerful but had low system requirements. Forth remained popular through the 80s, but as computers became more powerful it lost out to other languages. Because it's powerful, and easy to port to new systems, Forth is apparently used in many embedded applications, including openfirmware, which is the equivalent of the BIOS for many computers made by Sun, IBM, and Apple (so if you have a PowerPC based mac, you can boot up into openfirmware and program in forth).

As for the language itself -- as someone who started programing in BASIC and then moved on to c, c++, java, and the likes -- it's quite odd. Operations are done in reverse polish notation (which is easier on computers) rather than infix notation (which is what most people are familiar with). So instead of writing "2 + 3" you write "2 3 +". All data is effectively passed between functions (like plus) with two stacks which you are very intimate with. I'm sure other languages uses stacks in similar ways, but they're hidden from view. Also, I suppose because of its low system requirement origins (it's not fourth because the system it was originally written on could only handle 5 letter names), commands are kept very short, making them quite cryptic. Granted, all languages are somewhat hard to understand, but compare BASIC's PRINT command to forth's equivalent, ." (dot quote). The last big change I've noticed is you don't so much write lines of code, but write lots of very short (maybe one line) functions and string them together.

I should also point out that the language is not interpreted (although it didn't quite fit my idea of compiled, mainly because, in hindsight, I didn't have much of an idea of what complied means). The forth implementations for older computers tended to take the role of an operating system; forth was a complete environment to work on a computer in. Now you can run forth under other operating systems. Also, many (most? certainly most for older processors) implementations of forth do not have built in support for floating point numbers, so you have to put some thought in to using integers as fixed point numbers.

I'm still not sure what to make of forth. Once I get my 6502 computer up and running, I'm going to fool around with it more. I can't imagine writing complicated pieces of software in forth, but probably because I'm not in the right mind set. Because you have to write many small functions, it's really ideally suite for breaking a problem down into (very many) bite sized pieces, and hence is good for top down design. In that respect, forth seems to have been a precursor to many modern programing trends like extreme programing. The book, Thinking Forth (which is available for free on the web) supposedly explains this philosophy (I haven't read it yet).

A final thing I should comment on is forth users, many seem to be quite devout, perhaps even zealot like (Moore has said some stuff along the lines of "All forth programers are jubilant, but I've never met a happy C programer," I beg to differ). I haven't met enough forth programs to find out the extent of their devotion, but when I mentioned that I was learning forth to my dad (a mathematician), he laughed and recalled a colleague who used to preach the word of forth religiously to the rest of the department, although apparently he gave up proselytizing some time ago. Although maybe if his colleague was successful, I'd have learned forth rather than basic, and I'd be jubilant too.

_________________
TANSTAAFL -- There Ain't No Such Thing As A Free Lunch


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 14, 2006 7:15 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
I started thinking about and writing to answer the question before dlenmn posted, but it's interesting now to get these impressions from someone who has already started investigating.  I'll make some comments about his post here, and do my own effort to answer the question in my next post.

I believe the reason Forth will never be as big as C and other major languages is because it gives the user total control.  If you're trying to sell me Forth and you say, "You need my new version because it has...", instead of buying it, I'll say, "Good idea!" and go implement it myself on my own Forth.  How can you make any money that way?!  Forth, Inc. does sell their Forth, but they seem to make most of their money selling their programming and training services to large customers.

As far as cryptic commands go, the basics are indeed cryptic (like @ means "fetch" and ! means "store"); but the basics are quickly learned and never forgotten.  You can name your own Forth words anything—for example, ±½° or I²C_ACK.  Virtually all Forths today allow up to 31 characters in the names.  I believe Forth, Inc.'s SwiftForth allows up to 255.

There is the common criticism that Forth is a write-only language.  I have seen tons of unreadable Forth source code; but I blame that on the programmer, not the language.

It's true that only the high-end Forths routinely supply floating-point, but you can add it to any low-end Forth as well.  Leo Brodie used to discourage most use of floating-point, which left me skeptical; but now with years of practice in fixed-point and scaled-integer math, I'm a believer.  You don't need floating-point even for LOG, ALOG, SIN, COS, TAN, PI, etc. or for representing a huge range of numbers.  (That's what we're addressing in the forum topic under Programming-->scaled-integer math methods.  [Edit: There's more in the front page of the section of my website on large look-up tables for hyperfast, accurate 16-Bit scaled-integer math, including trig & log functions, at http://wilsonminesco.com/16bitMathTables/index.html.])  Could I write a floating-point set now (or implement one someone else has already written)?  Sure.  But for the things I do, I don't want it.

As far as the enthusiasm goes, I must say that there is a lot of capability there that does not initially meet the eye.  As I was getting into Forth, I saw a lot of limitations, so I was skeptical that I'd be able to do certain things.  As I got more experienced with it, I began to find that those limitations were only perceived, and that Forth actually not only offered ways to do these things, but even far more elegantly than I could have ever imagined.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Last edited by GARTHWILSON on Tue Feb 14, 2006 7:53 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 14, 2006 7:32 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
99% was spot on with me, and articulated far better than I would have.

dlenmn wrote:
All data is effectively passed between functions (like plus) with two stacks which you are very intimate with.


Once you get used to this concept, you'll find other languages kind of limiting because you're constantly having to name things, even when they really don't need a name.

Quote:
commands are kept very short, making them quite cryptic.


No, you just don't know the language yet (by which I mean you're not "fluent" with the language yet).

The recommended Forth word is no longer than two lines. Moreover, you should strive hard to have fewer than 3 items on the stack for a word (this does not mean that your stacks cannot exceed this depth to be useful; it just says that, as a rule of thumb, any one word shouldn't need more than 3 parameters. Obviously, rules of thumbs can have exceptions if well founded). For example:

Code:
: paint   initialize begin event-loop done? until ;


That's not hard to read, and is amazingly English like. Let's see how this goes as we get deeper:

Code:
variable done

create handler-table
' mouse-movement-handler ,
' mouse-button-handler ,
' keyboard-handler ,

: off   0 swap ! ;
: done?   done @ ;
: initialize   graphics-mode reset-mouse done off ;
: event-type   current-event @ @ ;
: to-handler   cells handler-table + @ ;
: handle-event   event-type to-handler execute ;
: event-loop   begin event? until handle-event ;


Note that "!" and "@" mean "store" and "fetch" respectively. They're assigned single-character names because they're used so often. By the way, for those interested in the history of those names, it's because back then ! was used to indicate "destructive updates" in Lisp, which means the value written destroyed another value in the same memory location (e.g., as STA overwrites memory with the current accumulator contents). Hence, ! became store, while @ became fetch. For BASIC users, ! is POKE, @ is PEEK. :)

Other than what I described, I'd like to see if the reader has any difficulty in understanding the above code. If not, then let that stand as proof that self-documenting and highly readable and maintainable Forth is possible. Don't be fooled by the claims of Forth being write-only. I've seen even Pascal programs that were extremely difficult to read and maintain too, and Pascal is the benchmark in readable code (or, at least, was, until Python came around, but even Python is a descendent of Modula-2).

Quote:
I should also point out that the language is not interpreted (although it didn't quite fit my idea of compiled, mainly because, in hindsight, I didn't have much of an idea of what complied means).


It's both. Forth is interpreted at the outer interpreter level (e.g., what you type interactively is interpreted in the BASIC sense of the term). Inside colon definitions, however, the code is typically compiled into what's called threaded code. Threaded code (not to be confused with multi-threaded code!) is a highly compact representation of a program where most of the overhead of normal interpretation is performed at compile time. This representation can be either interpreted with what's called an inner interpreter, or can be natively executed by the CPU. It all depends on the type of Forth you're using. There are also native-code compiling Forth environments that produce code rivaling or exceeding those of modern C compilers as well, but they're usually commercial Forth environments, and tend to be expensive.

To illustrate how these different methods differ, look at the following example:

Code:
\ in Forth, this is what you see...
: to-handler   cells handler-table + @ ;

\ in a direct-threaded Forth environment, this is what the CPU sees:
to_handler:
  jsr colon_definition
  dc.w cells, handler_table, plus, fetch, exit

\ in an indirect threaded Forth environment, this is its memory layout:
to_handler:
  dc.w cells, handler_table, plus, fetch, exit

\ in a subroutine-threaded Forth environment:
to_handler:
  jsr cells
  jsr handler_table
  jsr plus
  jmp fetch


Quote:
Also, many (most? certainly most for older processors) implementations of forth do not have built in support for floating point numbers, so you have to put some thought in to using integers as fixed point numbers.


This is true only for those systems that lack a hardware FPU. Those which offer a FPU will typically have floating point words defined for them.

Quote:
I can't imagine writing complicated pieces of software in forth, but probably because I'm not in the right mind set.


It's all about the mindset. Several quite significant projects have been written in Forth. See http://forth.gsfc.nasa.gov/ . The Canon Cat word processing system was written entirely in Forth. Nearly every one of Atari's stand-up arcade games were written in Forth back in the early to mid 80s. The Soviet Union even used Forth for its military and academic projects (while we concentrated on C and Lisp) because they couldn't afford the computing resources we enjoy. Now that the iron curtain has fallen, we're seeing a sharp decline in the use of Forth in Russia.

Quote:
Because you have to write many small functions, it's really ideally suite for breaking a problem down into (very many) bite sized pieces, and hence is good for top down design.


But, you'll want to do bottom-up implementation. Test the foundation code as you go, interactively. This leads directly to lower time to market and with fewer bugs.

Quote:
Moore has said some stuff along the lines of "All forth programers are jubilant, but I've never met a happy C programer," I beg to differ


While that is quite a stretch, I do know for a fact that I haven't met a single former-C-now-Forth programmer who wasn't ecstatic about the language. I've converted quite a few people myself, and not once did I do any proselytizing. I won the programmer over with documentation, actual working code, and observed programming productivity performance.

I hate the proselytizing myself -- my other all-time favorite language is Oberon, which is a refinement of Modula-2 -- about as wholesale opposite of the Forth philosophy as you can get. :) As someone knowledgable in BASIC, BCPL, C, Forth, Io, Java, Lisp, Modula-2, Oberon, Pascal, Perl, Python, Tcl (vaguely), and more I probably forgot, I think I have a right to say that Forth really is the all-time most misunderstood language, perhaps with Lisp in 2nd place. Lord knows that, next to BASIC, it's easily one of my most productive programming languages, and like BASIC, it is highly conversational.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 14, 2006 7:50 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
There are tons of write-ups on the web to answer bvold's question.  I'll direct you to a couple of good ones, http://web.archive.org/web/200607212354 ... ut4th.html and http://web.archive.org/web/200603141413 ... bforth.htm, before attempting to answer it myself below.  The book "Starting Forth" by Leo Brodie is very dated but still very good.  You can find it online at http://home.iae.nl/users/mhx/sf.html .  [Edit: Forth, Inc. has it online now with the original cartoons but some material updates for ANS Forth at http://www.forth.com/starting-forth/.]  Forth Inc.'s website is at http://www.forth.com/ .  The Forth Interest Group's website is at http://www.forth.org/

If you've ever used RPN Hewlett-Packard calculators, you're part of the way to Forth already.  Instead of using piles of parentheses in equations, you are given direct access to the data stack.  To contrast the two calculator programming methods (algebraic versus RPN), the algebraic code shows what calculation you'll get, whereas the RPN shows how you get there.  Initially, I could have gone either way; but as I got into using the hand-held computer for controlling things (where there's a lot more to computing than just calculations), RPN showed definite benefits.

Forth's data stack is not limited to the four levels of the HP calculators though.  Its limit is deep enough that you won't ever overflow the stack in normal work.  In contrast to RPN calculators, Forth uses the data stack for most parameter-passing, not just for your arithmetic.

Every little piece of code you write in Forth is what we call a "word", whether it's a subroutine, a new kind of variable or data structure, part of a new program structure, or whatever.  Each word you write is added to the dictionary, and becomes part of the language just like the words your Forth came with.  If this sounds like you can actually extend the language, that's exactly right.

In fact, you can get "under the hood" and modify and extend even the compiler itself, giving incredible freedom.  You can even define your own operators like + - * / etc., or redefine existing ones.  Every word's name—assuming it has one—can start with or include any characters except space, <CR>, <LF>, <NUL>, <BS>, and maybe <ESC> and the tab character.  That leaves almost 250 characters available.  There really is no punctuation, and even : ! @ [ ] , ; " are just words with very short names.

If you want to optimize a portion in assembly for best performance, you can, if you wish, write it first in high-level Forth to quickly test your idea, and then when you have it working, rewrite it in assembly, without having to change any of the code that uses it.  If your Forth does not include an assembler, it's easy to write one in Forth.  I wrote mine in a couple of hours.

Code is very fast to develop.  Forth Inc., whose main business seems to be programming services, has plenty of stories where, for example, it was estimated that a team of C programmers would need two years to complete a certain project (and we all know the estimates are always too low), but one man came in and did the whole thing by himself in Forth in six months.

There is no type checking in Forth; but with a little experience and the interactive nature of Forth, you'll seldom make a type error, and when you do, it will expose itself quickly and you'll get it corrected.

Many aspects of early Forth are obsolete, but the essence of Forth is as solid as ever.  Attractions include (but are not limited to):
  • power through simplicity
  • fully extensible
  • more interactive than the best BASICs I've seen
  • near-instant turnaround time from writing a little piece of code, to compiling it into your system, to watching it run, thanks to incremental compilation
  • easy and efficient to service interrupts in high-level Forth
  • easy to do multitasking, and even multi-user, even on simple processors
  • real-time
  • offers unlimited abstraction, without forfeiting down-to-the-metal control of the computer
  • almost no syntax requirements
  • mix assembly in very easily
  • very fast to develop bug-free code
  • very memory-efficient
  • execution speed generally comparable to C, although if you use a stack processor whose machine language is Forth, then it will scream performance
  • had the tools to do object-oriented programming (OOP) even before it was called that
  • makes good programmers better, and bad ones worse!

What it's used for:  It seems to shine most in machine-control and scientific applications, but it can be used for just about anything.  Plenty of spacecraft equipment is programmed in Forth, as are parts of Windows.  Applications range from small ones with only a few K of ROM, to large systems for administration in hospitals and airports.  [Edit: I posted links to some really big-league software packages written in Forth on page 9 of this topic, at viewtopic.php?p=54026#p54026, and the fourth post after that.]

The 6502 is kind of a natural for Forth, if it could ever be said that an 8-bit processor is a "natural" for handling 16 (or more)-bit cells.  It would be cool if the 6502 designers had had Forth in mind so they would have added a couple of instructions to streamline it further; but as it is, certain things do work out very nicely to implement Forth on the 6502.

I see Samuel posted while I was writing.  I guess I post the material above at risk of sounding like I'm proselytizing!
Quote:
Don't be fooled by the claims of Forth being write-only.

I've definitely heard that one before, but I blame that on the programmer, not the language.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Wed Feb 06, 2013 4:23 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
The article has been there for years, but I just saw it:  Lost at C?  Forth May Be the Answer.  Not quite fitting the title, it doesn't really start comparing it to C until you get about 70% of the way down the page, at the section, "How does Forth Compare with C?"  In the listing about 5 paragraphs below that, the most important parts to me might be #3 (immediate turnaround without needing the host computer to compile and link a target executable), #6 (no debugger needed), and #8 (extremely efficient interrupt handling, without overhead).

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Wed Feb 06, 2013 5:15 am 
Offline

Joined: Sun Jul 10, 2005 3:18 pm
Posts: 8
I had forgotten about this thread and my previous post on it. Since then, I've done a fair amount in forth -- read Staring Forth, read Thinking Forth, made a little computer that ran Forth, wrote a floating point word set for practice, etc. It has a truly amazing power to weight ratio -- you can do impressive things on a computer with very limited resources. I agree with that article; that makes it great for embedded programming.

However, I mostly do scientific computing nowadays. At first -- with Scientific Forth: A modern language for scientific computing in hand -- I tried to do scientific computing in forth, and it's simply not the right tool for the job. For that type of work, power to weight ratio isn't a concern; what matters is power, performance, and ease of use -- simple dynamic memory allocation, optimized operations on huge arrays and matrices, etc. The fact of the matter is that other languages allow you to do these cleanly with less thought -- which is important since you spend enough time figuring out what to do; you don't want to burn too much on how to do it. I'm sure forth zealots would disagree, but they're simply wrong.

_________________
TANSTAAFL -- There Ain't No Such Thing As A Free Lunch


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Wed Feb 06, 2013 5:40 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
I have that book (Scientific Forth) too, and found it quite unreadable.  I don't think that's Forth's fault though, just the way the book is written.  I can't say I've done much scientific computing.  FFTs is approximately the limit of what I've done in Forth, and got it going pretty quickly.  It may partly have to do with how the individual thinks though.  My thoughts don't go in normal English order, which is partly why I don't speak nearly as well as I write, since I can write and then edit.  I understand the Korean language is RPN, so Forth is probably more natural for native Korean speakers.  After I found Forth though, I never wanted to see an algebraic language again.

I have an HP-50g calculator someone gave me whose owners rave about it for scientific uses, and its user language is very close to Forth.  The manual it came with is terrible though so it was hard for me to get interested.  I know there's a better (and huge) manual for it I should download and print, but I have too much invested in my 41cx (which is also RPN) to make it worth it, especially now with new modules available, the 41z which gives it a native 4-level complex stack and 70+ complex-number operations written in assembly, and the Sandmath which has oodles and oodles of higher-level math functions.  Edit, years later: I did get Diego's Clonix-D module and put several ROM module images in its flash, including Angel's 41z and his WarpCore which adds 140 general-purpose functions that improve code density and performance in any discipline.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Thu Feb 07, 2013 6:38 am 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
The RPL used on the HP calculators is "Forth-ish" but most certainly not a Forth as we, especially in the 6502 world, think it.

As a Forth it's much higher level. Rather than putting simple scalars (some of which may happen to be addresses) on the stack, you put objects: numbers, strings, lists, functions, matrices, etc. It has first class functions, but not really closures per se.

It's control structures are slightly bas-ackwards:
Code:
    IF 1 = THEN 2 2 + ELSE 3 3 * END

If Top of Stack = 1, then perform "2 2 +" (which equals 4), otherwise perform "3 3 *" (9).

The RPL normally used is User RPL. This is distinguished from the lower level Sys RPL. User RPL is noted because it takes the time to check for things like data type compatibility, and range checking where as Sys RPL does not (and can there fore crash if given the wrong data).

For example, in User RPL:
Code:
"ABC" 1 +

evaluates to "ABC1", the '+' operator at the high level knows what to do based on the data types. In Sys RPL you would need to do this manually.

In truth, writing code in RPL is really a pleasure. It's simple to test, to create and edit your words, you have a stepping debugger. You also have nice things like forms and menus. Once you get used to it, the keyboard works pretty well (though the 48 keyboards are better than the 50 which is better than the 49).

Back in the day, I wrote a time tracking, data collection system for the HP-48. A company I was working with wanted a portable solution to do some data tracking out in the greenhouses. They were looking at some of the machines available, notably by companies like Symbol and the like. I happened to be visiting my Dad who had a -48, and I played around with it.

It seemed quite capable, but the selling point was that the HP-48 has built in, of all things, the Kermit protocol. Combined with the menus and forms, I whipped up a nice little app for it, and every day they would plug them in to a PC and upload the data via Kermit. It worked a treat, and the units cost $99 each (a far cry from what Symbols cost). They ran forever on AAA batteries, and were tough as well -- one got run over by a truck. We stuffed them in these bright orange nylon pouches we found.

It's a cool platform, really. I'd kill to have a back light on mine.


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Thu Feb 07, 2013 7:10 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
Thanks Mr. Hartung.  Now I know whom to come to for help if I ever do start getting into my 50g.  :D   It's interesting you say the battery life on the 48 was so good.  My 50g made a brand-new set of alkaline AAAs go dead and even leak in less than three months of sitting in the drawer.  Apparently it was everything the 49 should have been though.  [Edit: I found out it's because of a leaky capacitor that was making the calc take 7mA even when off.]

Comparing the speeds of inverting an 8x8 real matrix, IIRC, the TI-59 calculator—well, I gave up and turned it off after something like 10 or 15 minutes; the HP-15c took 40 seconds, the HP-41 with Advantage module took 20 seconds, the HP-71B (which has the Saturn processor that the 50g emulates) with Math module took 3.5 seconds, and the 50g gave no visible delay.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Thu Mar 27, 2014 9:22 pm 
Offline

Joined: Sat Aug 21, 2010 7:52 am
Posts: 231
Location: Arlington VA
To turn the original question on its head, what is *not* Forth? At what point does an implementation jump the shark and become something else? Target compiled code, with all the headers stripped out, for example. Or Postscript. For a roll-your-own implementation, what rules must be followed?


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Thu Mar 27, 2014 9:51 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
Interesting idea.  First musings:  You can definitely compile a Forth application without headers for a product that has no need to compile or to interpret a command line, and it's still Forth.  You can definitely do a lot of "roll your own" which is part of Forth anyway as the programmer essentially extends the language to make top-level words that basically are his program.  Things that come to mind as making it non-Forth are:

  • putting data on the same stack with the return addresses.  Forth requires two stacks, with optionally more.
  • abandoning reverse Polish notation and requiring parentheses and punctuation
  • taking away consistency in data stack cell size
  • removing the "Pearl of Forth," ie, CREATE, DOES>, and related words, which enable the programmer to make new kinds of defining words and to specify their compile-time behavior and run-time behavior separately

and I'll probably think of more later to add.  Hopefully Brad will jump in, as anything he writes will probably be way better than what I could do.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Thu Mar 27, 2014 10:10 pm 
Offline

Joined: Tue Jan 07, 2014 8:40 am
Posts: 91
Garth, I'd say you've largely covered it. I would add

    a) not passing parameters to/from called subroutines on a programmer-visible stack
    b) not offering an extensible "dictionary" of language elements (words)

As always, there are exceptions. E.g., many Forth programs (and C programs) pass data through global variables. What matters is for (a) is the procedure-call mechanism of the language.

And (b) of course applies at the time the program is compiled. A program can be target compiled and burned into ROM, at which point you can't add any more words!

I'd say the edges aren't sharp and clear. I've seen quite large Forth programs written without any use of CREATE..DOES>. I've seen extensions to allow algebraic expressions. The ANS Standard itself recognizes extensions to use local variables; I've even seen local-variable extensions that allowed named parameter passing. And there are many object-oriented Forth extensions.

Of course the pedantic answer is that anything which cannot compile a Standard Forth Program is not Forth. You can add whatever you want, but there's a certain minimum functionality that must be supplied.

_________________
Because there are never enough Forth implementations: http://www.camelforth.com


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Fri Mar 28, 2014 12:20 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 679
What is Forth? A miserable pile of stack operations!

What is Forth? Baby don't POP me, don't POP me, no more... *bobs head*


(I'll see myself out now...)

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Fri Mar 28, 2014 12:56 am 
Offline

Joined: Sat Aug 21, 2010 7:52 am
Posts: 231
Location: Arlington VA
Brad R wrote:
Of course the pedantic answer is that anything which cannot compile a Standard Forth Program is not Forth. You can add whatever you want, but there's a certain minimum functionality that must be supplied.


I was hoping nobody would say this, but I tend to agree. This whole thread kind of reminds me of the blind men describing an elephant. Sam Gross puts it best, "an elephant is soft and mushy" Image

Six blind elephants were discussing what men were like. After arguing they decided to find one and determine what it was like by direct experience. The first blind elephant felt the man and declared, 'Men are flat.' After the other blind elephants felt the man, they agreed.

My thoughts are greatly influenced by R.L. Loeliger's book, "Threaded Interpretive Languages," in which he implements a decidedly nonstandard Forth for Z80, but calls it a "TIL." In fact, this book was my introduction to Forth when I worked at ComputerLand back in 1981.

Somewhere recently I read (maybe it was on the camelforth site) that "any Forth worth its salt these days will implement the ANS standard." That's a bit of a paraphrase. I inspected gforth (my available ANS Forth implementation) and was dismayed by the apparent bloat. There is 16K of just word names in gforth, to say nothing of the code behind them that implements their functioning. I'm working with a 32K RAM machine here, have mercy! Andre Fachat's youtube video demonstrating his Geckos operating system, he says in the first 40 seconds that the operating system only leaves 6K available for application code.
Code:
$ gforth -e 'words bye' | wc
    245    1835   16440


I'm leaning toward this: Forth is a design pattern in assembly language. It traditionally contains elements such as the dictionary, the two stacks, langage extensibility, other stuff mentioned by Garth. There are traditions and a community/culture surrounding it, and several standards have emerged through the years to encourage portability, known as "Standard Forth". But above all else, Forth is practical, and it provides the programmer with bare metal access to the machine without the inconvenience of coding everything in assembly.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 144 posts ]  Go to page 1, 2, 3, 4, 5 ... 10  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: