News for hackers. Stuff that matters.
Re:Writing a Forth in Haskell by sebcat on Thursday June 08, 2017 @03:26PM (#14516490)
Doesn't really give Forth the credit it deserves. Totally misses the point of Forth: the simplicity of the environment and it's relationship to the underlying hardware, defining primitives like : and VARIABLE with CREATE and DOES>, threaded code, , (COMMA) , ... Nice promotion of Haskell though
Re:Writing a Forth in Haskell by reinvdwoerd on Thursday June 08, 2017 @03:29PM (#14516519)
You're right of course, this is an ongoing exploration. I hope to learn the deeper truths in the process.
Re:Writing a Forth in Haskell by jacquesm on Thursday June 08, 2017 @03:51PM (#14516697)
I would suggest re-doing the exercise on an 8 bit cpu with < 8 K of RAM. That will open your eyes to what is so special about Forth.
Re:Writing a Forth in Haskell by brians on Thursday June 08, 2017 @04:05PM (#14516804)
One good place to look for that is <http://git.annexia.org/?p=jonesforth.git;a=summary>, previously discussed at <https://news.ycombinator.com/item?id=942684>.
Re:Writing a Forth in Haskell by jlg23 on Thursday June 08, 2017 @04:47PM (#14517071)
Thanks for the links, had not seen this before.

(though your links are slightly broken)

Re:Writing a Forth in Haskell by rwmj on Thursday June 08, 2017 @06:00PM (#14517507)
[Disclosure: I'm the author of JONESFORTH]

If you search on github there are several clones and indeed forks on JONESFORTH. It is public domain, so I welcome that:

https://github.com/search?utf8=%E2%9C%93&q=jonesforth&type=

There are also versions ported to several other architectures, which I occasionally announce on my blog (when people email me about it :-)

https://rwmj.wordpress.com/?s=jonesforth

Re:Writing a Forth in Haskell by throwaway7645 on Thursday June 08, 2017 @06:42PM (#14517728)
Thank you as JonesForth keeps getting hard to find. Any chance you will ever do an even more in-depth tutorial? Put it on lulu and I will buy. I'd like to write my own Forth, but need a bit more handholding.
Re:Writing a Forth in Haskell by rwmj on Thursday June 08, 2017 @06:44PM (#14517744)
If the tutorial is hard to find, please feel free to clone it on the git sites of your choice.

In depth: Likely not. I've actually been working on another literate language tutorial (completely unrelated to FORTH), so ... watch this space (or my blog).

Re:Writing a Forth in Haskell by throwaway7645 on Thursday June 08, 2017 @08:21PM (#14518272)
Good advice...yea I remember you saying you weren't using Forth anymore a year ago. What new language are you looking at?
Re:Writing a Forth in Haskell by rwmj on Friday June 09, 2017 @04:01AM (#14519890)
The new language is also a toy, but it's based on SML, Lisp and others.
Re:Writing a Forth in Haskell by throwaway7645 on Friday June 09, 2017 @06:52AM (#14520506)
Gotcha. I was originally assuming OCaml based off of your site.
Re:Writing a Forth in Haskell by robert_tweed on Thursday June 08, 2017 @04:03PM (#14516792)
I'm curious about Forth, as it's probably the most important language I've never learned. I've done a fair bit of low-level, micro-optimised coding in C and assembly, but don't get much time for that kind of thing these days.

How would you describe Forth in relation to those? What makes it stand out and what are its weaknesses?

Re:Writing a Forth in Haskell by jacquesm on Thursday June 08, 2017 @04:12PM (#14516856)
Forth is probably the smallest true high level language there is. It is entirely self-contained, needs just about nothing in terms of hardware support and can run in as little as 2K of memory.

It is well suited to things like real-time control, you'll probably have a hard time getting used to stack manipulation (especially in the beginning) and it tends to keep you up all night (not sure if that is a strength or a weakness ;) ).

It will also be the most fun you've had with a computer in a long time and it will likely make you look at the rest of what we do with computers as clunky in the extreme.

What Forth is not really suitable for is large projects and things built with a team. It is more of an artisanal thing, something closer to watchmaking or jewelery than major construction.

If you want to know more about why Forth is the way it is you could do worse than to start with studying the life of Chuck Moore for a bit, the language and its author are roughly equally interesting and for want of a better word peculiar.

One thing Forth is not: wasteful.

Re:Writing a Forth in Haskell by gerdesj on Thursday June 08, 2017 @05:51PM (#14517451)
I remember writing a fairly trivial program in Forth on a ZX81 for a school open day. You needed the 16K RAM pack thing with the usual lump of Blu Tac to stop it wobbling.

When I "discovered" Forth, it seemed like science fiction (soo fast!) to me after BASIC juddering around the screen.

Re:Writing a Forth in Haskell by pedrow on Friday June 09, 2017 @09:09AM (#14521058)
Probably worth mentioning the Jupiter Ace here[0] - a ZX81/Spectrum era computer which had Forth in ROM, instead of BASIC which was common at the time. The basic model only had 1K of RAM. I never used one but I remember when it came out, reviewers commented on its speed and memory efficiency.

[0]: https://en.wikipedia.org/wiki/Jupiter_Ace

Re:Writing a Forth in Haskell by nickpsecurity on Thursday June 08, 2017 @06:35PM (#14517693)
"It will also be the most fun you've had with a computer in a long time and it will likely make you look at the rest of what we do with computers as clunky in the extreme."

Double true if one looks at the hardware and software Chuck Moore makes with it.

Re:Writing a Forth in Haskell by rezaprima on Thursday June 08, 2017 @06:57PM (#14517827)
Can you tell me the link?
Re:Writing a Forth in Haskell by nickpsecurity on Thursday June 08, 2017 @09:36PM (#14518607)
Re:Writing a Forth in Haskell by PeCaN on Thursday June 08, 2017 @11:05PM (#14518906)
http://www.greenarraychips.com/ is his current company, mostly notable for extremely low-power chips using asynchronous circuits (i.e. there's no central clock). IIRC he develops the CAD software he uses to design chips on his own chips.
Re:Writing a Forth in Haskell by throwaway7645 on Thursday June 08, 2017 @04:38PM (#14517009)
Read Chuck talk about OKad...when the hardware wasn't to his liking he built his own chips...after writing his own CAD software in only like 5k loc that runs waay faster than traditional CAD software and uses almost no resources.
Re:Writing a Forth in Haskell by yumaikas on Saturday June 10, 2017 @04:58AM (#14526667)
Do you think that a concatenative language could be suitable for a team to use?
Re:Writing a Forth in Haskell by flavio81 on Friday June 09, 2017 @02:10AM (#14519474)
Last time i did some coding in forth, it was Fig-Forth on the 8-bit Atari 800XL. It was really fun and I was amazing on how fast it could run despite being in such limited hardware.

I would say Forth is easier to use than assembly, and perhaps much more flexible/extensible than C, although in some senses lower level since C gives you a very nice, ordered way of specifying what are the arguments to your functions/etc.

Re:Writing a Forth in Haskell by Karrot_Kream on Thursday June 08, 2017 @04:32PM (#14516974)
In addition to other comments:

Forth is a really cool language, but has the pitfall of trading time for space. It's a very lean language, and incredibly dynamic, but its heavy reliance on jumps makes it run slowly on modern hardware and thrashes most branch predictors.

Re:Writing a Forth in Haskell by astrobe_ on Thursday June 08, 2017 @05:48PM (#14517429)
The branch prediction problem is true for every language that doesn't JIT (pronounced: "cheat"). Furthermore, Forth is not limited to threaded code. You can have some simple code generation (subroutine threaded code+some primitive inlining) if you really want to prioritize speed. Finally, Forth is a simple language with simple implementations so it's often easy to add the primitive(s) you need in order to deal with the bottlenecks.
Re:Writing a Forth in Haskell by coliveira on Thursday June 08, 2017 @04:39PM (#14517018)
Modern CPUs are optimized for C code. This is not the fault of FORTH, but it certainly is a problem for its adoption.
Re:Writing a Forth in Haskell by throwaway7645 on Thursday June 08, 2017 @06:54PM (#14517801)
This is why Chuck Moore designed his own chips like GreenArrays I believe. There is no impedance mismatch between software and hardware and the entire thing is optimized for the problem domain and massively parallel. I'm sure you can get more speed out of C, but it no other language (even Lisp or Smalltalk) can the user understand the entirety of the system. Lisp machines and Smalltalk machines probably are about as close as possible, but I have zero experience with them personally. Perhaps the project to put PicoLisp on bare-metal qualifies if one uses a simple enough microcontroller as the language itself is about as simple as you can get a practical lisp.
Re:Writing a Forth in Haskell by spelc on Friday June 09, 2017 @06:22AM (#14520399)
Over the last twenty years or so, I have written serious Forth code generators for six CPU architectures. There's only one code generation algorithm that's not regularly present in most Pasgol family compilers. The results are the VFX Forth systems at http://www.mpeforth.com.
Re:Writing a Forth in Haskell by Karrot_Kream on Friday June 09, 2017 @01:28PM (#14522858)
I've looked over your products over the years and been super impressed by your results. Thanks for all your hard work!
Re:Writing a Forth in Haskell by Karrot_Kream on Thursday June 08, 2017 @05:31PM (#14517345)
Not really, modern Lisps have done a fine job optimizing performance. FORTH suffers from treating the hardware too granularly, and thus not being able to take advantage of any of the advances in hardware in the last 2 decades.
Re:Writing a Forth in Haskell by yorwba on Thursday June 08, 2017 @11:37PM (#14519015)
There is no a priori reason FORTH can't take advantage of modern hardware, since in the extreme case the compiler can be completely replaced by redefining the meaning of ':' and ';'.
Re:Writing a Forth in Haskell by nickpsecurity on Thursday June 08, 2017 @03:42PM (#14516635)
Feel free to have fun with Haskell and Forth all you like. Your project. :) However, you need to learn C and/or ASM then implement Forth and some system codeto get to the deeper truths. Probably. Quite a bit of people using it in embedded systems.
Re:Writing a Forth in Haskell by spc476 on Thursday June 08, 2017 @11:36PM (#14519007)
If you can get DOES> working, you really understand how Forth works. I have a toy Forth implementation where I got DOES> working, and I still have a hard time understanding how I got it working.