4 ms·
I don't have any Forth background, but have written a significant amount of Factor code during the last year. I haven't really run into things that seem painful
by rsaarelm 15y ago
I don't have any Forth background, but have written a significant amount of Factor code during the last year. I haven't really run into things that seem painful or complicated to express in what I hope to be idiomatic Factor. The project I've been working on is an interactive game, so it's neither entirely trivial nor something that a concatenative language is obviously a particularly good fit for.
The main difference from Forth are the ubiquitous quotations, Factor's equivalents of a lambda expression, which make the idiom clean and quite like a functional language. For example, Factor's `if` conditional isn't a macro like the Forth one, it's just a regular word that takes a truth value and two quotations, and then calls either the first or the second quotation based on the truth value. There are also many combinator words like `bi` or `cleave` that operate on the quotations that don't have Forth equivalents as far as I know. A good deal of being able to write idiomatic Factor is being able to use the standard combinators.
For tricky things like complex equations that aren't easy to express in pure stack manipulation Factor has the local variable library, which allows easy repeated referencing of the inputs, so doing something like a closed form solution of a quadratic equation can be done without incomprehensible stack acrobatics.
The work-flow is a bit tricky though. I like setting up automated machinery running from the command line, and Factor likes to live in an image, SmallTalk style. I guess the idea is to just write the support machinery in Factor as well, and use the Factor REPL as the interactive workflow control site and short Factor scripts for automated command-line stuff.