# A "cheating" quine

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 , 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 a trailing newlines not present in the original file allowed? Oct 29 '15 at 22:04
• @isaacg IMHO That's not a quine, since it is not the source code.
– user42643
Oct 29 '15 at 22:05
• You should state a requirement that it determine the actual filename instead of assuming a hard-coded string for the source location. Oct 29 '15 at 22:26
• I agree with @feersum though, that requiring a specific file name makes this challenge way to trivial.
– user42643
Oct 29 '15 at 22:33
• Can 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). Nov 1 '15 at 9:15

# A Groovy 103 100 bytes!

Yes I know I'm evil

I stay in line with the other JVM answers (Java, Scala) to make this answer.

class X{static def main(String[]a){new X()}
def X(){print new File(getClass().name+'.groovy').text}}


# Emacs Lisp (93 Bytes)

:; emacs -Q -script $0; exit (find-file (nth 2 command-line-args)) (message (buffer-string))  The first line calls the program in your normal shell and exits (to prevent the rest also being evaluated). command-line-args will be a list of three strings, "emacs", "-scriptload" and the name of your file. find-file will open that file and make it the current buffer, so that (message (buffer-string)) will write it to stdout as -script redirects messages there. It should be noted, that -Q may not be necessary if your Emacs doesn't print other messages during startup, so that the first line could be shortened to #!emacs -script, shortening this to 81 bytes, but as it is highly unlikely that init and site-lisp files produce 0 messages at all, this cannot be assumed. # Matlab, 32 bytes disp(fileread([mfilename,'.m']))  • You are not allowed to assume the file extension is .m. Jul 9 at 20:43 • @Makonede MATLAB files have have the ending .m, so it would make sense doing anything other than that. The challenge specifically says we have to read the file name, not the ending, and OP actually confirmed that we can use the file ending. Jul 10 at 21:18 # APL, 8 bytes (non-competing) APL does not use source files for single functions, rather a whole workspace (a machine-readable collection of token-representations) is saved and loaded, so I guess this is not allowed: f ⎕CR'f'  (⎕CR is Character Representation) as the program reads its current definition in memory (the loaded workspace), which may have been modified from the source in the file. # HTML and Javascript, 88 Bytes <head></head><body><svg onload="alert(document.documentElement.innerHTML)"></svg></body>  Had to add <head></head><body></svg></body> because that's what the browser outputs regardless of the original file. • #HTML and Javascript, 109 Bytes# <html><head></head><body onload="alert('<html>'+document.documentElement.innerHTML+'</html>')"></body></html> @Masterzagh, Actually browsers add html tag too. Sorry, Couldn't add a comment as I don't have enough reputation. Jan 10 '17 at 12:32 • I tested it on firefox and chrome and neither added the html (at least on the alert which is what we're interested in). @prathapareddy – user64039 Jan 10 '17 at 16:45 # Lua, 32 29 bytes 3 bytes saved thanks to Jonathan Frech print(io.open(arg[0]):read())  ### Try it online! ## How? Lua uses the arg table to store it's arguments, the script name is always stored at index 0 of this table despite the fact there are no further arguments. After using this table to get the name of the file, printing it was as easy as opening the file and reading its content. • I think you can toss your variable and save three bytes. Sep 24 '18 at 20:40 • It is interesting, how your script's file name is stored at 'index' zero, even though LUA is 1-indexed ... And it goes on: arg[-1] contains the language name ... Sep 24 '18 at 21:49 # Perl 6 / POSIX shell, 16 bytes run 'cat',$?FILE


Try it online!

## CopyPasta Language, 32 bytes

But I think this is interesting enough to compete here.

CopyFile
TheFuckingCode
Pasta!


Copy the source code, display the clipboard, and stop the program.

• Worthy of note: This language did not have an interpreter when you posted this, so it would have been invalid. As of rn, I have implemented an interpreter for the language, since the linked interpreter on the esolang is a dead link Oct 3 '19 at 3:06

# stacked, 11 bytes

program put


Try it here!

Outputs the program stored in the program variable. Simple!

# Jellyu, 26 bytes

“open(sys.argv[2])”ŒV


Try it online!

Not encoded in Jelly's SBCS, because 1. by meta consensus on flags Jelly u is a different language from Jelly (so it's not like I'm handicapping myself or anything), 2. I'm having some difficulties deciding on what form of output would be valid for an SBCS Jelly cheating quine, and 3. I'm having some difficulties actually executing on the methods I've considered (note that that's not even shorter than this).

“open(sys.argv[2])”ŒV    Evaluate "open(sys.argv[2])" as Python, within Jelly's interpreter.py.

sys.argv           Get the arguments with which this was invoked on the command line.
(jelly fu [whatever the file's called])
[2]        Take the third argument,
open(           )       and open the file at that location.

ŒV    Iterate through the file object, obtaining a Jelly string of its contents.

• This can be encoded in the SBCS and be perfectly valid at the same time. Jul 8 at 18:04
• @Makonede It still presents the difficulty of taking SBCS-encoded file contents and outputting either the corresponding UTF-8 or the same bytes. Jul 8 at 18:13
• How about this: The output should look identical to the program. So the corresponding UTF-8. Jul 8 at 18:18
• ...I was about to say "well guess what I already tried", but it turns out the apparent failure is an issue with TIO's bash rather than the solution itself. Glad I tried that again Jul 8 at 18:37

# 05AB1E (legacy), 433930 27 bytes

’ƒÛ(__£Ø__('Ë‚').Òœv[1])’.E


Try it online! I would've used the rewrite, if only I knew Elixir… Output doesn't contain the program, however it is the program in a singleton iterable object (a file). This is allowed.

’ƒÛ(__£Ø__('Ë‚').Òœv[1])’.E  # full program
’ƒÛ(__£Ø__('Ë‚').Òœv[1])’    # push "open(__import__('sys').argv[1])"...
.E  # evaluated as Python code
# implicit output

============================================================================

open(__import__('sys').argv[1])  # full Python program
open(                         )  # return file at path...
[1]   # second...
__import__('sys').argv      # command-line argument


Note: This program assumes no command-line flags or extra arguments are passed. If this assumption is not allowed, it can be fixed at a cost of 1 byte by adding a - before the 1.

# Julia 1.0, 29 26 bytes

print(readline(@__FILE__))


Try it online!

# Processing, 48 bytes

print(loadStrings(getClass().getName()+".pde"));

• I don't know Processing, but this looks like it wouldn't work if the file name didn't end in .pde. Jul 8 at 23:11
• The java answer sais , getClass().getName()+".java" Also I don't know if there is a way of getting the extension, you can get a list of filenames in a folder but it's not bulletproof either Jul 9 at 16:01
• Then the Java answer is invalid too. If there's no guaranteed way, too bad. Jul 9 at 20:40

# Nim, 43 bytes

import os

• See my comment on the above answer. You are not allowed to assume the filename ends in .nim. Jul 9 at 20:41