14
\$\begingroup\$

Your task is simple: Write a program that can be run in two languages. It should be a normal quine (prints its own source code) in language 1, and should be an error quine (generates an error message identical to its own source code) in language 2.

This is , so the shortest valid submission (in bytes) wins.

Rules:

  • The languages may be arbitrarily similar. Supersets/similar versions/similar dialects are not disallowed.
  • The error quine rules are the same as those in Make an Error Quine!.
\$\endgroup\$
  • \$\begingroup\$ Related, and Related. \$\endgroup\$ – Esolanging Fruit May 28 '17 at 6:04
  • \$\begingroup\$ Are two different dialects of BASIC allowed? \$\endgroup\$ – MD XF May 29 '17 at 4:28
  • \$\begingroup\$ @MDXF If they have the exact same behavior except that one outputs to STDERR instead, then no. Otherwise, yes. \$\endgroup\$ – Esolanging Fruit May 29 '17 at 6:31
  • \$\begingroup\$ So my answer is valid, then. \$\endgroup\$ – MD XF May 29 '17 at 14:58
  • \$\begingroup\$ @MDXF It is valid. \$\endgroup\$ – Esolanging Fruit May 29 '17 at 20:41
2
\$\begingroup\$

Befunge-93 (FBBI) / C (tcc), 93 + 62 = 155 bytes

^"
>#001p#"<>:#,_@#1-8*3:-1*57+55-1*79*57:-1:*77**278\-1:*57$p:1: error: declaration expected

Try it online!: Befunge-93, C

Thanks to randomdude999 for noting that the filename requires matching quotes to work.

Must be saved under the filename ^"\n>#001p#"<>:#,_@#1-8*3:-1*57+55-1*79*57:-1:*77**278\-1:*57$p, where \n is a newline. Because of this, the TIO for C doesn't run exactly as intended. Tested to work on Lubuntu.

Explanation (C):

The program fails to compile, and tcc happily outputs the name of the file as part of its error message. There are multiple compilation errors you can get, based on the beginning of the code. ^ at the start gives us a declaration expected, which is short and doesn't contain any problematic characters like ". On the other hand, the gcc and clang developers are very pessimistic and they chose to output multiple errors at once, which is not very nice, so we aren't using their compilers.

Explanation (Befunge-93):

Befunge is convenient for quines in that its code can also be utilised as character data, thanks to the " command, which toggles string mode. At the beginning, we perform some useless stack operations, then issue a p (put command) which places a NUL character at (0, 1). Then we reflect the instruction pointer to the left and begin reading everything as a string. This has to be done to the left, because of the stack's LIFO nature. After wrapping around and reaching the " character again, the string ends. Note that the NUL character replaced the $ character, creating a delimiter midway through the string. We then push 3 numbers onto the stack and jump over the NUL (because it unfortunately hangs the interpreter when run as an instruction). The static part of the error message has to be executed here. Most of its characters are no-ops, but the p command consumes three arguments (hence why we pushed 3 numbers, otherwise part of the string would be eaten here), and : & 1 characters push a total of 4 values to the stack, which we counteract with a p and a $ (pop and discard) instruction. Then, some arithmetic is performed to push the ASCII codes for ^"\n>#001p#" and finally a loop prints out all the values on the stack as characters until it finds a NUL character and terminates.

\$\endgroup\$
  • \$\begingroup\$ You need to find an OS that supports such a filename and list it. I know Windows doesn't support that. \$\endgroup\$ – mbomb007 Jun 16 at 20:08
  • \$\begingroup\$ @mbomb007 Supposedly, Linux will usually accept any printable character in a filename except for /. I can't test that myself right now. \$\endgroup\$ – negative seven Jun 16 at 20:10
  • 1
    \$\begingroup\$ What version of tcc did you use? I'm using 0.9.27-3 straight from Arch repos, and the error I get is <define>:1: error: missing terminating " character. \$\endgroup\$ – randomdude999 Jun 16 at 20:26
  • 1
    \$\begingroup\$ Alright, I found the exact version of tcc used on TIO, and I got the same error message, but only if the quotes of the filename match. Having unmatched quotes seems quite necessary for this answer to function. Here's something that may help you out: Linux also allows newlines in filenames. This is the tcc output when adding a newline and a quote to the end of the filename: (long gist link). This does mean you'll need to find a way to print the newline and the stuff on the 2nd line though. \$\endgroup\$ – randomdude999 Jun 16 at 20:56
  • \$\begingroup\$ @randomdude999 Thanks. I've updated the solution to account for this. Quite interesting indeed that an unmatched quote causes such an issue... \$\endgroup\$ – negative seven Jun 16 at 21:52
0
\$\begingroup\$

Applesoft BASIC / Commodore LCD BASIC, 13 bytes

?SYNTAX ERROR

In the Apple ][ emulator, hit the RESET key to enter BASIC mode.
In the Commodore LCD emulator, hit RightArrowEnter to get into the BASIC application.
In both of them, don't type ?SYNTAX ERROR in all caps, because they automatically capitalize.

\$\endgroup\$
  • 2
    \$\begingroup\$ non-competing status is reserved for submissions in languages that were made after the challenge. If it is invalid according to the rules, delete it. Await OP's confirmation first because I think this should be valid (assuming it works). \$\endgroup\$ – HyperNeutrino May 29 '17 at 5:05
  • \$\begingroup\$ @HyperNeutrino Thanks, edited. \$\endgroup\$ – MD XF May 29 '17 at 14:57
  • 1
    \$\begingroup\$ Going to have to suspect this one too, then. This question is rather more brutal than it looks... \$\endgroup\$ – Ørjan Johansen May 30 '17 at 18:48
  • 1
    \$\begingroup\$ @ØrjanJohansen Well, I'm not so sure about this one. Technically, the Commore LCD had no standard error byte stream, so is it really an error quine? \$\endgroup\$ – MD XF May 30 '17 at 18:50
  • 1
    \$\begingroup\$ @ØrjanJohansen this? I guess that could mean it's impossible to tell whether this is valid or not. We could wait for confirmation from the OP? \$\endgroup\$ – MD XF May 30 '17 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.