4 ms·
A while ago I came across Factor¹, which calls itself "a practical stack language"; it has the same basic (lack of) syntax as Forth, but has a Common Lisp-inspi
by thristian 15y ago
A while ago I came across Factor¹, which calls itself "a practical stack language"; it has the same basic (lack of) syntax as Forth, but has a Common Lisp-inspired object system, garbage collection, and a standard library whose scope resembles Python's.
I haven't actually written anything in it yet.
Partially, it's because of work-flow issues - Factor doesn't lend itself to hacking on source-trees outside the Factor source tree, and I'm not sure how I'd set up a single-button "run all the tests" command, for example. Partially it's an issue of finding the right project - being a new language and a new paradigm, I'd want to start off with something simple, but not so simple that I'd be tempted to dash off a half-dozen lines of Python and move on.
A good chunk of it, however, is because of articles like this one (in fact, probably this very article I read on Hacker News some months ago) that make me despair of ever making code that will be as simple and efficient as the code-samples I've seen — the Python community calls Python code that goes with the grain of the language as "Pythonic"; I'm not sure what Factor's equivalent adjective would be ("Factorial"?).
¹: http://factorcode.org/ http://factorcode.org/
- rsaarelm 15y agoI 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.