pd.NA

From Esolang
Jump to navigation Jump to search

pd.NA is a programming language inspired by Branflakes. It is an extension of Branflakes which allows null or missing values in its cells.

Overview

pd.NA operates on a tape of cells, which can contain either a byte or an NA, which propagates through arithmetic operations such as increment and decrement.

If the output command . is used when the current cell is NA, it is undefined behaviour. The input command , yields NA on EOF.

So here are the basic instructions:

Hex digits are in lowercase.

  • > - Move the pointer forwards one cell.
  • < - Move the pointer backwards one cell.
  • : - Set the cell to zero.
    If followed by two hex digits, sets the cell to the specified value.
  • + - Increment the cell by one.
    If followed by two hex digits, increments by the specified value.
  • - - Decrement the cell by one.
    If followed by two hex digits, decrements by the specified value.
  • ? - Set the current cell to NA.
  • ^ - Push the cell value to the stack.
  • v - Pop the stack and store it to the current cell.
  • . - Print the cell as an ASCII character.
  • , - Input a character and store it into the cell.
  • & - Clear the output.
  • = - Pop two values off the stack, and set the cell to their sum.
  • _ - Pop two values off the stack, and set the cell to their difference (second-first).
  • * - Pop two values off the stack, and set the cell to their product.
  • / - Pop two values off the stack, and set the cell to their quotient (second/first). Division by zero produces NA.
  • % - Pop two values off the stack, and set the cell to their modulus (second%first). Modulo by zero produces NA.
  • [ - Start a loop which runs while the current cell is nonzero. If the cell is NA when the condition is checked, throw an error.
  • ] - End a loop.
  • ( - Start an if statement which runs if the current cell is nonzero. If the cell is NA when the condition is checked, throw an error.
  • | - Else in if statements.
  • ) - End an if statement.
  • # - Break out of a loop.
  • " - Starts and ends a comment.

So, with all these errors, how do you check if a cell is NA, you might ask? It will be explored in the next section!

Try/Catch blocks

So far, we have found that NAs can cause errors inside loops. But we haven’t found a way to stop these errors and check for NAs.

To check for NAs, we use try/catch blocks similar to those in other programming languages.

To create a try/catch block, use this syntax:

   { TRY CODE | CATCH CODE }

The block will run the “TRY CODE”, but when you are about to get an “comparison with NA is ambiguous” error, the “TRY CODE” will stop, and the program jumps to the “CATCH CODE”. Unlike if staments and loops, try/catch blocks do not nest.

An example of try-catch blocks:

   {( "Cell is nonzero" | "Cell is zero") | "Cell is NA"}

Computational class

Turing-complete, because it contains all Branflakes commands.