Meta quine checker

10

1

This challenge, if you accept it, is to write three functions or programs A, B, and C:

  • A is a quine that outputs all of A,B and C (which is also the whole content of the code in your submission).
  • B takes a parameter F and checks whether it is such a quine (outputting FBC), or doing something different.
  • C takes a parameter G and checks whether G possibly works like B (checking whether F outputs FGC). It is impossible to decide whether a function is a quine checker, so let's do something simpler:
    • It must return truthy if G is valid for B.
    • It must return falsey if G returns falsey for all valid quines, or G returns truthy for all valid non-quines.
    • It can return anything, crash or not terminate, etc, if it is any of the other cases.

Note that B is possible. A and F doesn't have any input, so you can just run them and check the result.

Rules

  • There should be some way to tell which parts are A, B and C from the output of A. For example: each has one line, or they are recognized as three functions in the interpreter.
  • Each function should run with only the definition of itself, not your complete code.
  • You can use a function/program or its source code, or a pair of both as the input of B (or G) and C.
  • You can redefine truthy/falsey to a subset of those values. You can also consistently require F returning some type you choose, like a single string.
  • You can require A, B, F and G, if they are called with valid parameters, consistently don't have some types of other inputs or side effects you choose, such as accessing global variables, or reading stdin, etc.
  • You can also assume F and G, if they are called with valid parameters, always terminate.
  • F should work in the same condition as A. So it cannot depend on B or C or another variable's existence, unless that variable is defined in its own part in its output.
  • No functions or programs can read its own source code.
  • This is code-golf, shortest code (which is the output of A) in bytes wins.

jimmy23013

Posted 2015-04-16T01:25:34.343

Reputation: 34 042

B is still impossible in general because F might not terminate, as well as in practice in many languages because it requires combinations of abilities like temporary redirection of stdout and either function-to-string or exec. The best you can hope for is probably a half-working solution in a LISP. – Peter Taylor – 2015-04-16T07:47:48.760

How would you check G with all quines and non-quines? I'm currently working on a Mathematica solution. – LegionMammal978 – 2015-04-16T10:35:14.390

@PeterTaylor "You can also assume F and G, if they are called with valid parameters, always terminate." And "output" can mean return, not necessarily print to stdout. – jimmy23013 – 2015-04-16T15:04:41.720

@LegionMammal978 It is impossible to check all quines and non-quines. But the task of C is something simpler, where you only need to check one quine and one non-quine. – jimmy23013 – 2015-04-16T15:08:03.557

@PeterTaylor Though not required, temporary redirection is possible in PHP, bash, and you can temporarily modify the console.log function in JavaScript and you can assume F never know. – jimmy23013 – 2015-04-16T15:14:07.830

For languages without built in eval, can F and G be ordered pairs of source and a function. – PyRulez – 2015-04-18T02:38:11.963

1@PyRulez I think this is in the spirit of this challenge, so I'm going to allow it. But the function cannot access its own source code. – jimmy23013 – 2015-04-18T03:20:21.967

Answers

1

CJam, 254 bytes

An example answer, not golfed.

{{['{\"_~}{{[1$'{@\"_~}"{{["_~}"2$+'{@"_~}"]s`"{{['{\\"\+"]s}_~}"+~1$~{L}@~!&}_~}_``1>W<"\"]s\~=}_~}"@]s}_~}{{[1$'{@"_~}{{[\"_~}\"2$+'{@\"_~}\"]s`\"{{['{\\\\\"\+\"]s}_~}\"+~1$~{L}@~!&}_~}"]s\~=}_~}{{["_~}"2$+'{@"_~}"]s`"{{['{\\"\+"]s}_~}"+~1$~{L}@~!&}_~}

The 3 functions are:

{{['{\"_~}{{[1$'{@\"_~}"{{["_~}"2$+'{@"_~}"]s`"{{['{\\"\+"]s}_~}"+~1$~{L}@~!&}_~}_``1>W<"\"]s\~=}_~}"@]s}_~}
{{[1$'{@"_~}{{[\"_~}\"2$+'{@\"_~}\"]s`\"{{['{\\\\\"\+\"]s}_~}\"+~1$~{L}@~!&}_~}"]s\~=}_~}
{{["_~}"2$+'{@"_~}"]s`"{{['{\\"\+"]s}_~}"+~1$~{L}@~!&}_~}

A and F take no parameters and return a string. B, G and C take a CJam block as parameter and return 1 for truthy, or 0 for falsey.

jimmy23013

Posted 2015-04-16T01:25:34.343

Reputation: 34 042