Content deleted Content added
Rescuing 1 sources and tagging 0 as dead. #IABot (v1.6.5) |
m v2.05b - Bot T20 CW#61 - Fix errors for CW project (Reference before punctuation) |
||
(31 intermediate revisions by 19 users not shown) | |||
Line 1:
{{Short description|Functional programming language}}
{{redirect|Pure (language)|the linguistic notions|Linguistic purism|and|Adamic language}}
{{Infobox programming language
|name = Pure
|logo =
|screenshot = Pure with texmacs.png
|screenshot caption = Using Pure with [[TeXmacs]]
|paradigm = [[Functional programming|Functional]], [[Declarative programming|declarative]], [[term rewriting]]
|designer = Albert Gräf
|developer = Albert Gräf
|released = {{Start date and age|2008}}
|latest release version = 0.
|latest release date = {{Start date and age|
|typing = [[Strong and weak typing|
|implementations =
|dialects =
|operating system = [[Cross-platform software|Cross-platform]]: [[FreeBSD]],
|license = [[GNU Lesser General Public License]]
|influenced by =
|influenced =
|website = {{URL|
}}
'''Pure''', successor to the equational language '''Q''', is a dynamically typed, [[Functional programming|functional]] [[programming language]] based on [[term rewriting]]. It has facilities for user-defined [[
== Overview ==
Pure comes with an [[Interpreter (computing)|interpreter]] and [[debugger]], provides [[Garbage collection (computer science)|automatic memory management]], has powerful functional and symbolic programming abilities, and interfaces to [[Library (computing)|libraries]] in [[C (programming language)|C]] (e.g., for numerics, low-level protocols, and other such tasks). At the same time, Pure is a ''small'' language designed from scratch; its interpreter is not large, and the library modules are written in Pure. The syntax of Pure resembles that of [[Miranda (programming language)|Miranda]] and [[Haskell]], but it is a [[free-format language]] and thus uses explicit [[delimiter]]s (rather than [[off-side rule]] indents) to denote program structure.
The Pure language is a successor of the equational programming language Q,<ref>
Pure [[Plug-in (computing)|plug-ins]] are available for the [[Gnumeric]] spreadsheet and Miller Puckette's [[Pure Data]] graphical multimedia software, which make it possible to extend these programs with functions written in the Pure language. Interfaces are also provided as library modules to [[GNU Octave]], [[OpenCV]], [[OpenGL]], the [[GNU Scientific Library]], [[FAUST (programming language)|FAUST]], [[SuperCollider]], and liblo (for [[Open Sound Control]] (OSC)).
==Examples==
The [[Fibonacci numbers]] (naive version):
<syntaxhighlight lang="q">
</syntaxhighlight>
Better ([[tail-recursive]] and [[linear-time]]) version:
<syntaxhighlight lang="q">
</syntaxhighlight>
Compute the first 20 Fibonacci numbers:
<syntaxhighlight lang="q">
</syntaxhighlight>
An [[algorithm]] for the [[Eight queens puzzle|n queens problem]] which employs a [[list comprehension]] to organize the backtracking search:
<syntaxhighlight lang="q">
</syntaxhighlight>
While Pure uses [[eager evaluation]] by default, it also supports [[Lazy evaluation|lazy]] data structures such as streams (lazy [[List (computing)|lists]]). For instance, [[David Turner (computer scientist)|David Turner]]'s algorithm<ref>Turner, David A. SASL language manual. Tech. rept. CS/75/1. Department of Computational Science, University of St. Andrews 1975.</ref> for computing the stream of [[prime numbers]] by [[trial division]] can be expressed in Pure:
<syntaxhighlight lang="q">
</syntaxhighlight>
Use of the <code>&</code> operator turns the tail of the sieve into a [[thunk]] to delay its computation. The thunk is evaluated implicitly and then [[Memoization|memoized]] (using [[call by need]] evaluation) when the corresponding part of the list is accessed, e.g.:
<syntaxhighlight lang="q">
</syntaxhighlight>
Pure has efficient support for vectors and matrices (similar to that of [[MATLAB]] and [[GNU Octave]]), including vector and matrix comprehensions.
Namespaces, types and interfaces belong to the standard repertoire:
<syntaxhighlight lang="q">
nonfix nil;
type bintree nil | bintree (bin x left right);
outfix « »;
namespace foo (« »);
infixr (::^) ^;
x^y = 2*x+y;
namespace;
interface stack with
push s::stack x;
pop s::stack;
top s::stack;
end;
type stack [];
push xs@[] x | push xs@(_:_) x = x:xs;
pop (x:xs) = xs;
top (x:xs) = x;
</syntaxhighlight>
As a language based on [[term rewriting]], Pure fully supports [[symbolic computation]] with expressions. Here is an example showing the use of local rewriting rules to [[polynomial expansion|expand]] and [[factorization|factor]] simple arithmetic expressions:
<syntaxhighlight lang="q">
factor = reduce with
a*c+b*c = (a+b)*c;
a*b+a*c = a*(b+c);
end;
expand ((a+b)*2); // yields a*2+b*2
factor (a*2+b*2); // yields (a+b)*2
</syntaxhighlight>
Calling [[C (programming language)|C]] functions from Pure is very easy. E.g., for a [["Hello, World!" program]], the following imports the <code>puts</code> function from the [[C library]] and uses it to print the string <code>"Hello, world!"</code> on the terminal:
<syntaxhighlight lang="c">
</syntaxhighlight>
Instead of manually compiling source files to LLVM bitcode modules, one can also place the source code into a Pure script, enclosing it in %< ... %> (inline code, e.g. C, Fortran 77/90 and so on).
==See also==
Line 149 ⟶ 139:
* [[Functional programming]]
* [[:Category: Functional languages|Functional languages]]
* [[Clean (programming language)]]
== References ==
* Albert Gräf. "Signal Processing in the Pure Programming Language". ''Linux Audio Conference 2009''.
* Michael Riepe. [http://www.heise.de/ix/artikel/Rein-ins-Vergnuegen-856225.html "Pure – eine einfache funktionale Sprache"] {{Webarchive|url=https://web.archive.org/web/20110319165239/http://www.heise.de/ix/artikel/Rein-ins-Vergnuegen-856225.html |date=2011-03-19 }}. ''Heise''.
* [https://web.archive.org/web/20130808212022/http://blueparen.com/node/6 "Interview With Albert Gräf"]. blueparen.
* Mark Boady, [https://www.cs.drexel.edu/~mwb33/posters/teach_pres/mwb33_teaching_presentation.pdf Introduction to Term Rewrite Systems and their Applications]
== Notes ==
{{Reflist}}
==External links==
* {{Official website|
* [https://github.com/agraef/pure-lang Pure at Github]
* [
* [
* [https://agraef.github.io/pure-docs/ Documentation Overview (html)]
* [https://agraef.github.io/pure-docs/pure-reduce.html Computer Algebra with Pure: A Reduce Interface]
* [https://agraef.github.io/pure-lang/quickref/pure-quickref.pdf Pure quick reference]
* [https://github.com/agraef/pure-lang/wiki/UsingPure Using the Pure Interpreter]
* [https://github.com/agraef/pure-lang/wiki/TeXmacs Using Pure with TeXmacs]
* [https://github.com/agraef/pure-lang/wiki/pure-texmacs.en.pdf The Pure TeXmacs Plugin]
{{Programming languages}}
|