Category:Factor: Difference between revisions
m
Add link to unimplemented tasks
m (change a date) |
m (Add link to unimplemented tasks) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 1:
{{language
|exec=machine
|site=
|gc=yes
|parampass=reference
Line 13:
Factor is a stack-based, concatenative, general-purpose programming language with a focus on practicality.
Initially developed by Slava Pestov, Factor began life in 2003 as a scripting language written for a game. The implementation was originally an interpreter written in [[Java]], but has since gained an optimizing compiler and has been rewritten in Factor with a minimal [[C++]] core. Read more about Factor's implementation history [
Factor is a stack language similar to, but of a higher level than, [[Forth]]. Factor is a [
In Factor, we tend to name data flow operations rather than values. In an applicative language, you might write
<
var y = foo(x);
var z = bar(x);</
In Factor this is a data flow pattern called <code>bi</code>.
<
This says, "apply <code>foo</code> to the object at the top of the data stack, and apply <code>bar</code> to it as well." Rather than naming the values <tt>x</tt>, <tt>y</tt>, and <tt>z</tt>, we named the data flow pattern.
Factor comes with many practical features, including a [[Interactive programming (repl)#Factor|REPL]], a self-contained help browser, an object inspector, a debugger/code walker, a deployment tool, editor integration for most popular text editors and
Most code tends to be expressed naturally in a functional manner. Factor comes with combinators (higher-order functions) typically seen in functional languages, such as <code>map</code>, <code>filter</code>, <code>reduce</code>, and many more. Although most things can be done efficiently without mutation, Factor doesn't shy away from it when it's useful. Mutating words end with exclamation points (by convention). Factor provides lexical and dynamic variables which can make writing imperative code more natural, or allows one to clean up code that performs a lot of stack shuffling.
One of Factor's greatest strengths is its ability to factor words into smaller words. Due to the nature of [[concatenative programming]], this is typically a cut and paste job that can be done almost anywhere there is whitespace. Factor also has impressive metaprogramming capabilities. Since Factor is almost entirely written in Factor, there is full introspection support, including seamless access to Factor's parser, allowing one to define new syntax. Factor also offers [[Lisp]]-style macros, and in general, Factor code can be treated like a collection ([https://en.wikipedia.org/wiki/Homoiconicity homoiconicity]).
==About Factor examples on Rosetta Code==
Most of the newer examples are meant to be copied and pasted directly into the listener (Factor's REPL) where they should run without issue. In order to deploy the examples to binaries or run them as scripts, you'll need to put them in a vocabulary (e.g. <code>IN: myvocab</code> and set a <code>MAIN:</code> word which acts as the entry point for the program. If an example doesn't run, it probably means that the example only works in an older version of Factor. Most of the time, this is because certain words have been changed without maintaining backwards compatibility (e.g. <code>iota</code> became <code><iota></code> in Factor 0.98).
For this reason, it is advised that examples use the <code>works with</code> template to indicate which version of Factor the example works with. For example,
<pre>{{works with|Factor|0.98}}</pre> becomes
{{works with|Factor|0.98}}
==Todo==
[https://rosettacode.org/wiki/Tasks_not_implemented_in_Factor Tasks not implemented in Factor]
==Links==
*[
*[
*[
*[https://en.wikipedia.org/wiki/Factor_(programming_language) Factor on Wikipedia]
|