Pure Programming Examples
To whet your appetite, here are some programming examples for your browsing pleasure. All examples are available as beautified html with syntax highlighting and as plain source scripts. (In case you want to format your own Pure sources as html, there's a language definition for Andre Simon's highlight program included in the Pure source tarball.)
-
hello.pure: Start here to quickly get an idea how Pure programs look like. Source.
-
avltree.pure: Example illustrating how AVL trees can be implemented in Pure. Source.
-
recursive.pure: One of the benchmarks from the Language Shootout. Have some fun comparing this to other language versions available here. Source.
-
signal.pure: Signal handling example. Source.
-
symbolic.pure: Simplistic symbolic algebra examples (symbolic differentiation, disjunctive normal form). Source.
-
Matrix examples. linalg.pure (source) and gauss.pure (source) show the new matrix capabilities built into Pure 0.7 and later.
-
C interface examples. poor.c shows how to call Pure scripts from C/C++ (source). sort.c demonstrates how to inspect and create Pure expression data like lists and how to call back into the Pure interpreter from a C function (source).
-
Libor Spacek's examples. date.pure shows some calendar formulas and a Mayan calendar counting the days until the current cycle ends, a "must have" for hobby doomsday prophets (source)! queens.pure features some n-queens algorithms, including Libor's blazingly fast non-iterative solution of the n-queens problem (source). myutils.pure provides some handy utility functions (source).
Also have a look at the standard library sources. These are provided here mostly for documentation purposes, but also contain a bunch of instructive definitions.
-
prelude.pure: The standard Pure prelude. Source.
-
primitives.pure: Primitive operations (arithmetic etc.). Included in the prelude. Source.
-
strings.pure: String operations. Included in the prelude. Source.
-
matrices.pure: Matrix operations. Included in the prelude. Source.
-
math.pure: Pure's math library. Provides complex and rational numbers, as well as the usual bunch of mathematical functions (exp, logarithms, trigonometric and hyperbolic functions, etc.). With this module Pure becomes a useful desktop calculator. Source.
-
system.pure: Pure's system interface (still under construction). Source.
-
Jiri Spitz' port of the Q container data structures. These provide efficient, functional-style (immutable) containers for use in Pure applications. Arrays and heaps (priority queues) are implemented as balanced binary trees in array.pure (source) and heap.pure (source). Dictionaries, hashes, sets and bags (multisets) based on AVL trees are provided by dict.pure (source) and set.pure (source).