Category: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. Factor is still being developed by dozens of contributors, with the latest stable release in August 2023.
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
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
Todo
Tasks not implemented in Factor
Links
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 1,001 total.
(previous page) (next page)N
- Number reversal game
- Numbers divisible by their individual digits, but not by the product of their digits.
- Numbers in base 10 that are palindromic in bases 2, 4, and 16
- Numbers in base-16 representation that cannot be written with decimal digits
- Numbers which are the cube roots of the product of their proper divisors
- Numbers whose binary and ternary digit sums are prime
- Numbers whose count of divisors is prime
- Numbers with equal rises and falls
- Numbers with prime digits whose sum is 13
- Numbers with same digit set in base 10 and base 16
- Numeric error propagation
- Numeric separator syntax
- Numerical and alphabetical suffixes
- Numerical integration
- Numerical integration/Adaptive Simpson's method
O
- Object serialization
- Odd and square numbers
- Odd squarefree semiprimes
- Odd word problem
- Odd words
- Old lady swallowed a fly
- Old Russian measure of length
- One of n lines in a file
- One-dimensional cellular automata
- OpenGL
- Operator precedence
- Optional parameters
- Order by pair comparisons
- Order disjoint list items
- Order two numerical lists
- Ordered words
- Ormiston pairs
P
- Padovan n-step number sequences
- Padovan sequence
- Pairs with common factors
- Palindrome dates
- Palindrome detection
- Palindromic gapful numbers
- Palindromic primes
- Palindromic primes in base 16
- Pandigital prime
- Pangram checker
- Parallel calculations
- Parsing/RPN calculator algorithm
- Partial function application
- Partition an integer x into n primes
- Partition function P
- Pascal matrix generation
- Pascal's triangle
- Pascal's triangle/Puzzle
- Password generator
- Pathological floating point problems
- Peano curve
- Pell's equation
- Penney's game
- Penta-power prime seeds
- Percolation/Mean cluster density
- Percolation/Mean run density
- Percolation/Site percolation
- Perfect numbers
- Perfect shuffle
- Perfect totient numbers
- Perlin noise
- Permutations
- Permutations with some identical elements
- Permutations/Derangements
- Permuted multiples
- Pernicious numbers
- Phrase reversals
- Pi
- Pick random element
- Pierpont primes
- Piprimes
- Pisano period
- Playing cards
- Plot coordinate pairs
- Poker hand analyser
- Polymorphic copy
- Polymorphism
- Polynomial derivative
- Polynomial long division
- Population count
- Positive decimal integers with the digit 1 occurring exactly twice
- Power set
- Pragmatic directives
- Price fraction
- Primality by trial division
- Primality by Wilson's theorem
- Prime conspiracy
- Prime decomposition
- Prime numbers p for which the sum of primes less than or equal to p is prime
- Prime numbers which contain 123
- Prime triplets
- Prime words
- Primes which contain only one odd digit
- Primes whose first and last number is 3
- Primes whose sum of digits is 25
- Primes with digits in nondecreasing order
- Primorial numbers
- Priority queue
- Probabilistic choice
- Product of divisors
- Product of min and max prime factors
- Program name
- Program termination
- Proper divisors
- Pseudo-random numbers/Combined recursive generator MRG32k3a
- Pseudo-random numbers/Middle-square method
- Pseudo-random numbers/PCG32
- Pseudo-random numbers/Splitmix64
- Pseudo-random numbers/Xorshift star
- Pseudorandom number generator image
- Pythagorean triples
Q
R
- Rainbow
- Random Latin squares
- Random number generator (device)
- Random number generator (included)
- Random numbers
- Range consolidation
- Range expansion
- Range extraction
- Ranking methods
- Ray-casting algorithm
- Read a file character by character/UTF8
- Read a file line by line
- Read a specific line from a file
- Read entire file
- Real constants and functions
- Reduced row echelon form
- Reflection/Get source
- Reflection/List methods
- Reflection/List properties
- Regular expressions
- Remove duplicate elements
- Remove vowels from a string
- Rename a file
- Rep-string
- Repeat
- Repeat a string
- Return multiple values
- Reverse a string
- Reverse the order of lines in a text file while preserving the contents of each line
- Reverse words in a string
- Rhonda numbers
- RIPEMD-160
- Rock-paper-scissors
- Rodrigues’ rotation formula
- Roman numerals/Decode
- Roman numerals/Encode
- Roots of a quadratic function
- Roots of unity
- Rosetta Code/Count examples
- Rot-13
- RPG attributes generator
- Run-length encoding
- Runtime evaluation
- Runtime evaluation/In an environment
- Ruth-Aaron numbers
S
- S-expressions
- Safe and Sophie Germain primes
- Safe primes and unsafe primes
- Sattolo cycle
- Scope/Function names and labels
- Search a list
- Search a list of records
- SEDOLs
- Selectively replace multiple instances of a character within a string
- Self-describing numbers
- Semiprime
- Semordnilap
- Send an unknown method call
- Send email
- Sequence of non-squares
- Sequence of primes by trial division
- Sequence of primorial primes
- Sequence: nth number with exactly n divisors
- Sequence: smallest number greater than previous term with exactly n divisors
- Sequence: smallest number with exactly n divisors
- Set
- Set consolidation
- Set puzzle
- Set right-adjacent bits
- Set, the card game
- Seven-sided dice from five-sided dice
- Sexy primes
- SHA-1
- SHA-256
- SHA-256 Merkle tree
- Shell one-liner
- Shift list elements to left by 3
- Shoelace formula for polygonal area
- Short-circuit evaluation
- Shortest common supersequence