SpaghettiScript

From Esolang
Jump to navigation Jump to search

SpaghettiScript is a joke language created by User:UltimateProGrammer in 2020. It is similar to bf, but with functions instead of loops. All code in SpaghettiScript is called spaghetti code. It is tape based, and Turing-complete. Each number on the tape starts at zero, and is called a cell. The fork points to cells. The syntax is as follows:

Command Explanation
[ Start a function. Must be followed by a positive integer representing the function's number, then valid spaghetti code.
] End a function.
- Subtract 1 from the value on the current cell.
~ Add 1 to the value on the current cell.
or The fork position is moved right one. The second option can be chosen for better Unicode support.
or The fork position is moved left one. The second option can be chosen for better Unicode support.
:O Output the current cell's value.
:o Set the current cell's value to input.
{o=(digit)} Only run the following fork function call if the stomach (current cell, represented by o) is equal to the digit following the equals sign.
---≡ Call the function with the number immediately following the fork.
===≡ 'Goto' the function with the number immediately following the fork. Execution in the current function will be suspended (no more code within it will be run)

Optional Commands

Commands that are not part of the spec, though can/should be used in an implementation.

Command Explanation
O Hold the current cell's value in memory
≡O Set the current cell's value to what is in memory
:OA Outputs the current value in memory as ascii.
Forcefully "flushes" the current output. Useful for outputting between inputs.

Notes:

  • Some commands in SpaghettiScript are Unicode, so it may not look correct on devices without Unicode support.
  • Functions cannot be defined inside other functions
  • If the fork function call starts with dashes (-), the position on the tape will be set to 0 when the function is called. If it starts with tildes (~), the tape will stay where it was when the function was called.(note: currently unimplemented)

Examples

Hello World (newlines for readability):

[1~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:OA
⇢~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:OA
⇢~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:OA
⇢~~~~~~~~~~~~~~~~~~~~~~~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{o=0}---≡2 ---≡1] [2] ---≡0
Converting code from other languages

For loop:

[1 (for loop code here) -{o=0}---≡2 ---≡1]

While loop:

[1 (while loop code here) {o=0}---≡2 ---≡1]

Implementation

The modern implementation is available here. It was created by UltimateProGrammer (talk) originally in 2020, but updated to match the language specification in 2022.

Keyboard Shortcuts (for typing Unicode)
Shortcut (Cmd works on MacOS) What Happens
ctrl+= Types '' at the cursor
ctrl+- Types '~' at the cursor
ctrl+; or \ Types '' at the cursor
ctrl+, or [ Types '' at the cursor
ctrl+. or ] Types '' at the cursor
ctrl+s Save the current spaghetti code
ctrl+l Load the most recently saved spaghetti