-
Notifications
You must be signed in to change notification settings - Fork 20
Examples
To whet your appetite, here are some programming examples for your browsing pleasure. You might also wish to refer to our very brief introduction to Pure, to help you reading the examples, and the standard library scripts, in particular the prelude, for definitions of the predefined operations.
Some basic examples first.
- hello.pure: Start here to quickly get an idea how Pure programs look like.
- avltree.pure: An example illustrating how AVL trees can be implemented in Pure.
- recursive.pure: One of the benchmarks from the Language Shootout. Have some fun comparing this to other language versions available here.
- sortalgos.pure: Some classical sorting algorithms in Pure.
- sudoku.pure: Peter Bernschneider's Sudoku solver.
Matrix examples. These show off the new GSL matrix capabilities built into Pure 0.7 and later.
- linalg.pure: Various basic linear algebra operations.
- gauss.pure: A Pure implementation of the Gaussian elimination algorithm.
- gslexample.pure: Some examples for Pure's GSL module, which aims to provide a complete wrapper for the GNU Scientific Library one day.
Calling foreign code. These examples illustrate how easy it is to interface to your own code written in C, Fortran and other languages in order to "outsource" expensive operations such as heavy number crunching.
- fortran.pure: Illustrates how to call GNU Fortran subroutines and functions from Pure.
- fortran.f90: Accompanying Fortran module.
- inline_examp.pure: How to inline C, C++ and Fortran code in Pure scripts.
- faust_examp.pure: How to call Faust code from Pure. Faust is a functional signal processing language.
The following examples illustrate some of Pure's metaprogramming and symbolic evaluation capabilities:
- lucid.pure: A toy implementation of the Lucid dataflow programming language.
- quasiquote.pure: An implementation of a Lisp-like quasiquote operation which makes it easy to manipulate expressions as literals. (An alternative implementation can be found here, and some usage examples here.)
- reflection.pure: A Pure program can inspect (and modify) itself, very much like Lisp programs. (This is just a very basic example. Please check the manual for more.)
-
rules.pure: An example showing how to implement local rewriting rules with the
reduce
builtin. - symbolic.pure: Simplistic symbolic algebra examples (symbolic differentiation, disjunctive normal form).
-
units.pure: How to perform unit conversions using the
reduce
builtin.
Also make sure you have a look at some of Libor Spacek's examples:
- date.pure: A Mayan calendar counting off the days until the current cycle ends. A "must have" for hobby doomsday prophets!
- queens.pure: Some additional n-queens algorithms, including Libor's blazingly fast non-backtracking solution.
That are all the featured examples for now. More examples can be found in the sources.