7 ms·
Starting Forth
- jcr 11y ago"Starting Forth" is recommended reading, and so is "Thinking Forth" which was posted a few days ago: https://news.ycombinator.com/item?id=9842557 https://news.ycombinator.com/item?id=9842557
- dmytrish 11y agoI tried reading "Thinking Forth", but never got why it is praised so much. Looks like a bunch of war stories from 80s from veterans who discovered some basics of encapsulation in need to handle Forth programs complexity.
- rpcope1 11y agoIt's really cool to see all of this interest in Forth. I think when I learned Forth, it made me a significantly better developer over all; it's also an awesome base for DSLs and really a fascinating paradigm.
- VieElm 11y agoHonest question, wouldn't you just write a lexer with yacc/bison for a DSL? How does a full programming language act as a base for a DSL, which is usually more limited than a programming language?
- rtpg 11y agothe avantage of using a full programming language as a base for your DSL is that you don't have to deal with some of the "simpler" things. Your base language already has variable assignment, loops, recursion? Great, you don't have to deal with that. Type checking? Wonderful, don't have to go read up on type inference
- rebootthesystem 11y agoA typical use case for Forth to launch from bare metal (more like bare silicon) into the application on embedded systems or as the bootstrap mechanism/BIOS for a more advanced OS on a larger, perhaps desktop, system. A Forth console over a serial port can provide a user with tons of low and high level access to a system. I built a 12 processor "parallel" robotics controller back in the '80's using a bunch of Rockwell R65F11 Forth processors (6502's with Forth in ROM).
- AdieuToLogic 11y ago> Honest question, wouldn't you just write a lexer with yacc/bison for a DSL? Perhaps this article[1] can help answer the question (BTW, the title of the page belies its applicability). Check out Figure-1 specifically. > How does a full programming language act as a base for a DSL, which is usually more limited than a programming language? IMHO, this is what makes Forth both beautiful and mind bending, as Forth is a "full programming language" in which programs/systems written in it are expressed as a DSL defining the system itself. If that sounded recursive, then you're well on your way to grokking Forth :-). 1 - http://www.forth.org/lost-at-c.html http://www.forth.org/lost-at-c.html
- rpcope1 11y agoWell for a lot of devices I've worked with, you can shoehorn Forth places that most (if not all) other languages short of assembler can not go (Forth is _really_ lightweight). Forth was designed with DSL's in mind (Forth has "vocabulary" which is targeted specifically at this); the language usually comes with a basic syntax and some core primitives built in, but features a really profound ability to define new primitives, even things like "if" that most languages have built-in and have no facilities for constructing variants. You might liken it to macros in Lisp. A good place to learn more (if you have some familiarity with Lisp) is: http://stackoverflow.com/questions/24282153/comparison-of-common-lisp-macros-and-forth-metaprogramming-capabilities http://stackoverflow.com/questions/24282153/comparison-of-co... I guess the other huge nice thing abort Forth for DSLs is that it is (unlike assembler or C), an interactive language, even on the most stripped down platforms (like bare bones $0.50 8-bit MCU stripped down), and still encourages the sort of REPL experimentation typically only seen in much much higher level languages. All of this comes at a big price though, in that the caliber of developer required to wield Forth in a sane manner tends to be very high.
- mikekchar 11y agoThe kernel for FORTH is crazy small. IIRC it's not unusual to shoe horn it into 2K. When people talk about writing DSLs in FORTH, I think what they are really saying is writing an API based on the FORTH kernel. So the DSL is really FORTH, but just with your API. Granted changing how words are compiled and executed is pretty much standard fare for a FORTH programmer, so you can make it work however you want. FORTH is a bit like smalltalk in that you usually work in an interactive environment and save images. FORTH code compiles down to essentially a jump table and so it is also really, really efficient, space wise. You can decompile code easily and modify it in your image. If you were trying to write a control language for some small embedded device, it would be ideal. If you were trying to write a DSL for configuring a build system (or something like that) it would be less nice ;-) My first few paying jobs (when I was in university) was writing FORTH code, but that's a very long time ago ;-) I'm still quite nostalgic about it even though I've forgotten almost everythng I once knew.
- david-given 11y agoYup, me too. I'd recommend that anyone with a serious interest in programming should learn Forth (and write a Forth system from scratch): I'll probably never use it in anger, but it made me think about programming in a very different way. (Also, curiously, gave me an increased respect for K&R C, which allows minimalist programming in a way that ANSI C doesn't.)
- DennisP 11y agoHow does K&R C allow more minimalist programming?
- userbinator 11y agoThose who enjoy Forth may also like to try PostScript for a more graphical experience.
- protomyth 11y agoI liked programming in PostScript more than Forth because of all the additional non-graphic things it had. Look at the Blue Book ("The PostScript® Language Tutorial and Cookbook") http://partners.adobe.com/public/developer/ps/sdk/sample/index_psbooks.html http://partners.adobe.com/public/developer/ps/sdk/sample/ind... for some examples.
- arethuza 11y agoMany years ago I did a project with a lisp back-end, a front end in PostScript (NeWS/HyperNeWS) and C code gluing the two together - it made me appreciate than an interactive PostScript environment is surprisingly lisp-like. Edit: This has made me wonder about a NeWS-like server sitting on top of OpenGL and using an interactive PostScript like language.....
- protomyth 11y agoI started my career with a Turbo C complier, a PostScript printer, and a government database written in FoxBase. I learned a lot of PostScript programming in order to generate the report we needed. I later got NeXTSTEP 3.3 which made interacting with PostScript a true joy. I have often thought a NeWS-like server would be a fine replacement for a lot of web stuff.
- sysk 11y agoIs Forth still being used in industry other than for legacy systems? (genuine question)
- AdieuToLogic 11y agoOpen Firmware and the FreeBSD loader use it presently.
- sedatk 11y agoYes, IIRC Intel's Itanium (IA64) architecture used firmware and drivers in Forth (instead of machine code) so you could use the hardware on any CPU architecture.
- pgeorgi 11y agoNo, Itanium specifically eschewed OpenFirmware (IEEE1275-1994, which is ANS Forth based) in favor of inventing EFI, which would develop into UEFI later. Among the reasons: no interest in bytecode (UEFI now has EBC), no ACPI support (IEEE1275 predates ACPI by a decade, Intel didn't bother), protecting Intel's "Independent" BIOS Vendors from having to compete in an existing market (there were several OpenFirmware vendors). Most OF implementations are now open source, we collected them at www.openfirmware.info.
- theophrastus 11y agopostscript is a dialect of forth http://hyperpolyglot.org/stack http://hyperpolyglot.org/stack
- teh_klev 11y agoI wouldn't go as far as saying Postscript is a dialect of Forth, influenced by or perhaps "Forth-like" (i.e. stack-based), but certainly not a dialect.
- Animats 11y agoNot much. Forth is from an era when it was hard to program small microcontrollers and the tools for doing so were expensive. Today, everybody cross-compiles to microcontrollers. I've done robotics programming in Forth. I do not expect to use it again.
- AdieuToLogic 11y agoAn approachable platform for hacking Forth is the OLPC laptop[1]. For about $25 USD[2], that's a pretty cheap way to go Forth and multiply :-). 1 - http://www.openfirmware.info/Forth/FCode http://www.openfirmware.info/Forth/FCode 2 - http://www.ebay.com/sch/items/?_nkw=olpc+laptop&_sacat=&_ex_kw=&_mPrRngCbx=1&_udlo=&_udhi=&_sop=12&_fpos=&_fspt=1&_sadis=&LH_CAds=&rmvSB=true http://www.ebay.com/sch/items/?_nkw=olpc+laptop&_sacat=&_ex_...
- brudgers 11y agoGNU Forth [or gforth] is available on Android phones. http://www.forth-ev.de/wiki/doku.php/en:projects:gforth-android:start http://www.forth-ev.de/wiki/doku.php/en:projects:gforth-andr...
- lukego 11y agoIf you have an OLPC XO 1 then you can also download the specifications for the AMD CPU here: http://www.versalogic.com/support/Downloads/PDF/LXManualMay08.pdf http://www.versalogic.com/support/Downloads/PDF/LXManualMay0... That tells you how to do graphics hacks and so on. I had fun with that on my OLPC. I optimized the Forth console to scroll using hardware BLIT (much faster than CPU copy of the framebuffer) and I ported Squeak Smalltalk to run directly on OFW using hardware graphics primitives e.g. for the mouse pointer. Fun times :)
- lukego 11y agoThe biggest hack I did was to rewrite the builtin PONG game to try and be more in the spirit of Thinking Forth: http://lukego.livejournal.com/10847.html http://lukego.livejournal.com/10847.html
- llebttamton 11y agoTrivia: the FreeBSD boot loader uses forth
- deleted 11y ago[deleted]
- emersonrsantos 11y agoJupiter Ace (a 8-bit microcomputer from the 80's) used its own dialect of Forth instead of BASIC, and there's lots of files and documents at http://www.jupiter-ace.co.uk http://www.jupiter-ace.co.uk
- llebttamton 11y agoThere was a Forth debug/service terminal included in an electronic typewriter / typing tutor device from the 80's with an integrated CRT display. So an educated guess is that its software was also written in Forth. It was made between 1981 and 1987 and I think it was a golf ball-style printer, so if anyone have an idea as to the make and model, that would be great.
- peteri 11y agoI'm guessing you're thinking of the Canon Cat. There was also a plugin board version for an Apple //e which went in the 80 column slot.
- avodonosov 11y agoAnd here is what Forth creator Chuck Moore does today: http://www.greenarraychips.com/ http://www.greenarraychips.com/
- NhanH 11y agoAsking the obvious question: What should I use that for? (The computer, and Forth too)
- dmpk2k 11y agoIts power consumption is ridiculously low; IIRC, at full utilization, it can be powered by a solar panel the size of your hand.
- agumonkey 11y agoSome people use them (or a sibling) in space http://www.cpushack.com/2014/11/12/here-comes-philae-powered-by-an-rtx2010/ http://www.cpushack.com/2014/11/12/here-comes-philae-powered... I guess dead simple design, low consumption is attractive here.
- platform 11y agoGreen Array Chips architecture is quite interesting. Perhaps a natural question, is there a software framework that mimics this way of building horizontally scalable services?
- pjc50 11y agoForth seems to have one thing in common with Lisp: a small dedicated following that believe it's the way forward and considerably easier to learn, despite never really having taken off. I suspect this is something to do with different ways of conceptualising programs.
- samsaga2 11y agoif you take away the parentheses from Lisp you end with a Forth
- progman 11y agoNot at all. I have developed in both languages. Forth is almost bare metal, between Assembler and C. Lisp is a high level language. Its abstraction level can be pushed way beyond any other language. DSL creation is much easier in Lisp than in Forth.
- pjmlp 11y agoAnother common thing, it also had its own computers, for example: https://en.wikipedia.org/wiki/Jupiter_Ace https://en.wikipedia.org/wiki/Jupiter_Ace
- gaius 11y agoI believe the Jupiter Ace was the only Forth-native home computer, tho' I have it on a ROM for the Beeb.
- pgeorgi 11y agoThey're different branches of computing history. There are few that consider it the 'way forward' as far as the mainstream is concerned, but the fans tend to consider it an underexplored model for one reason or another. See also oberon, smalltalk, eiffel for more language communities of that kind (the jury is still undecided where haskell ends up); os/2, plan9, l4 when it comes to operating systems/kernels; 6502, m68k, mill for Instruction Set Architectures; (and so on) Every now and then, us non-mainstreamers tend to sound a bit preachy when we get an audience, I grant that :-)
- Estragon 11y agoThis book inspired me quite a bit as a teenager.
- j_m_b 11y agoIs there any resource for learning how to implement Forth? It would be really cool to have a book that showed you how to determine your machine's capabilities and gave example of how you could implement it from scratch starting on Windows, Mac, Linux and onto other systems like Raspberry Pi, TI calculators and than how it is implemented on more esoteric systems like satellites.
- Avshalom 11y agoit doesn't go into specifically exploiting your machine but the infamous Jones Forth is ~1000 lines of assembly and ~a billion lines of comment explaining the assembly and this gets you into a functioning Forth, then it starts writing everything else in forth, including IF, WHILE, DO UNTIL... which shows how you can use the parsing words to write new language features. https://rwmj.wordpress.com/2010/08/07/jonesforth-git-repository/ https://rwmj.wordpress.com/2010/08/07/jonesforth-git-reposit...
- linuxlizard 11y agoQuestion for the Forth folks in this thread. Does Forth support loadable code modules? Here's the problem I'm trying to solve (still in the tinkering stage). I have an embedded processor with small on-board SRAM but huge external address space and a NAND flash. Can't add external RAM. http://www.atmel.com/tools/ATSAM4S-XPRO.aspx http://www.atmel.com/tools/ATSAM4S-XPRO.aspx Would like to be able to run more code than can fit in the SRAM. With C, I was looking at the old style overlays. https://en.wikipedia.org/wiki/Overlay_%28programming%29 https://en.wikipedia.org/wiki/Overlay_%28programming%29 Also want to be able to support downloadable code modules. Was looking into a Tcl dialect http://wiki.tcl.tk/1363 http://wiki.tcl.tk/1363 but I keep thinking Forth would be perfect.
- nanofortnight 11y agoI can imagine implementing a direct threaded Forth, but instead of code addresses being memory locations, code addresses are a virtual address; DOCOL and NEXT swap in the appropriate segment of code into memory where necessary. This could possibly be optimised in a subroutine threaded Forth so code within each "page" wouldn't have to verify loaded segments. Implementing a dictionary insertion/optimization routine that packs related routines together to minimise swapping would be an interesting problem, and would probably most easily not be done live but ahead-of-time instead. In short: Yes, Forth can support the paging you desire if implemented that way.
- oofoe 11y agoThe traditional FORTH "overlay" is to use FORGET. You create a dummy word to serve as a marker, like ": OVERLAY ;" or something, then later, you can "FORGET OVERLAY" and load in new code to replace it. This only affects the dictionary -- the stack and heap (if any) aren't touched. The new ANS hotness is the "MARKER" word, you just say "MARKER OVERLAY" and then you can just invoke OVERLAY later and it clears things out for you. See Elizabeth Rather's comment here: http://computer-programming-forum.com/22-forth/c67f31fe1e09b166.htm http://computer-programming-forum.com/22-forth/c67f31fe1e09b...
- deleted 11y ago[deleted]
- 11y ago