9 ms·
Advanced Forth Programming Topics
- i_feel_great 10y agoWhich Forth has a "good" standard library?
- mikekchar 10y agoKeep in mind that it has been decades since I was a FORTH programmer. I'm half fearing and half hoping someone will correct what I'm about to say :-) Essentially, you want FIG FORTH. Virtually anything will give you that. Remember that FORTH doesn't really have libraries. It's more like Smalltalk where you have a running environment of loaded code. Generally you want to have a small kernel and then load only the words that are relevant to what you are doing. For that reason, there isn't really any big standard library (that I'm aware of) like there are with other languages. FORTH words decompile really, really easily too, so mostly FORTH programmer work with source code. You just load what you need from wherever you get it. Having said that, there have historically been attempts to have libraries and create build environment, etc, etc. I'm not aware of any that achieved any universal popularity.
- undecidabot 10y agoNot Forth, but Factor (https://factorcode.org/ https://factorcode.org/) is very much inspired by Forth (also being a stack-based / concatenative programming language), and it does have a good standard library complete with your usual data structures along with extra libraries for regexp, several parsers (csv, json, xml), an http server and client, a web framework (built on top of that server with SQL DB drivers), a ui framework (via OpenGL), and even xkcd (http://docs.factorcode.org/content/article-vocab-index.html http://docs.factorcode.org/content/article-vocab-index.html). Check this blog out for some cool things you could do with Factor: http://re-factor.blogspot.com/ http://re-factor.blogspot.com/
- AstroJetson 10y agoFactor is cool, but it has some differences that may trip an experienced user. But for a first time Forth user, the extra frameworks/libraries may be a help. As pointed out below, FIG Forth has a great deal of support. All my interactions using Forth have been on underpowered systems pounding on the bare metal. So lots of the words created supported that environment. Math words and geometry words came from FIG Forth.
- swah 10y agoThe small community around Slava Pestov was (is) great... The standard library is amazing and they (used to) follow a model that has worked well for them (IRRC): the best libraries from the community become part of the distribution. If they aren't that well written, the core guys would help you express the idea better. And then it could make it into the standard library. Or the core guys would just rewrite it for you (Factor is very compact). On the other hand, if something solving that same problem was already in the standard library, there was no discussion: that problem is already solved. Happy to see that Factor still lives!
- dvdkhlng 10y agoAll of the "big" Forth systems come with some sort of standard library. In the open source world, gForth [1] is pretty well-known which comes with a comprehensive set of words [2] many are not part of the ANS Forth standard [3,4]. You could call that gForth's "standard library". For stuff that is missing, gForth has an interface to native system libraries [5]. For math and scientific computing there is the Forth Scientific Library [6] which is written in standard-conforming forth and can be loaded and used on most of the forth systems currently in use. But then Forth coders somehow live by the philosophy "if you want it to be done right you have to do it yourself", so use of library code is frowned upon and people usually tend to reinvent the wheel and writing code from scratch :) [1] https://www.gnu.org/software/gforth/ https://www.gnu.org/software/gforth/ [2] http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/ http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/ [3] https://www.taygeta.com/forth/dpans.html https://www.taygeta.com/forth/dpans.html [4] http://www.forth200x.org/documents/forth14-5.pdf http://www.forth200x.org/documents/forth14-5.pdf [5] http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/C-Interface.html#C-Interface http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/C-In... [6] https://www.taygeta.com/fsl/scilib.html https://www.taygeta.com/fsl/scilib.html
- richard_todd 10y agoClosest thing I know of is FFL (http://soton.mpeforth.com/flag/ffl/index.html http://soton.mpeforth.com/flag/ffl/index.html) which works on several FORTHs.
- snaky 10y agoOne of the most interesting modern concatenative languages - Kitten (http://kittenlang.org/ http://kittenlang.org/)
- groovy2shoes 10y agoAgreed! I haven't had so much learning a new language in a long time. Lots of cutting-edge stuff going on in Kitten, and all the concatenative goodness you hear about from Factor fans, but (imo) in a much more palatable package. Part of what makes it so palatable for me is that there have been some syntactic compromises rather than relentless emphasis on RPN. For example, rather than (as in Forth): 0 = IF foo ELSE bar THEN Kitten allows you to say: -> x; if (x = 0): foo else: bar which I personally find much easier to follow. So, you get local variables, infix expressions, and some amount of non-RPN syntax, without sacrificing any of the power you'd get from another concatenative language. I've talked to Jon (the creator) a bit off-and-on, and from what I gather there are some really neat things being planned for Kitten in the near future :)
- snaky 10y agoWhat I found most interesting it's Kitten effects (actually coeffects) system based on the system of extensible records that allow very elegant permission composition. Author of Kitten gives some explanations comparing it with Haskell at https://www.reddit.com/r/programming/comments/4mzlvi/10_lesserknown_programming_languages_worth/d422nyi https://www.reddit.com/r/programming/comments/4mzlvi/10_less...
- groovy2shoes 10y agoAha! I hadn't realized they'd officially landed already. Yeah, the effects are one of those "really neat" things I was referring to :) I've been thinking about how they could be used with a term-rewriting system for certain kinds of optimization. Some rewrite rules only apply under certain conditions that may or may not be lexically apparent in the absence of an effects system. As a simple example: rewrite {f map} {g map} compose => {f} {g} compose map ; This transformation will only work if `f` and `g` are pure functions: if `f` and `g` have side-effects, then the transformation is no longer equivalent. But using the effects system, we can give rewrite rules a sort of context that lets the rewrite system know the extra conditions necessary for a rule to apply.
- anta40 10y agoIs there any open source, cross platform Forth compiler which able to create native executables like GCC/FPC do?
- i_feel_great 10y agogForth and Factor (heavily Forth-inspired) appear to do just that.
- larsbrinkhoff 10y agoI don't see that Gforth can create executables. It can create image files, but those are not directly executable; they need to be loaded by the Gforth runtime.
- larsbrinkhoff 10y agoMy personal Forth can write Linux ELF and Windows PE executables. (I don't have access to a Mac, so OS X Mach-O is out.) http://github.com/larsbrinkhoff/lbForth http://github.com/larsbrinkhoff/lbForth
- jevinskie 10y agoDoes anyone have links to resources that speak to converting a stack machine (Forth, in my case) into SSA form (LLVM, in my case)? My first approach was to just subroutine thread everything and see how well the inliner and optimizer handles that.
- jevinskie 10y agoI did some more digging and it looks like I should read the RAFTS paper. [0] [0]: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.5.3854 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.5.38...
- akavel 10y agoIs anyone aware of any Forth or Forth-like language for JVM or (ideally) Dalvik? Ideally, with a REPL allowing to access all Android APIs and create callbacks/interface implementations... super-ideally, statically-typed... eh, one can dream. By the way, a ML-like would fit me even more. (Or a statically-typed LISP.)
- dewster 10y agoIMO, anytime the programmer has to micro-manage anything it's basically assembly (Forth forces you to micro-manage the stack). I dislike syntax which uses the <> symbols, but I'm all for RPN and postfix (in theory anyway).
- jononor 10y agoDoes imperative programming force you to micro-manage variables and arguments? For me I think the challenge is that the stack-effects are 'hidden' in the code. However, this seems like it could be solvable by compiler (typed stack effects for instance) and tooling/IDE.
- dewster 10y ago> Does imperative programming force you to micro-manage variables and arguments? I just don't think many programmers fully take into account all the trouble a stack-based language is. You're constantly rearranging the stack to get values stored on it in position to call functions and such. You know stack manipulations are inherently wasteful, and you worry about doing too many of them. So you end up micro-managing them, and often end up sacrificing readability for efficiency. And the readability of stack languages is already woefully bad. I don't really understand why they continue to exist.