Earlier quoted context omitted.
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" str…
Writing a Forth in Haskell
51–55 of 55 posts
Re: Writing a Forth in Haskell
#52Earlier 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…
Re: Writing a Forth in Haskell
#53Can anyone point me to a Forth implementation where the absolute bare minimum is written in (C/assembly/whatever) and everything possible is then bootstrapped in Forth itself? I recall reading what the minimal word set needed to be able to write the rest of standard Forth (Fig Forth if I recall) but I seem to remember that most implementations don't push the purity quite that far for performance reasons.
I did exactly this, was curious if I could write an outer and inner interpreter in pure c in under 500 lines with only 5 c functions. I then used that to boot strap an image that can run using only the inner interpreter.
http://chiselapp.com/user/tehologist/repository/compc/index
Also several experimental versions. Final version includes a pdf that documents how the c code works.
Re: Writing a Forth in Haskell
#54Can anyone point me to a Forth implementation where the absolute bare minimum is written in (C/assembly/whatever) and everything possible is then bootstrapped in Forth itself? I recall reading what the minimal word set needed to be able to write the rest of standard Forth (Fig Forth if I recall) but I seem to remember that most implementations don't push the purity quite that far for performance reasons.
Re: Writing a Forth in Haskell
#55Earlier quoted context omitted.
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" str…
I had this dumb idea of actually evaluating LISP in a forth inspired way. It would be a stack of subroutine/accumulator pairs. so given (+ 1 2 3) "(" would pop an pair on a stack, + would set its subroutine, and 1 2 3 would be fed to the subroutine and accumulate a value. when ) is encountered, the data is fed into the subroutine/accumulator pair lower on the stack, so you could still have nesting. Horribly inefficie…