HOME

TheInfoList



OR:

Factor is a
stack-oriented programming language Stack-oriented programming, is a programming paradigm which relies on a stack machine model for passing parameters. Stack-oriented languages operate on one or more stacks, each of which may serve a different purpose. Programming constructs i ...
created by Slava Pestov. Factor is dynamically typed and has
automatic memory management In computer science, garbage collection (GC) is a form of automatic memory management. The ''garbage collector'' attempts to reclaim memory which was allocated by the program, but is no longer referenced; such memory is called ''garbage''. ...
, as well as powerful metaprogramming features. The language has a single implementation featuring a self-hosted optimizing compiler and an
interactive development environment An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools ...
. The Factor distribution includes a large standard library.


History

Slava Pestov created Factor in 2003 as a
scripting language A scripting language or script language is a programming language that is used to manipulate, customize, and automate the facilities of an existing system. Scripting languages are usually interpreted at runtime rather than compiled. A scripting ...
for a
video game Video games, also known as computer games, are electronic games that involves interaction with a user interface or input device such as a joystick, controller, keyboard, or motion sensing device to generate visual feedback. This feedba ...
. The initial implementation, now referred to as JFactor, was implemented in
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
and ran on the Java Virtual Machine. Though the early language resembled modern Factor superficially in terms of
syntax In linguistics, syntax () is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure ( constituenc ...
, the modern language is very different in practical terms and the current implementation is much faster. The language has changed significantly over time. Originally, Factor programs centered on manipulating Java objects with Java's reflection capabilities. From the beginning, the design philosophy has been to modify the language to suit programs written in it. As the Factor implementation and standard libraries grew more detailed, the need for certain language features became clear, and they were added. JFactor did not have an
object system Object-oriented programming (OOP) is a programming paradigm based on the concept of " objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pr ...
where the programmer could define their own
class Class or The Class may refer to: Common uses not otherwise categorized * Class (biology), a taxonomic rank * Class (knowledge representation), a collection of individuals or objects * Class (philosophy), an analytical concept used differently ...
es, and early versions of native Factor were the same; the language was similar to
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
in this way. Today, the object system is a central part of Factor. Other important language features such as
tuple In mathematics, a tuple is a finite ordered list (sequence) of elements. An -tuple is a sequence (or ordered list) of elements, where is a non-negative integer. There is only one 0-tuple, referred to as ''the empty tuple''. An -tuple is defi ...
classes, combinator inlining, macros, user-defined
parsing Parsing, syntax analysis, or syntactic analysis is the process of analyzing a string of symbols, either in natural language, computer languages or data structures, conforming to the rules of a formal grammar. The term ''parsing'' comes from ...
words and the modern vocabulary system were only added in a piecemeal fashion as their utility became clear. The foreign function interface was present from very early versions to Factor, and an analogous system existed in JFactor. This was chosen over creating a plugin to the C part of the implementation for each external
library A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vi ...
that Factor should communicate with, and has the benefit of being more declarative, faster to compile and easier to write. The Java implementation initially consisted of just an interpreter, but a compiler to
Java bytecode In computing, Java bytecode is the bytecode-structured instruction set of the Java virtual machine (JVM), a virtual machine that enables a computer to run programs written in the Java programming language and several other programming langua ...
was later added. This compiler only worked on certain procedures. The Java version of Factor was replaced by a version written in C and Factor. Initially, this consisted of just an interpreter, but the interpreter was replaced by two compilers, used in different situations. Over time, the Factor implementation has grown significantly faster.


Description

Factor is a dynamically typed,
functional Functional may refer to: * Movements in architecture: ** Functionalism (architecture) ** Form follows function * Functional group, combination of atoms within molecules * Medical conditions without currently visible organic basis: ** Functional sy ...
and
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
. Code is structured around small procedures, called words. In typical code, these are 1–3 lines long, and a procedure more than 7 lines long is very rare. Something that would idiomatically be expressed with one procedure in another programming language would be written as several words in Factor. Each word takes a fixed number of arguments and has a fixed number of return values. Arguments to words are passed on a data stack, using
reverse Polish notation Reverse Polish notation (RPN), also known as reverse Łukasiewicz notation, Polish postfix notation or simply postfix notation, is a mathematical notation in which operators ''follow'' their operands, in contrast to Polish notation (PN), in wh ...
. The stack is used just to organize calls to words, and not as a datastructure. The stack in Factor is used in a similar way to the stack in
Forth Forth or FORTH may refer to: Arts and entertainment * ''forth'' magazine, an Internet magazine * ''Forth'' (album), by The Verve, 2008 * ''Forth'', a 2011 album by Proto-Kaw * Radio Forth, a group of independent local radio stations in Scotla ...
; for this, they are both considered stack languages. For example, below is a snippet of code that prints out "hello world" to the current output stream: "hello world" print print is a word in the io vocabulary that takes a string from the stack and returns nothing. It prints the string to the current output stream (by default, the terminal or the graphical listener). The factorial function n! can be implemented in Factor in the following way: : factorial ( n -- n! ) dup 1 > [1,bproduct_.html"_;"title=",b.html"_;"title="[1,b">[1,bproduct_">,b.html"_;"title=" [1,bproduct_[_drop_1_.html"_;"title=",b">[1,bproduct_.html"_;"title=",b.html"_;"title="[1,b">[1,bproduct_">,b.html"_;"title="[1,b">[1,bproduct_[_drop_1_">,b">[1,bproduct_.html"_;"title=",b.html"_;"title="[1,b">[1,bproduct_">,b.html"_;"title="[1,b">[1,bproduct_[_drop_1_if_; Not_all_data_has_to_be_passed_around_only_with_the_stack._ [1,bproduct_[_drop_1_.html"_;"title=",b">[1,bproduct_.html"_;"title=",b.html"_;"title="[1,b">[1,bproduct_">,b.html"_;"title="[1,b">[1,bproduct_[_drop_1_">,b">[1,bproduct_.html"_;"title=",b.html"_;"title="[1,b">[1,bproduct_">,b.html"_;"title="[1,b">[1,bproduct_[_drop_1_if_; Not_all_data_has_to_be_passed_around_only_with_the_stack._Lexical_scoping">Lexically_scoped_local_variables_let_one_store_and_access_ [1,bproduct_[_drop_1_.html"_;"title=",b">[1,bproduct_.html"_;"title=",b.html"_;"title="[1,b">[1,bproduct_">,b.html"_;"title="[1,b">[1,bproduct_[_drop_1_">,b">[1,bproduct_.html"_;"title=",b.html"_;"title="[1,b">[1,bproduct_">,b.html"_;"title="[1,b">[1,bproduct_[_drop_1_if_; Not_all_data_has_to_be_passed_around_only_with_the_stack._Lexical_scoping">Lexically_scoped_local_variables_let_one_store_and_access_temporary_variable">temporaries_used_within_a_procedure._
[1,bproduct_[_drop_1_.html"_;"title=",b">[1,bproduct_.html"_;"title=",b.html"_;"title="[1,b">[1,bproduct_">,b.html"_;"title="[1,b">[1,bproduct_[_drop_1_">,b">[1,bproduct_.html"_;"title=",b.html"_;"title="[1,b">[1,bproduct_">,b.html"_;"title="[1,b">[1,bproduct_[_drop_1_if_; Not_all_data_has_to_be_passed_around_only_with_the_stack._Lexical_scoping">Lexically_scoped_local_variables_let_one_store_and_access_temporary_variable">temporaries_used_within_a_procedure._Dynamic_scoping">Dynamically_scoped_variables_are_used_to_pass_things_between_procedure_calls_without_using_the_stack._For_example,_the_current_input_and_output_streams_are_stored_in_dynamically_scoped_variables. Factor_emphasizes_flexibility_and_the_ability_to_extend_the_language.__There_is_a_system_for_macros,_as_well_as_for_arbitrary_extension_of_Factor_syntax._Factor's_syntax_is_often_extended_to_allow_for_new_types_of_word_definitions_and_new_types_of_literal_(computer_science).html" "title="Dynamic_scoping.html" ;"title="temporary_variable.html" ;"title="Lexical_scoping.html" ;"title=",b">[1,bproduct_[_drop_1_.html" ;"title=",b">[1,bproduct_.html" ;"title=",b.html" ;"title="[1,b">[1,bproduct ">,b.html" ;"title="[1,b">[1,bproduct [ drop 1 ">,b">[1,bproduct_.html" ;"title=",b.html" ;"title="[1,b">[1,bproduct ">,b.html" ;"title="[1,b">[1,bproduct [ drop 1 if ; Not all data has to be passed around only with the stack. Lexical scoping">Lexically scoped local variables let one store and access temporary variable">temporaries used within a procedure. Dynamic scoping">Dynamically scoped variables are used to pass things between procedure calls without using the stack. For example, the current input and output streams are stored in dynamically scoped variables. Factor emphasizes flexibility and the ability to extend the language. There is a system for macros, as well as for arbitrary extension of Factor syntax. Factor's syntax is often extended to allow for new types of word definitions and new types of literal (computer science)">literal Literal may refer to: * Interpretation of legal concepts: ** Strict constructionism ** The plain meaning rule The plain meaning rule, also known as the literal rule, is one of three rules of statutory construction traditionally applied by ...
s for data structures. It is also used in the XML library to provide literal syntax for generating XML. For example, the following word takes a string and produces an XML document object which is an HTML document emphasizing the string: : make-html ( string -- xml ) dup <->

<->

XML> ;
The word dup duplicates the top item on the stack. The <-> stands for filling in that part of the XML document with an item from the stack.


Implementation and libraries

Factor includes a large standard library, written entirely in the language. These include * A cross-platform GUI toolkit, built on top of OpenGL and various windowing systems, used for the development environment. * Bindings to several database libraries, including PostgreSQL and
SQLite SQLite (, ) is a database engine written in the C programming language. It is not a standalone app; rather, it is a library that software developers embed in their apps. As such, it belongs to the family of embedded databases. It is the mo ...
. * An
HTTP The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide We ...
server and client, with the Furnace web framework. * Efficient homogeneous arrays of integers, floats and C structs. * A library implementing regular expressions, generating machine code to do the matching. A foreign function interface is built into Factor, allowing for communication with C, Objective-C and Fortran programs. There is also support for executing and communicating with shaders written in GLSL. Factor is implemented in Factor and C++. It was originally bootstrapped from an earlier Java implementation. Today, the parser and the optimizing compiler are written in the language. Certain basic parts of the language are implemented in C++ such as the garbage collector and certain primitives. Factor uses an image-based model, analogous to many Smalltalk implementations, where compiled code and data are stored in an image. To compile a program, the program is loaded into an image and the image is saved. A special tool assists in the process of creating a minimal image to run a particular program, packaging the result into something that can be deployed as a standalone application. The Factor compiler implements many advanced optimizations and has been used as a target for research in new optimization techniques.


References


External links

* * * – a presentation written in Factor which mentions and praises Factor {{DEFAULTSORT:Factor (Programming Language) Programming languages Concatenative programming languages Function-level languages Stack-oriented programming languages Programming languages created in 2003 Extensible syntax programming languages 2003 software High-level programming languages Software using the BSD license