Pancode - Commands - Higher Order Functions

The following commands deal with the construction of functions of particular types from existing functions. Almost all of these commands either take a function as an argument or return one.

As a general note, the printed representations of functions produced by these commands may look more complicated than the actual behavior the functions provide. There are internal optimizations taking place which allow the produced functions to store relevant information faster than the equivalent handwritten code but which complicate the printed representation somewhat.

Identity Function (ī)

Pushes a function to the stack which, when called, does nothing. This is equivalent to [].

Constant Function (c)

Takes a single value and returns a function which, whenever called, returns that value. If this command is given a numerical modifier N, the resulting function will first pop N elements from the stack before returning its constant result.

Example:

10 c « Pushes a function equivalent to [10] »
10 c① « Pushes a function equivalent to [% 10] »

Curry ()

Pops two arguments. The first can be any value and the second must be a function. This command returns a function which, when executed, pushes the first value onto the stack and then calls the function.

If given a numerical modifier N, that numerical modifier specifies how many values to pop (excluding the function itself). All popped values will be pushed onto the stack each time the function is called.

Example:

10 [+] ● « Pushes a function equivalent to [10 +] »

Compose ()

Takes two functions and returns a new function which calls the first function and then calls the second. Subject to binary extension. Returns the identity function if given a numerical modifier of zero or a ⚐ argument.

Example:

[5 +] [2 ×] ○ « Pushes a function equivalent to [5 + 2 ×] »
Documentation Index