[Question]
  [
Write a program that will generate a "true" output [iff](http://en.wikipedia.org/wiki/If_and_only_if) the input matches the source code of the program, and which generates a "false" output iff the input does not match the source code of the program.
This problem can be described as being related to quines, as the program must be able to somehow compute its own source code in the process.
This is code golf: standard rules apply. Your program must not access any special files, such as the file of its own source code.
*Edit: If you so choose, true/false can be replaced with True/False or 1/0.*
# Example
If the source code of your program is `bhiofvewoibh46948732));:/)4`, then here is what your program must do:
## Input (Stdin)
```
bhiofvewoibh46948732));:/)4
```
## Output (Stdout)
```
true
```
## Input
```
(Anything other than your source code)
```
## Output
```
false
```
  
[Answer]
# JavaScript : 26
```
function f(s){return s==f}
```
I don't know if a JavaScript file really qualifies as a "program".
[Answer]
# Haskell, 72 characters
```
main=interact$show.(==s++show s);s="main=interact$show.(==s++show s);s="
```
Note: there is no end-of-line character at the end of the script.
```
$ runhaskell Self.hs < Self.hs
True
```
[Answer]
# Perl, ~~Infinity~~ ~~41~~ 38 Characters
```
$_=q(print<>eq"\$_=q($_);eval"|0);eval
```
**Update:** The program no longer ends with a newline, which means it will work correctly on multi-line files. You have to enter input from STDIN without hitting enter. On Windows I was only able to do this by reading from a file.
Original solution:
```
print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(...
```
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 68 bytes
Fishes love eating fish poop. Now we know they can distinguish theirs from their friends'.
```
00v      0+1~$^?)0~\;n0\
  >:@@:@gi:0(?\:a=?/=?!/$1+
  0n;n*=f$=2~~/
```
You can [try it online](https://fishlanguage.com/playground) !
[Answer]
## GolfScript, 11 chars
```
{`".~"+=}.~
```
Without the `=`, this code would be a quine that generates its own source code as a string. The `=` makes it compare this string to its input and output `1` if they match and `0` if they don't.
Note that the comparison is exact — in particular, a trailing newline at the end of the input will cause it to fail.
**Explanation:**
* `{ }` is a code block literal in GolfScript;
* `.` duplicates this code block, and `~` executes the second copy (leaving the first on the stack);
* ``` stringifies the code block, and `".~"+` appends `.~` to it;
* finally, `=` compares the resulting string with the input (which is pushed on the stack as a string by the GolfScript interpreter before the program starts) and returns `1` if they match and `0` if they don't.
[Answer]
# Python 2, 55
```
a='a=%r;print a%%a==raw_input()';print a%a==raw_input()
```
Tested:
`a='a=%r;print a%%a==raw_input()';print a%a==raw_input()` -> `True`
`(anything else)` -> `False`
[Answer]
# JavaScript ES6, ~~16~~ 14 bytes
```
$=_=>_==`$=`+$
```
Minus two bytes thanks to Neil.
31 bytes if we must take input via prompt.
```
$=_=>prompt()==`$=${$};$()`;$()
```
38 bytes if we must output via alert.
```
$=_=>alert(prompt()==`$=${$};$()`);$()
```
This is the *proper* way to do it, as Optimizer's answer does not accept the entire source code.
[Answer]
# Node.js : 54
```
function f(){console.log(f+'f()'==process.argv[2])}f()
```
You test it by saving it into a file `f.js` (the exact name has no importance) and using
```
node f.js "test"
```
(which outputs false) or 
```
node f.js "$(< f.js)"
```
(which outputs true)
I also made a different version based on eval :
```
eval(f="console.log('eval(f='+JSON.stringify(f)+')'==process.argv[2])")
```
It's now at 72 chars, I'll try to shorten that when I have time.
[Answer]
# Smalltalk (Pharo 2.0 dialect), 41 bytes
Implement this **41** chars method in String (ugly formatting for code-golf):
```
isItMe^self=thisContext method sourceCode
```
Then evaluate this in a Workspace (printIt the traditional Smalltalk way)  
The input is not read from stdin, it's just a String to which we send the message (what else a program could be in Smalltalk?):
```
'isItMe^self=thisContext method sourceCode' isItMe.
```
But we are cheating, sourceCode reads some source file...  
Here is a variant with **51** chars which does not:
```
isItMe
    ^ self = thisContext method decompileString
```
And test with:
```
'isItMe
    ^ self = thisContext method decompileString' isItMe
```
If a String in a Workspace is not considered a valid input, then let's see how to use some Dialog Box in **116** chars  
Just evaluate this sentence:
```
(UIManager default request: 'type me') = (thisContext method decompileString withSeparatorsCompacted allButFirst: 7)
```
Since decompile format includes CR and TAB, we change that withSeparatorsCompacted.  
Then we skip the first 7 chars are 'doIt ^ '
Finally a **105** chars variant using stdin, just interpret this sentence from command line, just to feel more mainstream:
```
Pharo -headless Pharo-2.0.image eval "FileStream stdin nextLine = (thisContext method decompileString withSeparatorsCompacted allButFirst: 7)"
```
[Answer]
# flex - 312 chars
```
Q \"
N \n
S " "
B \\
P "Q{S}{B}{Q}{N}N{S}{B}n{N}S{S}{Q}{S}{Q}{N}B{S}{B}{B}{N}P{S}{Q}{P}{Q}{N}M{S}{Q}{M}{Q}{N}%%{N}{P}{N}{M}{N} putchar('1');"
M "(.|{N})* putchar('0');"
%%
Q{S}{B}{Q}{N}N{S}{B}n{N}S{S}{Q}{S}{Q}{N}B{S}{B}{B}{N}P{S}{Q}{P}{Q}{N}M{S}{Q}{M}{Q}{N}%%{N}{P}{N}{M}{N} putchar('1');
(.|{N})* putchar('0');
```
Can probably be made shorter, but it works with multi-line input (necessary since the source code is multiple lines) and even for inputs that contain the program as a substring. It seems many of the answers so far fail on one or both of these.
Compile command: `flex id.l && gcc -lfl lex.yy.c`
[Answer]
## D (133 chars)
```
enum c=q{import std.stdio;import std.algorithm;void main(){auto i=readln();writeln(equal("auto c=q{"~c~"};mixin(c);",i));}};mixin(c);
```
[Answer]
# JavaScript (V8), 35
```
function i(){alert(prompt()==i+[])}
```
call `i()` and it will prompt for input
[Answer]
# GolfScript - 26
```
":@;[34]@+2*=":@;[34]@+2*=
```
Inspired from <http://esolangs.org/wiki/GolfScript#Examples>
Another version:
```
"[34].@@;+2*="[34].@@;+2*=
```
Too bad that `\` is both swap and escape...
[Answer]
# Python 2, 47 bytes
```
_='_=%r;print _%%_==input()';print _%_==input()
```
A simple quine with the added check.
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 12 bytes
```
{s"_~"+q=}_~
```
[Try it online!](https://tio.run/##S85KzP3/v7pYKb5OSbvQtja@DpUHAA "CJam – Try It Online")
### Explanation
This just uses the standard CJam quine framework.
```
{s"_~"+q=}    e# Push this block (function literal).
          _~  e# Copy and run it.
```
What the block does:
```
 s            e# Stringify the top element (this block itself).
  "_~"+       e# Append "_~". Now the source code is on the stack.
       q      e# Read the input.
        =     e# Check if it equals the source code.
```
[Answer]
# Python, 187 bytes
```
import sys;code="import sys;code=!X!;print(sys.stdin.read()==code.replace(chr(33),chr(34)).replace(!X!,code,1))";print(sys.stdin.read()==code.replace(chr(33),chr(34)).replace("X",code,1))
```
Careful not to add newline at the end. Someone with better Python-fu might be able to shorten it.
[Answer]
## Tcl, 111 chars
```
set c {set c {$c};puts [expr {[read stdin] eq [subst -noc \$c]}]};puts [expr {[read stdin] eq [subst -noc $c]}]
```
[Answer]
## Perl, 52 char
```
$_='$/=$\;$_="\$_=\47$_\47;eval";print<>eq$_|0';eval
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 11 bytes
```
=hS+s"=hS+s
```
[Try it online!](https://tio.run/##yygtzv7/3zYjWLtYCUz@h/JiIFwA "Husk – Try It Online")
### Explanation
The explanation uses `¨` to delimit strings (to avoid unreadable escaping):
```
     "=hS+s  -- string literal: ¨=hS+s¨
  S+         -- join itself with
    s        -- | itself "showed": ¨"=hS+s"¨
             -- : ¨=hS+s"=hS+s"¨
 h           -- init: ¨=hS+s"=hS+s¨
=            -- is the input equal?
```
By removing the function `=` you can [verify](https://tio.run/##yygtzv7/PyNYu1jJFkT@/w8A "Husk – Try It Online") that it will indeed only match the source itself.
[Answer]
# [Python 2](https://docs.python.org/2/), 40 bytes
```
s="print's=%r;exec s'%s==input()";exec s
```
[Try it online!](https://tio.run/##K6gsycjPM/r/v9hWqaAoM69EvdhWtcg6tSI1WaFYXbXY1jYzr6C0RENTCSr2/7@SkhKxioFKAQ "Python 2 – Try It Online")
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 24 bytes
```
'1rd3*i={*}50l3-?.~i)*n;
```
[Try it online!](https://tio.run/##S8sszvj/X92wKMVYK9O2WqvW1CDHWNdery5TUyvPGrcMAA "><> – Try It Online")
Wrapping string literal followed by checking whether the input is identical to the stack, with a final check that there is no more input.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
“Ṿ;$⁼”Ṿ;$⁼
```
[Try it online!](https://tio.run/##y0rNyan8//9Rw5yHO/dZqzxq3POoYS6M@f9w@6OmNf//R6tjl1fX4VJQR4gjK0GTQtWCRymYg64ILBELAA "Jelly – Try It Online")
```
“Ṿ;$⁼”Ṿ;$⁼
“Ṿ;$⁼”      String literal: 'Ṿ;$⁼'
        $   Next two links act on the string literal
      Ṿ     Uneval: '“Ṿ;$⁼”'
       ;    Append string: '“Ṿ;$⁼”Ṿ;$⁼' (source code)
         ⁼  Is the string above equal to the input?
```
[Answer]
# [Zsh](https://www.zsh.org/), 33 bytes
```
f () {
	[ "`type -f f`" = $1 ]
}
```
[Try it online!](https://tio.run/##qyrO@P8/TUFDU6GaizNaQSmhpLIgVUE3TSEtQUnBVkHFUCGWq5YLqEJJRQMupanElZqcka@gYs/FpayQmJKiUFKUmJmTmZeuUFyQmJzKhaZcAbf6vNRyII2hgwtFR1Fqbn5ZKnZN1cjaVO1r4Rr/AwA "Zsh – Try It Online")
The extra spaces, tab, and newlines are required. `type -f f` does not print the original source, but the function formatted in a particular way, with indentation and a trailing newline.
[Answer]
# [R](https://www.r-project.org/), 54 bytes
```
f=function(s)s==paste0("f=function(s)s==", body(f)[3])
```
[Try it online!](https://tio.run/##K/r/P802rTQvuSQzP0@jWLPY1rYgsbgk1UBDCV1cSUchKT@lUiNNM9o4VvN/moY6eTrVNbmAehOTklPUNf8DAA "R – Try It Online")
`body` gets the body of the function (splitting it a bit, so that `body(f)[3]` is everything from `paste0` onwards). Interestingly, `body` reformats the code, adding spaces after commas, etc. This is thus a rare case of an R golf answer with a space after a comma.
This works because `body(f)` is an object of type `language`, and there exists an `as.character` method for this type. On the other hand, `f` and `args(f)` are of type `closure`, and cannot be converted to character type as far as I can tell. Please don't ask me what the language type is for…
[Answer]
# [R](https://www.r-project.org/) (version-dependent), 46 bytes
```
f=function(x)x==paste0('f=',capture.output(f))
```
`capture.output` - as the function name suggests - retrieves the text string that results from entering the function name `f` directly to [R](https://www.r-project.org/), which should output the body of the function. We manually prepend this with `f=` so that it exactly\* matches the program code, and check whether the function argument `x` is the same as this.  
\*See below
There are a couple of caveats, though, that depend on the [R](https://www.r-project.org/) version used:
1. Early versions of [R](https://www.r-project.org/) (like my own version 3.2.1) return the originally-defined function body as-is when the function name is entered to [R](https://www.r-project.org/). However, later versions add additional formatting, like inserting spaces and newlines, which breaks this code: this unfortunately includes the installation (3.5.2) on 'Try it online'. Later still, much newer [R](https://www.r-project.org/) versions (I tested 4.0.3) return to the as-is output formatting and everything is Ok again... except...
2. The most recent versions of [R](https://www.r-project.org/) compile functions at the first run, and thereafter append a 'byte code' specific for the compiled function to the outputted function body. This means that `capture.output` returns two strings, beginning at the second time the function is run. Luckily, the function body is still the first one (the byte code is the second one), so the result of supplying the program code as input is `TRUE FALSE`, which evaluates to 'truthy' in [R](https://www.r-project.org/) and so counts as a 'true' output for this challenge.
Special thanks to [Robin Ryder](https://codegolf.stackexchange.com/users/86301/robin-ryder) for helping to uncover the version-dependence of [R](https://www.r-project.org/)'s function outputting.
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 12 bytes
```
`:q$+=`:q$+=
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%60%3Aq%24%2B%3D%60%3Aq%24%2B%3D&inputs=%60%3Aq%24%2B%3D%60%3Aq%24%2B%3D&header=&footer=)
I finished making this, and then realized that it is almost identical to the Vyxal quine that @Lyxal wrote, but with the addition of `=` to check if the input is equal.
Explanation:
```
              # Implicit input
`:q$+=`       # Push the string ':q$+='
       :      # Duplicate the string
        q     # Quotify; put backticks around the topmost string
         $    # Swap the top two values on the stack
          +   # Concatenate the two strings
           =  # Check if the input is equal to the string
              # Implicit output
```
[Answer]
## C - 186 176 characters
One liner:
```
 *a="*a=%c%s%c,b[999],c[999];main(){sprintf(b,a,34,a,34);gets(c);putchar(strcmp(b,c)?'0':'1');}",b[999],c[999];main(){sprintf(b,a,34,a,34);gets(c);putchar(strcmp(b,c)?'0':'1');}
```
With whitespace (note that this breaks the program):
```
*a="*a=%c%s%c,b[999],c[999];main(){sprintf(b,a,34,a,34);gets(c);putchar(strcmp(b,c)?'0':'1');}",b[999],c[999];
main() {
  sprintf(b,a,34,a,34);
  gets(c);
  putchar(strcmp(b,c)?'0':'1');
}
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 26 bytes
```
"34bLN26)s:f="34bLN26)s:f=
```
[Run and debug it](https://staxlang.xyz/#c=%2234bLN26%29s%3Af%3D%2234bLN26%29s%3Af%3D&i=%2234bLN26%29s%3Af%3D%2234bLN26%29s%3Af%3D%0A%2234bLN26%29s%3Af%3D%2234bLN26%29s%3Afb%0Aabc%0A34&m=2)
[Answer]
## JavaScript ES6, 14 bytes
Like the other javascript answer but includes it's entire source code and not just the function
```
a=q=>'a='+a==q
```
Example usage:
```
a("q=>'a='+a==q") // returns false
a("a=q=>'a='+a==q") // returns true
```
[Answer]
# q, 8 bytes
```
{x~.z.s}
```
Return boolean on input matching the self-referential [.z.s](https://code.kx.com/q/ref/dotz/#zs-self)
]