Reverse and error!

You have to write a program, if its source code is reversed, then it will error.

For example, if your source is ABC, then reversing it and writing CBA should crash/throw an error. And ABC itself should be a vaild program (I mean your primary source should be a valid program). Output of the main source code can be empty, but your ABC code I mean primary source should not output anything to standard error.

Also the minimum length of a solution is 2 bytes.

Standard loopholes apply, shortest code wins.

• @Wasif Would be too similar to challenges in this vein: codegolf.stackexchange.com/questions/192979/… – Razetime Feb 27 at 7:06
• Basically any programming language (with the exception of Stack Cats) will error when its code is reversed. – Razetime Feb 27 at 7:10
• @Razetime another idea is too make the main source error and reversed one valid? (That might be more interesting) – Wasif Feb 27 at 7:10
• The question and its idea have already been posted. Changing that would make it a different question, and require all the answers to be deleted (also, that is effectively the same challenge) – Razetime Feb 27 at 7:13
• @Razetime another possibility to make this a little interesting is to restrict byte limit for this challenge (To 3-4 bytes or somehow like this), it would not require us to delete our answers, because everything is within 2-3 bytes, so possible solutions will be reduced – Wasif Feb 27 at 7:24

R, 2 bytes

NA


Try it online!

Outputs NA, which corresponds to "Not Available", to represent missing values.

On the other hand, AN errors, as it is literally not available.

A bunch of other examples:

1i
1L
ar
as
by
de
df
dt
gc
gl
Im
is
lh
lm
ls
pf
pi
pt
qf
qr
qt
Re
rf
rt
sd
ts
vi
{}
.C


Malbolge, 2 bytes

Errors via raising a SIGILL (illegal instruction).

DP


Try it online!

Try it reversed!

Explanation

Forward:

C [C] (C+[C])%94 Action
0 D (ord 68) 68 No operation.
1 P (ord 80) 81 Stop execution of current program.

Reversed:

C [C] (C+[C])%94 Action
0 P (ord 80) 80 Illegal instruction (stops program)
1 D (ord 68) 69 Illegal instruction (not executed)

Python 2, 2 bytes

And probably 1 million different languages too

+1


Try it online!

Python 2 or 3, 3 bytes

0/1


Try it online!

Try it online (Reversed)!

0/1 is a valid mathematical expression and will result 0 (will show nothing on TIO interpreter) 1/0 (reversed) causes a divide by zero error.

Polygots in a "loooottttttttttt" of languages

• Polyglot in about 9 million languages – pxeger Feb 27 at 7:00
• @pxeger I think so, answers are too broad! – Wasif Feb 27 at 7:01
• You can do better: [] is a valid line of code too. – Don Thousand Feb 27 at 19:22
• Two bytes: (), {}, [], 10, +0, ~0, -0, #!, 0;, and many, many more. – Makonede Mar 5 at 22:13
• Another option: 0\  (without the space) – Makonede Mar 6 at 19:57

Jelly, 2 bytes

D€


How it works

D€ - Main link. Takes no arguments
- Implicitly set the argument to 0 as the chain doesn't begin with a nilad
€ - Generate the range from 1 to 0 ([]) and over each element:
D  -   Get its digits
Output the empty list, which outputs nothing due to Jelly's output rules


skrow ti woH

€D - Main link. Takes no arguments
€  - € is a quick, which needs a preceding atom upon which to act
Without a preceding atom, parsing fails and the program errors
D - D is ignored as the program has errored


Alternative programs

There are far too many 2-byte programs that also work to fully list them. Instead, here's how to make your own:

1. Open Jelly on Try it online!
2. Open the Quicks page
3. Open the Atoms page
4. Choose any single character atom. Enter it into the TIO Code field (Copy-Paste works best)
5. Choose any single character quick. Enter it after the atom
6. Press Run.
7. If this errors, clear the characters and go to step 4

Python 3, 2 bytes

G B already posted one of those, but I wanted to show some more 2-byters:

+0
0,
~0
#\
id
0j
0;
{}
0


Try it all online!

Here is a more complete list.

JavaScript, 2 bytes

[]


Errors with ][

• @Wasif I know, this challenge is a little broad – Recursive Co. Feb 27 at 7:50

Unary Except Every Zero Is Replaced with the Title of This Programming Language or, Alternately, Is Replaced with the Smallest Counter-Example to the Goldbach Conjecture. Compilers and Interpreters Only Have to Implement the Former Option, 220626 bytes

too long to show here, but here is the full code

Bash, 2 bytes

wc


Try it online!

Try it online (Reversed)!

Don't think this one has a lot of "polygot"s

other 2-byters sh,ps,du,ls (if sl is not installed)

Windows Batch, 2 bytes

:a


This program is an empty label, if reversed then it would search for a drive named a:, but floppy drives are no longer available!!!

• My Windows VM has a virtual floppy drive, does that count? – Neil Feb 27 at 11:34

Vyxal, 2 bytes

i1


Explained

Before we begin, i takes two arguments (we'll call them a and b) and returns a[b] (indexing). 1 simply pushes 1 to the stack.

The program i1 is:

rhs, lhs = pop(stack, 2)
stack.append(lhs[rhs])
stack.append(1)


Because the stack is empty, implicit input is taken for lhs and rhs. And because there is no input, 0 is returned each time input is needed. Thus, i gives "0"[0] and then pushes 1.

The program 1i is:

stack.append(1)
rhs, lhs = pop(stack, 2)
stack.append(lhs[rhs])


Which attempts to push "0"[1], which is obviously out of the list. Vyxal doesn't have modular indexing (yet), so this errors.

• You always seem to answer in Vyxal because your username is very similar – Recursive Co. Feb 27 at 7:49
• Heh, funny about that. ;p – lyxal Feb 27 at 8:16
• Whereas in R, 1i is valid, but i1 isn't. ;-) – Robin Ryder Feb 27 at 8:17

naz, 2 bytes

1o


Any valid 2-byter will throw the error missing number literal if reversed; I just picked this one because it actually outputs something (0).

MATLAB/Octave, 2 bytes

pi


When run forward, this yields an approximation of pi represented as a floating point number. When reversed, it tries to execute the function named ip which is not defined:

octave:1> ip
error: 'ip' undefined near line 1, column 1


Java, 42 bytes

interface M{static void main(String[]a){}}


This is the shortest valid full Java program. It does not output anything. Since all methods in an interface are implicitly public, we can save bytes by putting the main method inside an interface instead of a class.

Try it online!

The reversed code is clearly invalid syntax:

}}{)a][gnirtS(niam diov citats{M ecafretni


Try it online!

Lua (2 bytes)

Write the following in the command line

=1


Although the =<something> is supported for backward compatibility, is a deprecated feature in Lua. 1= triggers the following error:

stdin:1: unexpected symbol near '1'


in Lua 5.4.2.

x86-16 machine code, 2 bytes

Full program. Error type is an unhandled SIGSEGV.

Hexdump:

00000000: 63c3                                     c.


Listing:

63         DB 63      ; Raises an unhandled SIGSEGV
C3         RET        ; Not executed


Listing (reversed):

C3         RET        ; Return to caller
63         DB 63      ; Not executed


[BASIC], 2 bytes

?a


Try it online!

a?


The reverse will just generate a Syntax Error

Basically (pun totally intended) if you can't make a 2-3 byte program in almost any language that'll crash if reversed, something is wrong!

MATL, 2 bytes

lt


Try it at MATL Online

Explanation

This program pushes the literal 1 to the stack and duplicates it using t. When reversed, t tries to grab it's input argument implicitly and since no inputs are provided it errors out

MATL run-time error: The following Octave error refers to statement number 1: t
---
Unable to fetch user input


Brain-flak, 2

()

Errors on )(

PHP, 2

$=?> does nothing <?=$ errors.