What is Pawns?

Why bother?

What are the key ideas?

*ptr1 = val;

ptr1

!ptr2

ptr2

Programming with pointers requires the programmer to understand pointer aliasing and sharing of data structures. In Pawns, sharing information is declared, providing documentation and allowing the compiler to understand the sharing and check the declarations are correct. As well as declaring side-effects, the programmer declares what sharing may occur between arguments when a function is called and what sharing may occur when it returns. By tracking possible sharing we can determine if arguments of a function can be updated during its execution. If update is restricted to variables which are local to the function execution, purely functional behaviour is guaranteed. For example, a data structure can be built locally using an imperative style, then returned. Thus imperative code can be encapsulated inside a declarative interface.

Pure functional programming is the default in Pawns. Arbitrary sharing of function arguments and results is possible and update of such data structures is not allowed. However, if enough extra declarations and annotations are supplied, there are no restrictions on what can be updated anywhere.

How can I find out more?

Related languages

The Disciple programming language supports similar low level imperative features to Pawns but uses "region" information rather than sharing information to limit interaction and effects. Disciple does more inference of region and side effect information than is done in Pawns, so there is more potential for "nasty surprises" and doesn't encapsulate effects to the same extent.

ML supports destructive update using data types containing ref and Haskell's STRef monad is similar. The type system limits interaction and effects. This has similar consequences to the Disciple approach with respect to nasty surprises and encapsulation and can also lead to multiple versions of a data type and extra indirection in the representation.

The scripting language Pawn has a similar name to Pawns but they are not at all closely related in other respects. Both are influenced by C. Pawn started life as a cut-down version of C and has no types or pointers (except it supports call by reference). Pawns combines C-style pointers with a nice type system and other benefits of pure functional programming.