Concatenative language
Other languages
Computer Science
Meta
== Listener examples == You can try expressions in the interactive listener. For example, some postfix arithmetic: [factor{2 3 + 4 * .}] Hello world: [factor{"Hello world" print}] == Complete examples == === Simple === - [[https://github.com/factor/factor/blob/master/extra/hello-world/hello-world.factor|hello-world]] - a complete program that defines a new vocabulary with a main word === Networking and web === - [[https://github.com/factor/factor/blob/master/extra/time-server/time-server.factor|time-server]] - simple TCP/IP server - [[https://github.com/factor/factor/blob/master/extra/webapps/calculator|webapps.calculator]] - simple webapp - [[https://github.com/factor/factor/blob/master/extra/webapps/wiki|webapps.wiki]] - the source code to this wiki - [[https://github.com/factor/factor/blob/master/basis/smtp|smtp]] - send e-mail via SMTP, with optional SSL support - [[https://github.com/factor/factor/blob/master/basis/syndication|inline XML syntax]]. === Algorithms === - [[https://github.com/factor/factor/blob/master/extra/rot13/rot13.factor|rot13]] - rot13 "encryption" - [[https://github.com/factor/factor/blob/master/basis/roman|roman]] - convert numbers to and from roman numerals - [[https://github.com/factor/factor/blob/master/extra/morse|morse]] - convert strings to morse code and vice versa, and play morse code with OpenAL - [[https://github.com/factor/factor/blob/master/basis/base64|base64]] - [[https://github.com/factor/factor/blob/master/extra/id3|id3]] - ID3 parser - [[https://github.com/factor/factor/blob/master/extra/usa-cities|usa-cities]] - parse a CSV file and extract information - [[https://github.com/factor/factor/blob/master/extra/benchmark/mandel|benchmark.mandel]] - Mandelbrot fractal generator === C library bindings === Many of these bindings have easier to use wrappers (for example, there's no reason to use the Unix API directly, since all I/O is done with higher-level cross-platform APIs). [[http://docs.factorcode.org/content/article-alien.html|Learn more about Factor's C library interface]]. - [[https://github.com/factor/factor/blob/master/basis/unix|unix]] - Unix/POSIX - [[https://github.com/factor/factor/blob/master/basis/windows|windows]] - Win32 - [[https://github.com/factor/factor/blob/master/basis/opengl/gl/gl.factor|opengl.gl]] - low-level OpenGL API === Graphics === These examples are more complex than the above, and some of them were written a while ago and haven't been cleaned up to use the latest idioms. They are all runnable from the [[Factor/UI|Factor UI]] if you have a good enough OpenGL driver -- just issue a command such as %"spheres" run% in the listener. - [[https://github.com/factor/factor/blob/master/extra/hello-unicode/hello-unicode.factor|hello-unicode]] - [[https://github.com/factor/factor/blob/master/extra/terrain/terrain.factor|terrain]] - [[https://github.com/factor/factor/blob/master/extra/spheres/spheres.factor|spheres]] - [[https://github.com/factor/factor/blob/master/extra/bunny/bunny.factor|bunny]] - [[https://github.com/factor/factor/blob/master/extra/maze/maze.factor|maze]] - [[https://github.com/factor/factor/blob/master/extra/tetris/tetris.factor|tetris]] === Comp sci === - [[https://github.com/factor/factor/blob/master/extra/rpn/rpn.factor|rpn]] - Simple reverse polish notation calculator. It implements a parser, "bytecode" instruction set, and simple stack interpreter, from scratch, without re-using parts of Factor's own implementation via reflection. - [[https://github.com/factor/factor/blob/master/extra/monads/monads.factor|monads]] - Implements a generic protocol, some operations over monads, and a few simple instances == Running the examples == Some of these examples define a [[http://docs.factorcode.org/content/word-MAIN__colon__%2csyntax.html|MAIN:]] word. This means they are runnable from the Factor listener, by issuing a command such as the following, [factor{"hello-unicode" run}] Other examples are libraries, which means that after loading them with a command like this: [factor{USE: roman}] you can then get a list of words, and in some cases, API documentation: [factor{"roman" about}] and play around: [factor{IN: scratchpad 123 >roman . "cxxiii"}] == Understanding the examples == If you see an example refer to a vocabulary in its %USING:% list, you can get help for that vocabulary from the Factor listener: [factor{"math.vectors" about}] The about page gives a list of words with stack effects -- clicking on a word will display documentation for the word, if any, as well as its definition (which may not exactly match the source file definition, since its printed from its in-memory representation). For many vocabularies, a "Documentation" link at the very top gives an overview article as well. If you see an example call a word you're unfamiliar with, make sure you load all required vocabularies by copying the example's %USING:% line into your listener, then use the %help% word to get help: [factor{\ reverse help}] This even works for bits of syntax: [factor{\ MEMO: help}] Finally, all of this reference documentation is also available online at [[https://docs.factorcode.org]]. == More == To see more examples of Factor code, [[http://factorcode.org|download]] the Factor distribution and take a look in the %core/%, %basis/% and %extra/% directories. Most of Factor is implemented in Factor (including the optimizing compiler), and there are a number of useful libraries and demos which you can look at as well, for a total of over 200 thousand lines of Factor code.
Describe this revision:
Save