Related to this quine answer. There was this comment:
That meta question is not applicable to this answer.
document.body
is not a function which you've created and are now printing the source of.document.body
is a function that returns an object with string attributes that contain the source code of the program. – Jo King
This comment basically says there is some abstraction between the source code and accessing it. To me, this still looks like the same thing as reading your own source code.
Should this be allowed in quines?
This is not a duplicate of What counts as a proper quine?
Even though the question is similar, there were enough likes on my questions in the comments on the JS answer that there is obviously still some clarification needed.
3 Answers 3
If someone submits a program as "C (Linux)" which opens /dev/sda1
(typically the primary disk drive) and searches for the source of the program, that is reading its own source code, even though it doesn't technically open "the" file containing it.
Extracting a JavaScript program from document.body
seems to me to be a direct analogue. There's a level of indirection, but it looks like a duck and quacks like a duck. It shouldn't be considered a permissible technique in a true quine.
-
6\$\begingroup\$ I agree with your answer, and I wonder why people aren't applying the quack test to this situation. Do you have any thoughts? It seems to me that the JS programs are pretty directly reading their own source code \$\endgroup\$dylnan– dylnan2018年05月02日 21:37:16 +00:00Commented May 2, 2018 at 21:37
-
\$\begingroup\$ I think a line could be drawn between whether the function/attribute you're accessing was declared by you, or by the program on startup. The CJam and JS quines both create the function, then print it, while
document.body
is already there \$\endgroup\$Jo King– Jo King2018年05月08日 07:17:33 +00:00Commented May 8, 2018 at 7:17 -
\$\begingroup\$ @JoKing, to whom is that comment addressed? I'm not sure whether it's intended for dylnan or attached to the wrong post. \$\endgroup\$Peter Taylor– Peter Taylor2018年05月08日 09:48:15 +00:00Commented May 8, 2018 at 9:48
-
\$\begingroup\$ @PeterTaylor Mostly dylnan's comment, sorry for the confusion \$\endgroup\$Jo King– Jo King2018年05月08日 09:49:31 +00:00Commented May 8, 2018 at 9:49
-
\$\begingroup\$ If you also count the first parsing as "reading source" then there's just no proper quine exist --- System must read the program to know what to do, so we have to allow it, making your expression only apply to
document.body.innerHTML
(or if more strict, if they're same) \$\endgroup\$l4m2– l4m22023年11月15日 17:16:55 +00:00Commented Nov 15, 2023 at 17:16
It must be possible to identify a section of the program which encodes a different part of the program. ("Different" meaning that the two parts appear in different positions.)
So, these are invalid:
<img onerror="alert(document.body.innerHTML)" src="#">
<img onerror="alert(this.outerHTML)" src="#">
<body onload="alert(document.body.outerHTML.slice(0,-7))">
<div id="r"><script>setTimeout("alert(r.outerHTML)")</script></div>
It's just nothing about document.body
-
\$\begingroup\$ Yes, those are all invalid. The reason that
document.body
is being disallowed is that, in general, the only thing you can do with it is indirectly read the source code. \$\endgroup\$Jo King– Jo King2018年05月14日 13:39:03 +00:00Commented May 14, 2018 at 13:39 -
\$\begingroup\$ You've only copied the first half of the definition. The second half says
Furthermore, a quine must not access its own source, directly or indirectly.
\$\endgroup\$Jo King– Jo King2018年05月14日 21:21:41 +00:00Commented May 14, 2018 at 21:21 -
\$\begingroup\$ @JoKing True. but with the definition before, the "access own source" seems only point to file operation \$\endgroup\$l4m2– l4m22018年05月15日 01:20:36 +00:00Commented May 15, 2018 at 1:20
-
\$\begingroup\$ Nope. See SMBF quines, Befunge/><>'s get command, Del|m|t. Generally, if you didn't create the representation of the source, you're not allowed to access it. \$\endgroup\$Jo King– Jo King2018年05月15日 02:07:12 +00:00Commented May 15, 2018 at 2:07
-
\$\begingroup\$ @JoKing Also if you claim
document.body is a function that returns an object with string attributes that contain the source code of the program
why don't you say(global) is an object with sub attributes that contain the source code of the program
? \$\endgroup\$l4m2– l4m22019年06月24日 08:27:59 +00:00Commented Jun 24, 2019 at 8:27
In the situation the link point, document.body.innerText
don't point to the source code at all
document.body
. That alone is enough reason to have this question. \$\endgroup\$