Pancode - Commands - Miscellaneous

These are useful commands that simply didn't fit into any other category.

Defined-or (¿)

Takes two arguments. If the first is anything other than ε, then the first is returned. Otherwise, the second is returned. Subject to binary extension. If given a numerical modifier of 0 or a ⚐ argument, returns ε.

Stack Frame (s)

Pushes the currently executing function onto the stack. If used with a numerical modifier, the numerical modifier specifies how many call stack frames to traverse upward before getting the function. For instance, a numerical modifier of 1 will push the function which called the current function.

This can be used to implement recursive functions without assigning them a name. For instance, the following code defines and calls a recursive function that prints "Hello" forever.

« WARNING! This may lock up your browser! Run at your own risk! »

[ "Hello" . s $ ] $

Array Start Sentinel ({)

Pushes the array start sentinel onto the stack. See Symbols for more information.

White Flag Sentinel ()

Pushes the white flag sentinel onto the stack. See Symbols for more information.

Null Sentinel (ε)

Pushes the null sentinel onto the stack. See Symbols for more information.

White Flag Constructor ()

Given two functions f and d, this command defines and pushes a new function onto the stack. The new function will pop the top value off the stack and check if it is ⚐. If so, it calls d. Otherwise, it pushes the top value back and calls f.

Pragmatically, the reason you might care to use this is in the situation where you're performing a fold. The Fold (/) command, if given an empty list argument, pushes ⚐ onto the stack then calls its provided function. By calling ⚑ on your function, you can specify the desired behavior if given the empty list.

« The default + behavior is to return zero if given ⚐ »
{} `+ / « Result: 0 »

« However, we can provide our own default, if we wish »
{} `+ [ "Empty list!" ] ⚑ / « Result: "Empty list!" »

Box ()

Takes a single value and returns a box containing that value.

Unbox ()

Pops a single value off the stack. If that value is a box, then its contents are returned. Otherwise, the value itself is returned.

Store in Variable ()

Pops a value and a symbol off the stack. Stores the value in the global variable indicated by the symbol. This behaves like the special syntax, but this command has the advantage that the variable name can be determined at runtime.

Read from Variable ()

Pops a symbol off the stack. Pushes the value of the global variable indicated by the symbol. This behaves like the special syntax, but this command has the advantage that the variable name can be determined at runtime.

Documentation Index