Front Page All Articles Recent Changes Random Article

Contents

Concatenative language

  • ACL
  • Ait
  • Aocla
  • Breeze
  • Callisto
  • Cat
  • Cognate
  • colorForth
  • Concata
  • CoSy
  • Deque
  • DSSP
  • dt
  • Elymas
  • Enchilada
  • ETAC
  • F
  • Factor
  • Fiveth
  • Forth
  • Fourth
  • Freelang
  • Gershwin
  • hex
  • iNet
  • Joy
  • Joy of Postfix App
  • kcats
  • Kitten
  • lang5
  • Listack
  • LSE64
  • Lviv
  • Meow5
  • min
  • Mirth
  • mjoy
  • Mlatu
  • Ode
  • OForth
  • Om
  • Onyx
  • Plorth
  • Popr
  • Porth
  • PostScript
  • Prowl
  • Quest32
  • Quackery
  • r3
  • Raven
  • Retro
  • RPL
  • SPL
  • Staapl
  • Stabel
  • Tal
  • Titan
  • Trith
  • Uiua
  • Worst
  • xs
  • XY
  • 5th
  • 8th

Concatenative topics

  • Compilers
  • Interpreters
  • Type systems
  • Object systems
  • Quotations
  • Variables
  • Garbage collection
  • Example programs

Concatenative meta

  • People
  • Communities

Other languages

  • APL
  • C++
  • Erlang
  • FP trivia
  • Haskell
  • Io
  • Java
  • JavaScript
  • Lisp
  • ML
  • Oberon
  • RPL
  • Self
  • Slate
  • Smalltalk

Meta

  • Search
  • Farkup wiki format
  • Etiquette
  • Sandbox

Factor/Examples

Listener examples

You can try expressions in the interactive listener. For example, some postfix arithmetic:

2 3 + 4 * .

Hello world:

"Hello world" print

Complete examples

Simple

  • hello-world - a complete program that defines a new vocabulary with a main word

Networking and web

  • time-server - simple TCP/IP server
  • webapps.calculator - simple webapp
  • webapps.wiki - the source code to this wiki
  • smtp - send e-mail via SMTP, with optional SSL support
  • syndication - parse RSS and Atom feeds, write Atom feeds, also demonstrates inline XML syntax.

Algorithms

  • rot13 - rot13 "encryption"
  • roman - convert numbers to and from roman numerals
  • morse - convert strings to morse code and vice versa, and play morse code with OpenAL
  • base64
  • id3 - ID3 parser
  • usa-cities - parse a CSV file and extract information
  • 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). Learn more about Factor's C library interface.

  • unix - Unix/POSIX
  • windows - Win32
  • 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 if you have a good enough OpenGL driver -- just issue a command such as "spheres" run in the listener.

  • hello-unicode
  • terrain
  • spheres
  • bunny
  • maze
  • tetris

Comp sci

  • 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.
  • monads - Implements a generic protocol, some operations over monads, and a few simple instances

Running the examples

Some of these examples define a MAIN: word. This means they are runnable from the Factor listener, by issuing a command such as the following,

"hello-unicode" run

Other examples are libraries, which means that after loading them with a command like this:

USE: roman

you can then get a list of words, and in some cases, API documentation:

"roman" about

and play around:

( 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:

"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:

\ reverse help

This even works for bits of syntax:

\ MEMO: help

Finally, all of this reference documentation is also available online at http://docs.factorcode.org.

More

To see more examples of Factor code, 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.

resume writing service

This revision created on Wed, 27 Apr 2011 11:40:48 by PhilipWalker

Latest Revisions Edit

All content is © 2008-2024 by its respective authors. By adding content to this wiki, you agree to release it under the BSD license.