Focal-2D

From Esolang
Jump to navigation Jump to search

Focal-2D programming language.

This language is based on the previously created "sim41 emulator".

The emulator is an implementation of the Hewlett Packard HP41 calculator. The original language of the HP41 was known as "The forty one calculator language -Focal-"

Focal-2D programs could be written on a two dimensional grid. The original language for the HP41 was "one dimensional" That language could be written using a single column of steps only. Each row contained a single programming step.

The novelty of Focal-2D is related to each step is contained in a cell. That cell is part of a 2D grid.

On the original HP41 programming language, the programs were read from top to bottom , step by step.

On Focal-2D exist the concept of direction of evaluation. This direction could be "up", "down", "left" or "right". Depending of the current direction of evaluation, the following step is read from an adjacent cell according to the present direction.

There are programming commands (exclusive of Focal-2D) used to change the direction of evaluation.

If the present direction of evaluation in a program is from left to right, then:

\\ changes it to from top to down.
// changes it to from down to top.

Example:

( Set the initial direction of evaluation to left-right )

(Assume each programming command saved on a cell. Here I will use spaces instead of cell separators )

+ 2 \\
     *

executes the instructions:

1.) + (sum the first two values of the stack and place the result on the first stack level)

2.) 2 ( enter the number two to the stack )

3.) * (Multiply the first two values of the stack and put the result on the first stack level)

A similar program using // is:

     *
+ 2 //

In this case // changed the direction to "down to top" and later the "*" command was evaluated.

In general:

If present direction is "top-down" // changes it to "right-left"

If present direction is "top-down" \\ changes it to "left-right"

If present direction is "down-top" // changes it to "left-right"

If present direction is "down-top" \\ changes it to "right-left"


If present direction is "left-right" // changes it to "down-top"

If present direction is "left-right" \\ changes it to "top-down"

If present direction is "right-left" // changes it to "top-down"

If present direction is "right-left" \\ changes it to "down-top"


Details of the implementation could be found searching internet for the "HP41 Emulator Page and MyRPL calculators". Or go to https://sim41.webcindario.com/.