Related Posts

Pokélang — a Pokémon-inspired programming language

I was thinking about a possible basic level programming class that I could teach, one that would start with the low-level basics of all programming languages. Basic things like how calculations are performed and how logic structures work. Homework assignment would be creating a viable programming language based on these concepts: among the ideas I had were a visual language based on pipes, which were a metaphor for parallel processing, and this: Pokélang, a Pokémon-inspired, stack-oriented, object variable language.

A program begins with the selection of the various trainers available. Each trainer brings a specific set of monsters, which correspond to various types of operations, such as mathematical, matrix, database, etc. This is equivalent to the header file specifications of the C language. (I understand there might be more specific language used to announce combatants from the various animated TV productions but I’m not that up on Pokémon trivia.)

Variables and operations are Pokémon monsters: variables are specified by one trainer and the operations as attacks by Pokémon monsters by the other trainer. Variables are pushed on to the stack when choosing a specific monster, where the variable is defined as the strength of the monster. Operations are then performed by the special attacks of any given monster of the opposing trainer. Both trainers may specify monsters as variables, especially in cases of constants like π or ∞, and both trainers may use monster attacks, but must alternate operations (unless performing combination attacks.)

Other language syntax:

  • All operations (variable definitions and program operations) begin with the name of the trainer. Success and error messages (when necessary, in places where there is a possibility of failure) returned are prefaced by “Gym”.
  • All monsters and attacks are capitalized.
  • Attacks are denoted by ending with an exclamation point.
  • All text within parentheses are treated as comments.
  • Variables are implicitly defined in context but may be explicitly defined for clarity.
  • Matrix definitions (as seen below) are defined using square brackets.
  • There are no winners or losers.

The following is a simple example of multiplying and inverting a simple matrix.

Trainers Ash, Amanada. (Ash is the basic collection of stack operation routines: it has no other operations and requires at least one additional trainer to do any kind of functional work. Amanada is the collection of matrix operations.)

Ash: I choose Stateveon with Strength of Integer 2. I choose Satreon with Strength of Matrix [ [2, 1], [1, 3] ]. (This defines a scalar variable with the integer value of 2 and a matrix variable with the value of ( ( 2, 1 ), ( 1, 3 ) ). Both are pushed on to the stack in order of choosing upon definition, so Statevon is below Satreon on the stack.)

Amanada: I choose Matrixeon. (This is the basic matrix operations monster.)

Amanada: Matrixeon, perform Combination Attack!

Amanada: Matrixeon uses Multiply! (The top two elements on the stack are multiplied and the result of ( ( 4, 2 ), ( 2, 6 ) ) is pushed on the stack.)

Amanada: Matrixeon uses Inversion! (The array on top of the stack is inverted.)

Gym: Its Super Effective! (The inversion was successful. The result of ( ( 0.3, ‑0.1 ), ( ‑0.1, 0.2 ) ) is placed on the stack. If the matrix was a singular matrix, meaning the determinate is zero as in the case of ( ( 4, 2 ), ( 6, 3 ) ) ), an error message would be displayed, instead.)

Ash: Satreon returns to the Pokéball. (The result is popped off the stack and stored in the named remote variable or output to display to the user / programmer.)

That’s about as far as I got.

This is not a language that is capable of more in the way of controlling program flow. Stack operations can be tricky when it comes to logic decisions, so this is more suited to straightforward yet involved calculations, sort of like early FORTRAN.

Share
The short URL of the present article is: http://www.terryobrien.me/3H0Ne

Comments are closed.