Narcissist: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 94: Line 94:
Only checks the first line of stdin:
Only checks the first line of stdin:
<lang lisp>#1=(PRINT (EQUAL (WRITE-TO-STRING '#1# :CIRCLE 1) (READ-LINE *STANDARD-INPUT*)))</lang>
<lang lisp>#1=(PRINT (EQUAL (WRITE-TO-STRING '#1# :CIRCLE 1) (READ-LINE *STANDARD-INPUT*)))</lang>

=={{header|D}}==
=={{header|D}}==
<lang D>import std.file; import std.stdio; import std.string; void main() { auto source = readText("narcissist.d").chomp; auto input = readln().chomp(); if (source == input) writeln("accept"); else writeln("reject"); }</lang>
<lang D>import std.file; import std.stdio; import std.string; void main() { auto source = readText("narcissist.d").chomp; auto input = readln().chomp(); if (source == input) writeln("accept"); else writeln("reject"); }</lang>
Line 275: Line 276:


{{works with|Julia|1.2}}
{{works with|Julia|1.2}}

=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>mysource = Base.read(Base.source_path(), String)
<lang julia>mysource = Base.read(Base.source_path(), String)
Line 367: Line 369:
<pre>narcissist() = {input() == narcissist;}
<pre>narcissist() = {input() == narcissist;}
1</pre>
1</pre>

=={{header|Perl}}==
=={{header|Perl}}==
<lang perl># this is file narc.pl
<lang perl># this is file narc.pl
Line 373: Line 376:
Run:
Run:
<lang>perl narc.pl < narc.pl</lang>
<lang>perl narc.pl < narc.pl</lang>

=={{header|Perl 6}}==

For the narcissist to work you must be very careful with whitespace. The following version works if it is given to standard input as exactly one line terminated by a newline character.

Note how the code takes advantage of Perl 6's ability to nest quoting delimiters.

<lang perl6>EVAL my $self = q{say slurp() eq q[EVAL my $self = q{]~$self~q[}]~10.chr ?? q{Beautiful!} !! q{Not my type.}}</lang>

{{out}}
<pre>$ narcissist='EVAL my $self = q{say slurp() eq q[EVAL my $self = q{]~$self~q[}]~10.chr ?? q{Beautiful!} !! q{Not my type.}}'
$ perl6 -e "$narcissist" <<<"$narcissist"
Beautiful!
$ perl6 -e "$narcissist" <<<"$narcissist # a comment ruining it all"
Not my type.
</pre>


=={{header|Phix}}==
=={{header|Phix}}==
Line 456: Line 443:
#t
#t
</lang>
</lang>

=={{header|Raku}}==
(formerly Perl 6)

For the narcissist to work you must be very careful with whitespace. The following version works if it is given to standard input as exactly one line terminated by a newline character.

Note how the code takes advantage of Perl 6's ability to nest quoting delimiters.

<lang perl6>EVAL my $self = q{say slurp() eq q[EVAL my $self = q{]~$self~q[}]~10.chr ?? q{Beautiful!} !! q{Not my type.}}</lang>

{{out}}
<pre>$ narcissist='EVAL my $self = q{say slurp() eq q[EVAL my $self = q{]~$self~q[}]~10.chr ?? q{Beautiful!} !! q{Not my type.}}'
$ perl6 -e "$narcissist" <<<"$narcissist"
Beautiful!
$ perl6 -e "$narcissist" <<<"$narcissist # a comment ruining it all"
Not my type.
</pre>


=={{header|REXX}}==
=={{header|REXX}}==
Line 485: Line 489:
if (lines.mkString("\r\n") == text) println("\naccept") else println("\nreject")
if (lines.mkString("\r\n") == text) println("\naccept") else println("\nreject")
}</lang>
}</lang>

=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>say (File.new(__FILE__).open_r.slurp == ARGF.slurp);</lang>
<lang ruby>say (File.new(__FILE__).open_r.slurp == ARGF.slurp);</lang>
Line 536: Line 541:
<pre>$ txr narcissist.txr narcissist.txr
<pre>$ txr narcissist.txr narcissist.txr
1</pre>
1</pre>

=={{header|UNIX Shell}}==
<lang bash>cmp "$0" >/dev/null && echo accept || echo reject</lang>


=={{header|VBA}}==
=={{header|VBA}}==
Line 581: Line 589:
Debug.Print IIf(flag, 1, 0)
Debug.Print IIf(flag, 1, 0)
End Sub</lang>
End Sub</lang>
=={{header|UNIX Shell}}==
<lang bash>cmp "$0" >/dev/null && echo accept || echo reject</lang>


=={{header|zkl}}==
=={{header|zkl}}==