Category:Factor: Difference between revisions

Content added Content deleted
m (fix code formatting)
m (update)
Line 1: Line 1:
{{language
{{language
|exec=machine
|exec=machine
|site=http://factorcode.org
|site=https://factorcode.org
|gc=yes
|gc=yes
|parampass=reference
|parampass=reference
Line 13: Line 13:
Factor is a stack-based, concatenative, general-purpose programming language with a focus on practicality.
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 [http://concatenative.org/wiki/view/Factor/Implementation%20history here]. As of June 2020, Factor is still being developed by several contributors, with the latest [http://re-factor.blogspot.com/2018/07/factor-098-now-available.html stable release] in July 2018.
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 [https://concatenative.org/wiki/view/Factor/Implementation%20history here]. As of June 2020, Factor is still being developed by several contributors, with the latest [https://re-factor.blogspot.com/2018/07/factor-098-now-available.html stable release] in July 2018.


Factor is a stack language similar to, but of a higher level than, [[Forth]]. Factor is a [http://concatenative.org/wiki/view/Concatenative%20language concatenative language], meaning that rather than applying functions to arguments (applicative languages) to evaluate things, we compose functions to evaluate a single piece of data — the entire program up until that particular point. In Factor, the basic structure of data flow is function composition. That is, <code>foo bar baz</code> is equivalent to <code>baz(bar(foo()))</code> in an applicative language. This offers a nice left-to-right style of reading and data flow.
Factor is a stack language similar to, but of a higher level than, [[Forth]]. Factor is a [https://concatenative.org/wiki/view/Concatenative%20language concatenative language], meaning that rather than applying functions to arguments (applicative languages) to evaluate things, we compose functions to evaluate a single piece of data — the entire program up until that particular point. In Factor, the basic structure of data flow is function composition. That is, <code>foo bar baz</code> is equivalent to <code>baz(bar(foo()))</code> in an applicative language. This offers a nice left-to-right style of reading and data flow.


In Factor, we tend to name data flow operations rather than values. In an applicative language, you might write
In Factor, we tend to name data flow operations rather than values. In an applicative language, you might write
Line 25: Line 25:
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.
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 REPL, a self-contained help browser, an object inspector, a debugger/code walker, a deployment tool, editor integration for most popular text editors and IDEs, and introspection capabilities useful for developers. Factor has a fully-featured library, including things such as an HTTP server/client, bindings to graphics libraries and databases, a C FFI, a cross-platform GUI framework, on down to niche things like polynomial arithmetic. Factor features an object system that takes inspiration from [[Common Lisp]] and [[Self]].
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 [[IDE]]s, and introspection capabilities useful for developers. Factor has a fully-featured library, including things such as an HTTP server/client, bindings to graphics libraries and databases, a [[C]] [[FFI]], a cross-platform [[GUI]] framework, on down to niche things like polynomial arithmetic. Factor features an object system that takes inspiration from [[Common Lisp]] and [[Self]].


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.
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]).
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==
==About Factor examples on Rosetta Code==
Line 39: Line 39:


==Links==
==Links==
*[http://factorcode.org Factor programming language]
*[https://factorcode.org Factor programming language]
*[http://planet.factorcode.org Planet Factor]
*[https://planet.factorcode.org Planet Factor]
*[http://concatenative.org/wiki/view/Factor Factor on concatenative.org]
*[https://concatenative.org/wiki/view/Factor Factor on concatenative.org]
*[https://en.wikipedia.org/wiki/Factor_(programming_language) Factor on Wikipedia]
*[https://en.wikipedia.org/wiki/Factor_(programming_language) Factor on Wikipedia]