Quine/Error Quine Polyglot

14

1

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!.

Esolanging Fruit

Posted 2017-05-28T06:04:05.970

Reputation: 13 542

Related, and Related. – Esolanging Fruit – 2017-05-28T06:04:34.207

Are two different dialects of BASIC allowed? – MD XF – 2017-05-29T04:28:02.770

@MDXF If they have the exact same behavior except that one outputs to STDERR instead, then no. Otherwise, yes. – Esolanging Fruit – 2017-05-29T06:31:49.893

So my answer is valid, then.

– MD XF – 2017-05-29T14:58:18.443

@MDXF It is valid. – Esolanging Fruit – 2017-05-29T20:41:10.220

Do C and C++ count as the same language / supersets? – MD XF – 2017-05-30T18:24:05.787

@MDXF I don't see why you're asking. I explicitly said that languages can be arbitrarily similar. – Esolanging Fruit – 2017-05-30T19:07:51.270

@MDXF But no, they do not. – Esolanging Fruit – 2017-05-30T19:08:03.243

Sounds good, thanks. Most polyglot challenges define C/C++ submissions as invalid. – MD XF – 2017-05-30T19:08:30.547

Since error messages frequently display the filename, can I specify an exact filename? And can it contain code that will be executed? – Jo King – 2019-05-25T03:29:11.837

Answers

2

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.

negative seven

Posted 2017-05-28T06:04:05.970

Reputation: 1 931

You need to find an OS that supports such a filename and list it. I know Windows doesn't support that. – mbomb007 – 2019-06-16T20:08:28.903

@mbomb007 Supposedly, Linux will usually accept any printable character in a filename except for /. I can't test that myself right now. – negative seven – 2019-06-16T20:10:25.073

1What 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. – randomdude999 – 2019-06-16T20:26:40.383

1

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.

– randomdude999 – 2019-06-16T20:56:03.970

@randomdude999 Thanks. I've updated the solution to account for this. Quite interesting indeed that an unmatched quote causes such an issue... – negative seven – 2019-06-16T21:52:50.623

Yup, can confirm it works on my Arch now. – randomdude999 – 2019-06-16T23:31:21.660

0

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.

MD XF

Posted 2017-05-28T06:04:05.970

Reputation: 11 605

2non-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). – HyperNeutrino – 2017-05-29T05:05:19.793

@HyperNeutrino Thanks, edited. – MD XF – 2017-05-29T14:57:50.413

Please update.. – CalculatorFeline – 2017-05-29T23:16:50.960

1Going to have to suspect this one too, then. This question is rather more brutal than it looks... – Ørjan Johansen – 2017-05-30T18:48:51.577

1@Ø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? – MD XF – 2017-05-30T18:50:08.387

As Challenger5's last comment on the error quine thread implies, that's hard to define objectively. :( – Ørjan Johansen – 2017-05-30T19:00:58.253

1

@Ø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?

– MD XF – 2017-05-30T19:02:39.680

I undelete my answer because it didn't seem substantively different from this. The language prints "?SYNTAX ERROR" on all syntax errors (on whatever stream); it's a language feature instead of a property of the program itself. – Robert Fraser – 2017-05-30T19:08:49.477

@RobertFraser Yes, but the fact that /// prints everything except a slash makes it cheating. BASIC does not print everything except a certain character set. – MD XF – 2017-05-30T19:09:52.600

Either way seems to be exploiting language choice instead of actually programming but whatever. – Robert Fraser – 2017-05-30T19:12:48.640

Brainfuck ignores all characters that aren't commands, so be careful betting your money... I'm pretty sure that's possible as long as you don't require it to be short. (I'm too lazy though.) – Ørjan Johansen – 2017-05-30T20:03:42.953

@ØrjanJohansen Oh that's right. Comment deleted :P – MD XF – 2017-05-30T20:05:19.913

My point is: the vast majority of possible inputs to /// output the same as their input. The vast majority of possible inputs to BASIC output "?SYNTAX ERROR". There's no real problem solving to either method. https://codegolf.meta.stackexchange.com/questions/4877/what-counts-as-a-proper-quine says that one part of the program must encode another part. If my answer is invalid, this should definitely be invalid also.

– Robert Fraser – 2017-05-31T00:51:34.120