Should i learn forth




















The missing features in Forth are the main strength of the language. If the language comes without guidelines and without predefined functions, the developer is in charge to deliver the missing parts.

Forth is a programming language not invented yet. Forth can be seen as a true metalanguage. Even the well known Forth primitives like swap, dup and mod are not standardized, which means they have to be invented in each Forth system by it's own.

Mainstream computer languages like Java or Python can be seen as the answer to a problem. Java, for example answers the question of how to program platform independent code. The programmer has to read the manual, understands the concepts behind Java and follows the community. Forth is working the other way around. It doesn't provide knowledge, Forth asks for knowledge. In mainstream programming languages, the newbie gets a shiny compiler for running the sourcecode.

In Forth, the newbie has to write the compiler as his first project. That is the reason, why Forth is loved by computer professionals.

It gives them the opportunity to learn, to make mistakes and to bring technology forward. My prediction is simple: in 20 years, all the mainstream languages are gone. C will become obsolete and nobody will remember the PHP scripting language, but Forth will become the industry standard. The reason is, that Forth doesn't provide sourcecode and the available Forth Virtual machines can't be recommended anymore.

But if nothing is there, what should the newbie learn? What are the do's and dont's? The reason why Forth is nearly invisible has to do with, that it's a virtual machine. A VM is a game similar to a cardgame.

The rules of the Forth game can be written down in a single sheet of paper. But for playing the game right, this description is not sufficient. What the beginner needs are additional information about Forth. I can't recommend a single book. The inventor is Chuck Moore and he has written some books about Forth, but they are not the best starting point. What i recommend is to use a search engine like google and search in the existing fulltext of all publications.

Finally I asked them how many labels should have been printed, The last label form had this count. I appeared to be correct. How could this be? The program it replaced took 90 minutes on the same machine and had be written by an experienced programmer.

Eventually they realized that all the labels had been printed and in less than half the time on the exact same hardware. So which programming language is best? It is more important to hire a programmer who think about what he is doing and comes up with the best solution for the job. Unfortunately there are very few of these. Aydin — Yes: MSIL definitely does a lot of thinking about stacks and so on: I think whoever put it together realized that you can boil pretty much anything down to processing and stacks if you want to, and FORTH is, of course, the epitome of that type of thing.

The only thing you really have in life, is time. Why waste your life on such folly? Nothing better to do? Read to your kids, build something, learn to cook, chasing the language of the month is the most useless thing I can think of. A false religion. You can also read, build, cook, fix cars, build engines, drive rally cars, play musical instruments, speak multiple languages, write books, etc: I do.

All of it is part of the same learning process. The end is in the journey, and other such aphorisms…. Dan Sutton, Agreed it is good to read, build, cook, fix cars, play musical instruments and speak foreign languages. But included in that mix is also learning new programming languages which is very close to learning a foreign language. The most accomplished pianist I know programs for a living as at a certain point he discovered that he was not going to play Carnage Hall.

Wow — definitely an abstruse way into programming. I like it! I actually did sing at Carnegie Hall, but I was 12 at the time part of a choir so I guess after that, I was done, so I program for a living instead…! In that case, the following will be of some interest: this summer, Microsoft are releasing the preview version of SQL Server , and it has R built into it: apparently, they acquired the parent company. Someone in HR giving career advice, and to a technical field no less?

Next we call buzz? Now the top two values on the stack are booleans representing whether the number was divisible by 3 or 5. After this, we call or to see if either of these is true, and invert to negate this value. Logically, the body of fizz-buzz? Therefore, fizz-buzz? Finally, do-fizz-buzz loops from 1 to 25, calling fizz-buzz? As you execute each line, watch the stack to see how it changes:. Remember, the final value on the stack is the return value of the fizz-buzz?

Forth also allows you to save values in variables and constants. Variables allow you to keep track of changing values without having to store them on the stack. Because the role of local variables is generally played by the stack, variables in Forth are used more to store state that may be needed across multiple words. This basically associates a particular memory location with the name balance. You should see the value on the stack. This Forth implementation arbitrarily starts storing variables at the memory location The word!

This time you should see the value on the stack. Likewise, retrieves the value based on the memory location, and pushes that value onto the stack. The word? Constants are defined in one line, like this:. This creates a new constant called answer with the value Running this will push the value 84 on the stack.

To allocate this memory, use the allot word. This example creates a memory location called numbers , and reserves three extra memory cells after this location, giving a total of four memory cells. Forth has a special word called key , which is used for accepting keyboard input. When the key word is executed, execution is paused until a key is pressed. Once a key is pressed, the key code of that key is pushed onto the stack. Try out the following:. This is because the interpreter is waiting for your keyboard input.

Try hitting the A key, and you should see the keycode for that key, 65 , appear as output on the current line. Now hit B , then C , and you should see the following:.

Forth has another kind of loop called begin until. This works like a while loop in C-based languages. Every time the word until is hit, the interpreter checks to see if the top of the stack is non-zero true. If it is, it jumps back to the matching begin. If not, execution continues. We then use. If it is, we break out of the loop, otherwise we loop back to begin. Before we look at the code, try playing the game.

To start the game, execute the word start. Then use the arrow keys to move the snake. If you lose, you can run start again. Before we delve too deeply into this code, two disclaimers. First, this is terrible Forth code. Second, this game uses a few non-standard techniques in order to interface with JavaScript. You may have noticed that this editor is different from the others: it has an HTML5 Canvas element built in.

The first pixel is found at the memory address given by the variable graphics , and the rest of the pixels are offsets from the variable. So, for example, to draw a white pixel in the top-left corner you could run. For example, 3 4 draw-white draws a white pixel at the coordinates 3, 4.



0コメント

  • 1000 / 1000