26 ms·
Forth vs Lisp
- dang 5y agoOne old thread: Forth vs Lisp - https://news.ycombinator.com/item?id=2243877 https://news.ycombinator.com/item?id=2243877 - Feb 2011 (15 comments)
- zerr 5y agoAny reasons to code in Forth these days, besides intellectual exercise?
- qsort 5y agoIt's very easy to bootstrap and can be made Turing-incomplete if needed. Bitcoin script is a Forth IIRC.
- whartung 5y agoSpeaking of this, I've always loved this paper [1] about Forth. And it's a real eye opener. It's a real eye opener when you understand that primitives such as assignment and variable references are, indeed, in Forth, actual primitives. Primitives that can be readily changed. Combine this with a venerable Forth (cross)assembler and it's pretty powerful for all of its simplicity. This is bootstrapping without even a boot, just need a sniglet. [1] https://pygmy.utoh.org/3ins4th.html https://pygmy.utoh.org/3ins4th.html
- rbanffy 5y ago> It's very easy to bootstrap Indeed. In college, I designed a stack based CPU that made it trivially easy to build a Forth compiler for it. It also had registers, because I started with a register based design, but the microcode fleshed out stack based instructions and the registers were mostly for storing data outside the stack.
- RodgerTheGreat 5y agoChuck is quite fond of indexing registers on his forth machines; they make operations like memory copies much less messy than exclusively keeping state on the parameter stack.
- nmz 5y agoThis? https://youtu.be/55234oZ0EDU https://youtu.be/55234oZ0EDU factor[1] also looks like a nice language. In reality though? we should only code in CPP/C/JS [1] https://factorcode.org/ https://factorcode.org/
- int_19h 5y agoBootstrapping a development environment on an exotic and/or very resource-constrained platform. The neat thing about Forth is that, once you have the kernel running, and can hook some simple I/O to it (e.g serial), you basically have a remote REPL. And this can be made to work on devices where RAM is measured in kilobytes.
- eatonphil 5y agoIt's about as fun and easy to implement a simple thing that looks like a forth as it is to implement a simple thing that looks like a lisp. But that's where the ease of forth ends for me. I find forth basically impossible to read even when, at best, authors leave a comment on basically every 1-2 words. Writing it is pretty hard too. In contrast it's about as easy to be productive in a lisp (CL or Scheme) as it is in Python or JavaScript (give or take useful 3rd party libraries). Even if they're from the same time period and are interesting for being not very Algol-like, I don't think it makes a lot of sense to discuss Forth and Lisp in the same conversation. They were both improvements on very different things.
- voxl 5y agoThis is just personal preference. I find lisp impenetrable and parenthetical soup. But I can read pipelined function calls (in e.g. OCaml or Haskell) easily.
- eatonphil 5y agoMy point is that Forth's general goal is to be a higher-level assembly language for embedded systems. Common Lisp and Scheme's general goal is to be a high-level programming language for application development (also PL research in Scheme's case). By general goal I mean what you could ultimately guess the focus is based on the implementation decisions and how the community uses the implementations. They both do a good job but in very different situations.
- Karrot_Kream 5y agoAt high levels (meaning you've built up some nice Forth words), I disagree. The main difference is that most Lisps and Schemes have a GC, so you're not in charge of allocating/freeing memory like you would in Forth. That doesn't stop Forth words from implicitly referring to a variable that actually contains memory allocation addresses and hiding the actual underlying details of the allocation. I think Forth certainly starts you out at a level of abstraction only somewhat more rich than an assembler while a Lisp runtime certainly abstracts more away from you, but once a Forth has been built-up, they become similar. Gforth gets a lot of flack in the Forth community for not being minimal, but it's a good example of a feature-rich Forth with support for things like exceptions, filesystems, sockets, and more. The Forth community itself is split into broadly two camps. The minimalist camp, (where Chuck Moore likes to live) which believes in bringing up custom Forths for custom platforms, creates small Forths that try to limit abstraction. The more featureful ANS Forth community tries to focus on a more batteries-included experience and these have more in common with most Common Lisp and Scheme runtimes.
- lizknope 5y agoI remember using some Sun workstations in the 1990's. They Open Firmware boot system used Forth. It was also used for PowerPC Macs but I never had any of those. https://en.wikipedia.org/wiki/Open_Firmware https://en.wikipedia.org/wiki/Open_Firmware
- agumonkey 5y agoopen firmware was still default in mac up until ~2008 (I bought a mac mini to play). I'm not sure it's still there though.
- rbanffy 5y agoAll Intel Macs use EFI.
- eatonphil 5y agoThe FreeBSD bootloader was written in Forth for a while. It looks like they may have transitioned off it to Lua by now. https://marc.info/?l=freebsd-current&m=153469833911665&w=2 https://marc.info/?l=freebsd-current&m=153469833911665&w=2
- spijdar 5y agoOpen Firmware is still used by IBM Power servers, although not as the "actual" bare metal firmware[1]. It's instead the default firmware interface for the standardized "VM", PAPR. A cut-down variant called SLOF is shipped with QEMU for this purpose, either for full emulation, or combined with KVM on Power hardware for accelerated virtualization. [1] Technically there's nothing preventing bare metal hardware from implementing PAPR, but to my knowledge, no currently produced hardware does. Same direction that Sun went with their servers late into the game, not long before their acquisition; sun4v ran everything inside LDOMs, with the default configuration giving all resources to a single LDOM, IIRC.
- codezero 5y agoI was playing with my old iBook from around 2000, and I needed to dig into the open firmware commands to set up network booting. Back in 2000 I didn’t know or care about Forth but since the pandemic I’ve gone down a few Forth rabbit holes (thanks CollapseOS!) so it was fun to know what was behind the scenes of the boot interface :)
- macintux 5y agoAs someone who has only barely dabbled in either, they feel very similar in philosophy, but I understand that's superficial to some degree. I have a particular soft spot for Forth in part because W. Richard Stevens (RIP) wrote a primer for Kitt Peak National Observatory: http://www.forth.org/KittPeakForthPrimer.pdf http://www.forth.org/KittPeakForthPrimer.pdf (PDF)
- mananaysiempre 5y agoVery similar philosophies re building up abstractions, DSLs and DSL-enabling syntax (half of Thinking Forth is essentially proselyzing DSLs), very different philosophies re lowest level of abstraction accessible in the language and compound datatypes. I’d say that neither of those are superficial.
- joe_the_user 5y agoThe upshot of the discussion seems to be that the definitions of a Lisp and a Forth are so orthogonal that one person correctly say "most lisps have no relations to forth and vice versa" and another can correctly say "look, a lisp that's also a forth". How conceptual orthogonality works.
- mikewarot 5y agoAs someone who has written a forth, and knows a tiny sliver of what lisp can do, the huge difference is that Forth can't deal with arbitrary data structures in anything close to the ease of Lisp. If you want to ingest a chunk of source code, tokenize, parse and put it all in an abstract syntax tree, you're far better off doing it in lisp. Forth doesn't really do data structures. Stoical is a forth variant that did, but it died out.
- 7thaccount 5y agoThere are a lot of Lisps out there, but even more Forths (like the one you've written), although people like to argue what it means to be a Forth. One desktop/server Forth that I have enjoyed is 8th and it is a Forth in the since that it is a concatenative language using words and a stack, but it also is like GForth in that it comes with garbage collection, while it also has support for various data structures like arrays/maps/JSON/matrix, file IO, GUI, database, cross compilation...etc. It still takes my brain awhile to use, but my workflow is pretty similar to the one I use with Python.
- mostlylurks 5y ago>Forth doesn't really do data structures It doesn't hand you a ready-made solution due to its extreme minimalism, but that doesn't mean that you can't have arbitrary data structures (and have them be quite ergonomic). All it takes is a handful of lines (each) to have words for defining C-like structs, sum types, separate stacks for distinct datatypes, RAII, even generics. You only need to implement these things once, afterwards you can simply reuse that solution. To expect the language, standard library, or popular frameworks to provide all the abstractions one will ever need is unfortunately a very common attitude these days. In general, but particularly in the case of forth, it is very beneficial to understand that you are allowed to make your own abstractions. Nothing is forcing you to stay on the lowest levels of abstraction, where you only directly utilize tools the language has given you. In fact, such an approach is quite antithetical to writing forth.
- andrewflnr 5y agoThere's a very good reason for this "common attitude", and it is network effects with their benefits for productivity. If the standard library includes a useful abstraction, then your code and my code that use that abstraction have an easier time interoperating, and so does the entire rest of the world. That's really handy.
- User23 5y agoI'm quite familiar with many Lisp dialects, including Emacs Lisp, Common Lisp, and Clojure, and I'm moderately familiar with Scheme too. I'm not a stranger to other outside the mainstream languages like OCaml and Haskell. However, every time I've tried Forth I've bounced off it hard. Has anyone here had a similar experience and managed to overcome it? I really want to learn Forth because I believe learning new paradigms makes me a better programmer and it's also fun. So how can I make learning Forth fun? And on a tangent, it's nice to see posts from the original Wiki. I spent a lot of time on that site a couple decades ago.
- eatonphil 5y agoIt's the most fun to me when I'm writing (or copying) programs in it for an implementation I wrote. So, write a forth implementation and add programs to benchmark or test it. You'll learn (parts of) it quickly!
- int_19h 5y agoI've found that the best way to truly grok Forth conceptually is to implement one yourself - and I don't mean a toy interpreter, but the real thing producing basic threaded code. Then you understand why it is the way it is, and what its strong sides are. Starting with a book that merely describes how to use it like any other PL just leads to questions like "why is this so weird?". Jones Forth is a common starting point - it has more comments than actual code, explaining the design in detail: https://github.com/nornagon/jonesforth/blob/master/jonesforth.S https://github.com/nornagon/jonesforth/blob/master/jonesfort...
- Karrot_Kream 5y agoThe reason I don't like building a Forth as an introduction to Forth is because it has you stop at the lowest level of abstraction a typical Forth program is written in. Forth is all about building layers of abstraction for yourself. If you're marching toward implementing a system with a set of words others have written about then you aren't really getting the practice in building your own abstractions that help writing Forth applications. It's why a lot of the Forth community laughs that most people come, write a Forth, then leave. A real Forth application can get quite high-level but it's up to you and your collaborators to design that tower of abstraction. I prefer a different approach myself. Start by writing small scripts, stuff that you've already written in other languages, in a full-featured Forth like Gforth. Once you feel comfortable doing that, start building small applications in Forth. Eventually, write bigger applications in Forth. Only shrink your base Forth vocabulary once you feel comfortable in a full-featured Forth like Gforth.
- rbanffy 5y agoIt was with Forth that I learned to build up the language until solving the problem becomes trivial. Of course, this can be done with any language, but Forth and Lisp make it look natural.
- shaunxcode 5y agoOr you could have the best of both worlds: https://github.com/schani/forthlisp https://github.com/schani/forthlisp
- klyrs 5y agoWhy not both? And throw in Python to boot? https://github.com/asrp/flpc/ https://github.com/asrp/flpc/
- RodgerTheGreat 5y agoTheir example of "Forth-like" syntax looks absolutely nothing like any Forth I've used. The "F'" version more closely resembles Factor or Joy, if anything.
- klyrs 5y agoYou're not wrong. I'd say it kinda does all three badly. But the gestalt is fun
- qgc 5y agoThey have some great live coding demos [0] on their blog [1]. [0] https://blog.asrpo.com/jit_programming https://blog.asrpo.com/jit_programming [1] https://blog.asrpo.com/ https://blog.asrpo.com/
- DonHopkins 5y agoForth * Lisp = PostScript
- protomyth 5y agoI have often thought of writing an interpreter to run a PostScript clone without the graphic primitives but adding some words dealing with files. PostScript does have a lot of fun extras.
- DonHopkins 5y agoCoco Conn and Paul Rother wrote this up about what they did with FORTH at HOMER & Assoc, who made some really classic music videos including Atomic Dog, and hired Charles Moore himself! Here's what Coco Conn posted about it, and some discussion and links about it that I'm including with her permission: Peter Conn: https://imgur.com/a/4Bmb4xu https://imgur.com/a/4Bmb4xu Homer & Associates (1982): http://leftbrain.us/rotherHistory/homer.html http://leftbrain.us/rotherHistory/homer.html Peter Conn Papers at Stanford: https://library.stanford.edu/blogs/special-collections-unbound/2019/05/peter-conn-papers-available-research https://library.stanford.edu/blogs/special-collections-unbou... https://oac.cdlib.org/findaid/ark:/13030/c8n303pn/entire_text/ https://oac.cdlib.org/findaid/ark:/13030/c8n303pn/entire_tex... George Clinton - Atomic Dog (Official Music Video) HD https://www.youtube.com/watch?v=LMVZ36VA0wg https://www.youtube.com/watch?v=LMVZ36VA0wg Steve Miller Band - Abracadabra https://www.youtube.com/watch?v=tY8B0uQpwZs https://www.youtube.com/watch?v=tY8B0uQpwZs Steve Miller Band - Bongo Bongo https://www.youtube.com/watch?v=_NrsRZdMI-A https://www.youtube.com/watch?v=_NrsRZdMI-A Flying Logos for 1989 Siggraph Electronic Theater: https://www.youtube.com/watch?v=9hIOfEiy4lc https://www.youtube.com/watch?v=9hIOfEiy4lc >First shown at the 1989 Siggraph Electronic Theater to a rave response, this 3 minute humourous film went on to win several top computer graphic awards that same year including Niccograph of Japan. >Coco: This was a show favorite at the SIGGRAPH film show that year. The year before the conference committee decided that showing demos wasn't the way to go anymore. Peter wrote Flying Logos as a way to sneak our demo reel into the show by turning it into a story. It worked and we made it into the film show. >Don: I truly believe that in some other alternate dimension, there is a Flying Logo Heaven where the souls of dead flying logos go, where they dramatically promenade and swoop and spin around each other in pomp and pageantry to bombastic theme music. It would make a great screen saver, at least! Somewhere the Sun Logo and the SGI Logo are still dancing together. ---- Peter Conn and I [Coco Conn] had a company called HOMER & Assoc. which was located at the Sunset Gower Studios from 1977 until we closed shop in 1997. We made music videos, commercials & computer graphics/special effects for feature films. One cool note, we worked with Paul Verhoven on both RoboCop in 1986 and the x-ray scene for Total Recall in '89. HOMER was actually a real time visual mixing console that our in-house engineer spent 1978 - 1981 designing and building, from scratch. The name HOMER stood for "Hybrid Optical Montage Electronically Reproduced." I helped as well, soldering the LEDs on the console and running cables. Peter built his own optical printer and three years into the build we also bought an early computer paint system. Our engineer finished building the console and promptly decided to move to England. We hadn’t used it because we still hadn’t found the right software to run the system. Luckily that’s when Paul Rother joined the company. The joy stick on our console would bump you to the next line of code (being a command or sequence of events: fade, cut, dissolve, etc.) The console had touch sensitive fader pads. There were no dials. I think they were made by Allison? Each channel (which controlled either a slide projector or a film projector) was touch sensitive. After recording a sequence we could then tweek the current version using additional effects the channels offered such as momentary, additive, on/off, etc. For instance if you wanted to crossfade two images, you could either program it or perform it. Of course everything you did was recorded and would play back on the next round. You literally performed a sequence of visual effects with your hands. Peter would do countless passes until everything was perfect. This performance would then be played back to IP film on the optical printer. Each slide tray or film real would be individually run, one by one, to IP film. Sometimes there would be 10-15 or more passes to get all the elements transferred. Once that was done we would then convert the IP film to video and do additional video editing and effects. A totally nuts analogue system. But it worked. --------------- HOMER Explained by Paul Rother, in-house programmer, (1982): The photo is Paul sitting in front of the Optical Printer 7-bit Paint system, Homer and Associates, circa 1982. Homer and Associates was really one of a kind kinda of company. Founded by Peter Conn, originally I got hired to program Homer II, a visual realtime mixing console. Homer I is another whole story, but before my time. Homer II consisted of 16 slide projectors, 4 movie projectors, a 4 track tape recorder, 24 visual channels (each with its own Z80) touch sensitive sliders, a master Z80 S100 bus system and featuring "the joy stick bumper " control, which looked liked the gear shift right out of a 1964 mustang convertible. The idea was that you would program a visual sequence, then play the sequence in sync with the sound track on the joystick, including cascades, bumps, cuts, etc. The whole thing would be recorded, and if you wanted to, like an audio mixer, go back and do over dubs, making corrections. Then once you had the perfect "hero" recording, you take the 8" floppy disc with the hero recording and the trays of slides to the optical printer, and record it to IP motion picture film, making multiple passes, one tray at a time. Now that I think about it, it was a crazy idea. We actually got the whole thing to work. And it worked great! Forth & Charles Moore We hired Forth, Inc. and got Charles Moore, the inventor of FORTH to program the console host computer. I learned FORTH and worked with Charles. I programmed the 2K byte EPROM in each visual channel. On the Master Z80 system we ran PolyForth a multi tasking system in 32K bytes. We had an extra 16K RAM for buffers and things. If I remember right, the system ran four tasks, but that was 20 years ago, my memory may be hazy. Anyway, I learn not only FORTH from Charles Moore, but also how to factor code in to small reusable routines, WORDs they're called in FORTH. I learned Object Oriented Programming without knowing it. Also a lot of use of vectors. Its a cool language. Charles Moore was a great inspiration to me, and really taught me a great deal that they never taught me in computer programming school. CAT-700 After we got the basic Homer II working and were able to record on the optical printer, Peter had another idea. He wanted to be able to see the movement of the optical printer, and see a prior frame compared to the current frame. We already had a video assist on the Fries Mitchell 35mm. What we needed was a Frame Buffer. We heard of S100 video board called the CAT-100, which was 1-bit frame buffer, good enough for what we needed. Somehow we never found a 1-bit version, but we found 7-bit version in the recycler! We flew to Reno, rented a car and drove to a log cabin up in the hills of Truckie California. We got a demo of the thing. The guys were super secret and didn't want us to see the controlling program. It worked, so we bought it, and then flew onto Palo-Alto and met the French guy who designed it. They checked it out and it was OK. This was the days before computer designed boards, and all the traces on the board were curvy, kinda like a Van Gogh painting. We learned that it was 7-bit (CAT-700) because it would have been an 8-bit, but they could not get the 8th bit to work. We spent the night in Palo Alto with a Stanford friend of Peters working on a crazy secret Apple project, the Lisa. 32KByte Paint System So I got the CAT-700 frame buffer to work, programmed in FORTH. So in that 32K we had an optical printer control system, and a paint system, all in one. (Also the OS, compiler, debugger, etc.) We later hooked up a Summigraphic Bitpad (before the Watcom tablet) and were able to draw on top of digitized frames. It got to the point where we needed TWO optical printers, one to digitize from film, and the other to record to film. Rube Goldberg is not strong enough descriptive to describe the system, with the filter wheels and all on stepper motors, it made music. The first use of the system was effects for Steve Miller Music Video, Abracadabra. I also remember using it on the George Clinton Video, Atomic Dog. This photo was taken right after we got the system to work. I had hooked up an analog slider box, which controlled things like color. There were 4 color maps we could switch between instantly We did a lot of work in planes, using 2 planes for the original image to be rotoscoped, and the other 5 planes to draw onto. This photo was taken for an article in Millimeter Magazine. The photo ended up being a two page color spread, and I think Peter was pissed, cause I got premier exposure. TTL logic At Homer and Assoc. I also learned TTL logic and designed a number of computer boards for the S100 bus. One that controlled stepper motors with a timer chip (Motorola 6840). Another to control the Slide Projectors also using the same Motorola timer chip to control the lamp triacs. My favorite thing, about the system, was the use of the cassette storage interface as a cheap timecode reader/writer.
- z0ltan 5y agoThey both suck. That's about it.
- perth 5y agoDoes Forth have a purpose when TCL exists?
- detaro 5y agoI'm curious why you see TCL as a "competitor" to Forth?
- perth 5y agoThe entire Python default windowing system relies on TCL, and companies like AMD use it for a lot of their internal test frameworks because it's easy to implement and well supported. So for embedded, which is people's argument for fourth, TCL is way more useful as evidenced by it winning the industry.
- detaro 5y ago... the argument for Forth embedded is usually Forth directly on hardware, not "embedded into another app" like TCL?
- luizfelberti 5y agoDoes TCL has a purpose since Forth exists? Serious question. TCL being stringly typed makes it dead on arrival for me, and I'm sure others feel the same.
- perth 5y agoExtremely widespread embedded support and cross platform. Forth seems dead to me, whereas TCL is huge and has good docs, a good standard library with batteries included, and it's easy to implement on embedded hardware because of how well documented it is. Also the inherent linkage to Python keeps it relevant.
- sneeeeeed 5y agoX86 forth is brilliant. I just got the GA144 dev board - I have a product in mind and I used several forths in the last year. X86 forth among them.
- spc476 5y agoIs there anyone else having issues reading the site? I'm using the latest version of Firefox, and I get: This site uses features not available on older iPhones. I'm interested in reading the site, not editing it. I'm already using a web browser, I don't need to download one written in dodgy Javascript. Sigh.