# 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 993 total.

(previous page) (next page)### D

- Day of the week of Christmas and New Year
- Days between dates
- Deal cards for FreeCell
- Deceptive numbers
- Decimal floating point number to binary
- Deepcopy
- Define a primitive data type
- Delete a file
- Deming's funnel
- Department numbers
- Descending primes
- Detect division by zero
- Determinant and permanent
- Determine if a string has all the same characters
- Determine if a string has all unique characters
- Determine if a string is collapsible
- Determine if a string is numeric
- Determine if a string is squeezable
- Determine sentence type
- Dice game probabilities
- Digit fifth powers
- Digital root
- Digital root/Multiplicative digital root
- Dinesman's multiple-dwelling problem
- Disarium numbers
- Display a linear combination
- Distinct palindromes within decimal numbers
- Distinct power numbers
- Distributed programming
- Diversity prediction theorem
- DNS query
- Documentation
- Doomsday rule
- Dot product
- Doubly-linked list/Element definition
- Dragon curve
- Draw a cuboid
- Draw a pixel
- Draw a sphere
- Draw pixel 2
- Duffinian numbers
- Dutch national flag problem
- Dynamic variable names

### E

- Eban numbers
- Echo server
- Egyptian division
- EKG sequence convergence
- Element-wise operations
- Elementary cellular automaton
- Emirp primes
- Empty directory
- Empty program
- Empty string
- Enforced immutability
- Entropy
- Entropy/Narcissist
- Enumerations
- Environment variables
- Equilibrium index
- Erdös-Selfridge categorization of primes
- Erdős-primes
- Esthetic numbers
- Ethiopian multiplication
- Euler method
- Euler's identity
- Euler's sum of powers conjecture
- Evaluate binomial coefficients
- Even or odd
- Evolutionary algorithm
- Exactly three adjacent 3 in lists
- Exceptions
- Exceptions/Catch an exception thrown in a nested call
- Executable library
- Execute a system command
- Execute Brain****
- Execute HQ9+
- Execute SNUSP
- Exponentiation operator
- Exponentiation order
- Exponentiation with infix operators in (or operating on) the base
- Extend your language
- Extensible prime generator
- Extra primes
- Extract file extension
- Extreme floating point values

### F

- Factorial
- Factorial base numbers indexing permutations of a collection
- Factorions
- Factors of a Mersenne number
- Factors of an integer
- Fairshare between two and more
- Farey sequence
- Fast Fourier transform
- FASTA format
- Faulhaber's formula
- Faulhaber's triangle
- Feigenbaum constant calculation
- Fermat numbers
- Fibonacci n-step number sequences
- Fibonacci sequence
- Fibonacci word
- Fibonacci word/fractal
- File extension is in extensions list
- File input/output
- File modification time
- File size
- File size distribution
- Filter
- Find adjacent primes which differ by a square integer
- Find Chess960 starting position identifier
- Find common directory path
- Find first missing positive
- Find if a point is within a triangle
- Find limit of recursion
- Find minimum number of coins that make a given value
- Find palindromic numbers in both binary and ternary bases
- Find prime n such that reversed n is also prime
- Find prime numbers of the form n*n*n+2
- Find square difference
- Find the intersection of a line with a plane
- Find the intersection of two lines
- Find the last Sunday of each month
- Find the missing permutation
- Find words which contain the most consonants
- Find words which contains all the vowels
- Find words which contains more than 3 e vowels
- Find words whose first and last three letters are equal
- Find words with alternating vowels and consonants
- First 9 prime Fibonacci number
- First class environments
- First perfect square in base n with n unique digits
- First power of 2 that has leading decimal digits of 12
- First-class functions
- First-class functions/Use numbers analogously
- Five weekends
- Fivenum
- FizzBuzz
- Flatten a list
- Floyd's triangle
- Forest fire
- Fork
- Formatted numeric output
- Fortunate numbers
- Forward difference
- Four is magic
- Fractran
- Frobenius numbers
- Function composition
- Function definition
- Function frequency
- Fusc sequence

### G

- Galton box animation
- Gamma function
- Gapful numbers
- Gauss-Jordan matrix inversion
- General FizzBuzz
- Generate Chess960 starting position
- Generate lower case ASCII alphabet
- Generate random chess position
- Generate random numbers without repeating a value
- Generator/Exponential
- Generic swap
- Geohash
- Get system command output
- Globally replace text in several files
- Gray code
- Grayscale image
- Greatest common divisor
- Greatest element of a list
- Greatest subsequential sum
- Greed
- Greedy algorithm for Egyptian fractions
- Guess the number
- Guess the number/With feedback
- Guess the number/With feedback (player)

### H

- Hailstone sequence
- Halt and catch fire
- Hamming numbers
- Happy numbers
- Harmonic series
- Harshad or Niven series
- Hash from two arrays
- Haversine formula
- Hello world/Graphical
- Hello world/Line printer
- Hello world/Newbie
- Hello world/Newline omission
- Hello world/Standard error
- Hello world/Text
- Here document
- Heronian triangles
- Hex words
- Hickerson series of almost integers
- Higher-order functions
- Hilbert curve
- History variables
- Hofstadter Figure-Figure sequences
- Hofstadter Q sequence
- Hofstadter-Conway $10,000 sequence
- Holidays related to Easter