logo Pounce Sampler

A catalog of example Pounce programs.

Pounce is Concatenative

Pounce is a Concatenative language, influenced by Forth, Postscript, Joy, Cat and Kitten.

A Concatenative language provides for the "composition of functions" as a first class operation and programs are constructed by composing functions together. For more information on Concatenative languages,  concatenative.org is a comprehensive resource. Additionally the concatenative programming paradigm

Examples are interactive (code in blue boxes) so you can edit the code (try entering 21 2 * below) and see results in the orange box below.

running:
yields:
2

Enjoy exploring Pounce!

Post-fix

Pounce is a post-fix language. Notice that data (nouns) come first followed by verbs. For instance, when adding three and five, the nouns are 3 5 followed by the verb + . Then multiply by seven 7 * . Post-fix eliminates any need for operator-precedence rules or parentheses.

running:
yields:
56

Lists and Phrases

Words can be placed in a list where they are considered as nouns. For example cons is used to make a list of 10 and *

running:
yields:
[10 *]

A list is sometimes called a 'phrase' when the intent is to recite the phrase as a verb at some later time, like this:

running:
yields:
50

Fibonacci Numbers

To make this sequence, first the stack is seeded with 0 1, then adding more elements is done with dup2 which duplicates the top two elements of the stack. Adding them together creates the next Fibonacci number. Repeat this n times.

running:
yields:
0 1 1 2 3 5 8

Compose a New Word

To define a new word, two lists are needed: first a composition of words (a phrase) and then the name of the new word wrapped in a list. In post-fix style, compose comes after and adds this new word.

running:
yields:
42

Recursive Words

A 'factorial' function can be made using recursion. This composition of words is added to the dictionary and given the name fac and fac includes in its own phrase.

As with any recursive function, an 'if' clause is needed to test for the terminal case.

running:
yields:
120

linrec for Linear Recursion

A second version of 'factorial', this time without having to compose and name your own (recursive) word. Instead, linear recursion (linrec) does this with four short phrases.

running:
yields:
120

The words crouch and pounce allow references to stack values by name

The order of stack values is important, so crouch and pounce let you refer to them byh name. These are not variables, more like 'named' stack items.

For example: if 5 7 are on the stack. A list of names [a b] a is matched with 5 and b with 7

When a name is used in the phrase, it will be replaced with the value from the relative stack position. This is more convenient than doing lots of stack shuffling to achieve the same result.

Here is the formula for the slope of a line. OK, this may not be 'point-free', but no variables are bound in the process, so think of this as coping 'in' of stack values into your phrase.

running:
yields:
7

Prime Factors

A phrase to calculate the prime factors uses linrec to recursively break a number down to its prime factors.

running:
yields:
[53 2 2]

Map Filter Reduce

Stating with a list of numbers, map runs a phrase (as a function) on each element of the list [2 *].

running:
yields:
[12 6 16 8 10 14 4 18 2]

filter a list with a match phrase (even numbers) [2 % 0 ==].

running:
yields:
[6 8 4 2]

reduce a list by starting with 1 and accumulating a value with [*]

running:
yields:
362880

Combining reduce with pouncecan make a more complex reducer easier to understand

running:
yields:
[497 7]

Quicksort

Given a list of numbers to sort, binary recursion. binrec is used to process both sub lists made by [>] split

running:
yields:
[1 2 3 4 5 6 7 8 9]

A list of strings, same deal.

running:
yields:
[a b c d e f g h i]