Live data from Hacker News

Writing a Forth in Haskell

reinvanderwoerd.nl

21–30 of 55 posts

Re: Writing a Forth in Haskell

#21
post #16
post #10

Earlier quoted context omitted.

One good place to look for that is " rel="nofollow">http://git.annexia.org/?p=jonesforth.git;a=summary> , previously discussed at " rel="nofollow">https://news.ycombinator.com/item?id=942684> .

Thanks for the links, had not seen this before. (though your links are slightly broken)

[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

#22

Earlier quoted context omitted.

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?

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 we…

"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

#23
post #21
post #16

Earlier quoted context omitted.

Thanks for the links, had not seen this before. (though your links are slightly broken)

[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

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

#24
post #21

Earlier quoted context omitted.

[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

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.

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

#25
post #2

Surely you just take an existing LISP implementation and call "reverse" at the correct location in the code? :p

Even at the most basic level, Forth and lisp are quite different. Lisp has grouping and evaluates using a tree. forth has no grouping* and evaluates completely linearly.

* well you can hack it to give it grouping, but usually it doesn't.

Re: Writing a Forth in Haskell

#26
post #6

I think it's also valuable to take a look at how Joy handles quoting program fragments. I just wish there were better online resources around the language.

Links? When I tried I just used "[" to construct an empty dynamic array, and pushed words into it until I found "]". Very inefficient, but simple.

Re: Writing a Forth in Haskell

#27

Earlier quoted context omitted.

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.

Modern CPUs are optimized for C code. This is not the fault of FORTH, but it certainly is a problem for its adoption.

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

#28

Earlier quoted context omitted.

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 we…

"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.

Can you tell me the link?

Re: Writing a Forth in Haskell

#29
post #2

Surely you just take an existing LISP implementation and call "reverse" at the correct location in the code? :p

Even at the most basic level, Forth and lisp are quite different. Lisp has grouping and evaluates using a tree. forth has no grouping* and evaluates completely linearly. * well you can hack it to give it grouping, but usually it doesn't.

Lisp's abstract model doesn't use stacks to pass arguments. Arguments are just lexical variables and they live in environments like other lexical variables: completely foreign stuff to Forth. Environments often have to survive the termination of a lexical scope's execution; it is required when a closure has escaped. So things can't even be compiled to a stack-based machine, using a "pop everything when returning" strategy: only in some cases.

(ANSI) Lisp function calls are safe w.r.t. wrong number of arguments, and support optional and variadic arguments also. This is true of compiled code without source: when we load someone's compiled file and call a function in it with the wrong number of arguments, it is diagnosed.

Forth and Lisp are so miles apart, that I have to scratch my head why a comparison comes up in discussion from time to time.

(It is pretty much always from someone who uses Forth and doesn't know Lisp (or, worse, anything that isn't Forth). "Hey, I heard Lisp is also interactive and meta-programmable, so it must just be a Forth with postfix switched to prefix and parentheses added ...").

Re: Writing a Forth in Haskell

#30
post #2

Surely you just take an existing LISP implementation and call "reverse" at the correct location in the code? :p

Even at the most basic level, Forth and lisp are quite different. Lisp has grouping and evaluates using a tree. forth has no grouping* and evaluates completely linearly. * well you can hack it to give it grouping, but usually it doesn't.

Or in other descriptive terms, Forth could be called "point-free" or "tacit". There is no structure given by the code's context, no named arguments to describe what is in scope - all you have is what is on the stack at the moment of execution, and global variables that the program might access by convention.

Point-free can be a very concise and flexible strategy but also error-prone since (in Forth) it allows the stack to leak and consume/return an unbalanced quantity of arguments. This class of error is eliminated within the syntax of Algol style languages languages but can be reproduced easily if you build your own stack machine.

Post reply on HN