SwitchCase

From Esolang
Jump to navigation Jump to search

SwitchCase is an esolang invented by User:None1.

Memory

SwitchCase uses variables containing unbounded signed integers.

At the start of program, the only variable is _, which is zero.

Control flow

The only control flow is switch-case, it is like this:

$<variable name>
<integer1>?<commands1>
<integer2>?<commands2>
<integer3>?<commands3>
...
!<command>

It executes commands1 if value of variable name equals to integer1, executes commands2 if value of variable name equals to integer2, executes value of commands3 if variable name equals to integer3, etc, executes the commands after ! if none of the conditions are satisfied, the ! part is not required, in this case, nothing will be executed if none of the conditions are satisfied, but there must be at least one ? part. Duplicate integers before the question mark is forbidden.

You must use control flow to execute commands.

Commands

+<nonnegative integer> Adds current variable in the switch case by <nonnegative integer>
-<nonnegative integer> Subtracts current variable in the switch case by <nonnegative integer>
, Input current variable in the switch case as ASCII
# Input current variable in the switch case as integer
. Output current variable in the switch case as ASCII
@ Output current variable in the switch case as integer
'<positive integer> Jump to the <positive integer>-th switch case
=<variable> defines a variable, initially zero

Examples

Hello World

$_
0?+72.
$_
72?+29.
$_
101?+7.
$_
108?+0.
$_
108?+3.
$_
111?-67.
$_
44?-12.
$_
32?+55.
$_
87?+24.
$_
111?+3.
$_
114?-6.
$_
108?-8.
$_
100?-67.

Truth Machine

$_
0?#
$_
0?@
1?@
$_
1?'2

Computational class

Turing complete, because you can compile the two register minsky machine to it:

Initialize:
$_
0?=A=B

Increment A:
$A
0?+1
!+1

Increment B:
$B
0?+1
!+1

If A=0, jump to the i-th minsky machine command, otherwise decrement A:
$A
0?'i
!-1

If B=0, jump to the i-th minsky machine command, otherwise decrement B:
$B
0?'i
!-1