56
6
Long-time lurker, first-time poster. So here goes.
In the Wikipedia page for quine, it says that "a quine is considered to be 'cheating' if it looks at its own source code." Your task is to make one of these "cheating quines" that reads its own source code.
This is code-golf, so the shortest code in bytes - in each language - wins. This means that a 5-byte Pyth script would not beat a 21-byte Python script - but a 15-byte Python script would.
You must use file I/O to read the source code, so the following JavaScript code, taken from the official Wikipedia page, is invalid:
function a() {
document.write(a, "a()");
}
a()
It must access the source code of the file on disk.
You are not allowed to specify the file name. You must make it detect the filename itself.
Everyone clear? Go!
Is it allowed to specify the name of the file that the program is run in? How should that be scored? – isaacg – 2015-10-29T22:01:05.460
1Is a trailing newlines not present in the original file allowed? – isaacg – 2015-10-29T22:04:37.320
3@isaacg IMHO That's not a quine, since it is not the source code. – mınxomaτ – 2015-10-29T22:05:28.830
3You should state a requirement that it determine the actual filename instead of assuming a hard-coded string for the source location. – feersum – 2015-10-29T22:26:09.270
3I agree with @feersum though, that requiring a specific file name makes this challenge way to trivial. – mınxomaτ – 2015-10-29T22:33:52.320
@isaacg No, it isn't. I'll add that to the OP – TheInitializer – 2015-10-29T23:01:29.780
1Can we assume that (for compiled languages) the source code is in the same folder (i.e. we can just add ".cpp" or ".hs" to arg[0] to get the source). – HEGX64 – 2015-11-01T09:15:23.097
1@HEGX64 Sure, that makes sense. – TheInitializer – 2015-11-01T19:23:46.033
APL uses a workspace to store and execute code. May I read the program code from the workspace? The program will not contain its own name. – Adám – 2016-05-25T11:37:27.247
1@Adám I'm not sure how this workspace thing works, but what I'm going for is reading the program code from the filesystem. If it does that, great. – TheInitializer – 2016-05-25T22:35:54.287
@TheInitializer The workspace is already fully loaded into memory before the command is given to a program to run. In that sense, the workspace is APL's virtual "file" system.
– Adám – 2016-05-25T23:24:39.123@Adám It seems fine I guess. – TheInitializer – 2016-05-26T23:07:30.083