# Category:Factor

**Factor**

This

**programming language**may be used to instruct a computer to perform a task.

Official website |
---|

Execution method: | Compiled (machine code) |
---|---|

Garbage collected: | Yes |

Parameter passing methods: | By reference |

Type safety: | Safe |

Type compatibility: | Duck |

Type expression: | Implicit |

Type checking: | Dynamic |

Lang tag(s): | factor |

See Also: |

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 here. As of June 2020, Factor is still being developed by several contributors, with the latest stable release in July 2018.

Factor is a stack language similar to, but of a higher level than, Forth. Factor is a 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, `foo bar baz`

is equivalent to `baz(bar(foo()))`

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

```
var x = ...;
var y = foo(x);
var z = bar(x);
```

In Factor this is a data flow pattern called `bi`

.

```
[ foo ] [ bar ] bi
```

This says, "apply `foo`

to the object at the top of the data stack, and apply `bar`

to it as well." Rather than naming the values `x`, `y`, and `z`, 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.

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 `map`

, `filter`

, `reduce`

, 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 (homoiconicity).

## About Factor examples on Rosetta Code[edit]

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. `IN: myvocab`

and set a `MAIN:`

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. `iota`

became `<iota>`

in Factor 0.98).

For this reason, it is advised that examples use the `works with`

template to indicate which version of Factor the example works with. For example,

{{works with|Factor|0.98}}becomes

## Links[edit]

## Subcategories

This category has the following 3 subcategories, out of 3 total.

### @

- Factor examples needing attention (empty)
- Factor Implementations (empty)
- Factor User (19 P)

## Pages in category "Factor"

The following 200 pages are in this category, out of 985 total.

(previous page) (next page)### A

- A+B
- Abbreviations, automatic
- Abbreviations, easy
- Abbreviations, simple
- ABC problem
- ABC words
- Abelian sandpile model/Identity
- Abundant odd numbers
- Abundant, deficient and perfect number classifications
- Accumulator factory
- Achilles numbers
- Ackermann function
- Active object
- Additive primes
- Air mass
- AKS test for primes
- Align columns
- Aliquot sequence classifications
- Almkvist-Giullera formula for pi
- Almost prime
- Alternade words
- Amb
- Amicable pairs
- Anadromes
- Anagrams
- Anagrams/Deranged anagrams
- Angle difference between two bearings
- Angles (geometric), normalization and conversion
- Animate a pendulum
- Animation
- Anonymous recursion
- Anti-primes
- Append numbers at same position in strings
- Apply a callback to an array
- Approximate equality
- Arbitrary-precision integers (included)
- Arithmetic evaluation
- Arithmetic numbers
- Arithmetic-geometric mean
- Arithmetic/Complex
- Arithmetic/Integer
- Arithmetic/Rational
- Array concatenation
- Array length
- Arrays
- Ascending primes
- Assertions
- Associative array/Creation
- Associative array/Iteration
- Associative array/Merging
- Attractive numbers
- Average loop length
- Averages/Arithmetic mean
- Averages/Mean angle
- Averages/Mean time of day
- Averages/Median
- Averages/Mode
- Averages/Pythagorean means
- Averages/Root mean square
- Averages/Simple moving average

### B

- Babbage problem
- Balanced brackets
- Balanced ternary
- Base 16 numbers needing a to f
- Base64 decode data
- Base64 encode data
- Bell numbers
- Benford's law
- Bernoulli numbers
- Bin given limits
- Binary digits
- Binary search
- Binary strings
- Bioinformatics/base count
- Bioinformatics/Sequence mutation
- Bioinformatics/Subsequence
- Biorhythms
- Bitcoin/address validation
- Bitcoin/public point to address
- Bitmap
- Bitmap/Bresenham's line algorithm
- Bitmap/Bézier curves/Cubic
- Bitmap/Bézier curves/Quadratic
- Bitwise operations
- Boolean values
- Box the compass
- Brazilian numbers
- Break OO privacy
- Brilliant numbers
- Brownian tree
- Bulls and cows
- Bulls and cows/Player
- Burrows–Wheeler transform

### C

- Caesar cipher
- Calculating the value of e
- Calendar
- Calkin-Wilf sequence
- Call a foreign-language function
- Call a function
- Call an object method
- Camel case and snake case
- Canonicalize CIDR
- Cantor set
- Carmichael 3 strong pseudoprimes
- Cartesian product of two or more lists
- Case-sensitivity of identifiers
- Catalan numbers
- Catalan numbers/Pascal's triangle
- Catamorphism
- Change e letters to i in words
- Changeable words
- Chaocipher
- Character codes
- Check Machin-like formulas
- Check output device is a terminal
- Check that file exists
- Chemical calculator
- Cheryl's birthday
- Chinese remainder theorem
- Chinese zodiac
- Chowla numbers
- Cipolla's algorithm
- Circles of given radius through two points
- Circular primes
- Cistercian numerals
- Classes
- Closures/Value capture
- Code Golf: Code Golf
- Collections
- Colorful numbers
- Colour bars/Display
- Colour pinstripe/Display
- Combinations
- Combinations and permutations
- Comma quibbling
- Command-line arguments
- Commatizing numbers
- Comments
- Common list elements
- Common sorted list
- Compare a list of strings
- Compile-time calculation
- Compound data type
- Concatenate two primes is also prime
- Concurrent computing
- Conditional structures
- Conjugate a Latin verb
- Conjugate transpose
- Consecutive primes with ascending or descending differences
- Constrained random points on a circle
- Continued fraction
- Continued fraction/Arithmetic/Construct from rational number
- Convert decimal number to rational
- Convert seconds to compound duration
- Coprime triplets
- Coprimes
- Copy a string
- Copy stdin to stdout
- Count how many vowels and consonants occur in a string
- Count in factors
- Count in octal
- Count occurrences of a substring
- Count the coins
- Cousin primes
- Cramer's rule
- CRC-32
- Create a file
- Create a file on magnetic tape
- Create a two-dimensional array at runtime
- Create an HTML table
- CSV data manipulation
- CSV to HTML translation
- Cuban primes
- Cubic special primes
- Cullen and Woodall numbers
- Cumulative standard deviation
- Currency
- Currying
- Curzon numbers
- CUSIP
- Cycle detection
- Cyclops numbers