Narcissist: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: removed superfluous blank lines. -- ~~~~)
m (→‎{{header|Perl 6}}: Use nested quoting delimiters.)
Line 137: Line 137:
=={{header|Perl 6}}==
=={{header|Perl 6}}==


For the narcissist to work you must be very careful with whitespace. The presented version works if it is stored as a file of exactly one line terminated by a (Unix) newline character.
For the narcissist to work you must be very careful with whitespace. The presented version works if it is stored as a file of exactly one line terminated by a newline character.


Note: The code can be simplified as soon as Perl 6 implementations support nested quoting delimiters properly (i.e. q{ ...{...}...}).
Note how the code takes advantage of Perl 6's ability to nest quoting delimiters.


<lang perl6>my $self=q|say slurp() eq ('my $self=q'~124.chr~$self~124.chr~'; eval($self);'~10.chr)|; eval($self);
<lang perl6>my $self=q{say slurp() eq 'my $self=q{'~$self~'}; eval($self);'~10.chr ?? 'Beautiful!' !! 'Not my type.'}; eval($self);
</lang>
</lang>


{{out}}
{{out}}
<pre>$ rakudo narcissist.pl <narcissist.pl
<pre>$ rakudo narcissist.pl <narcissist.pl
Beautiful!
True
$ rakudo narcissist.pl <any-other-input.txt
$ rakudo narcissist.pl <any-other-input.pl
Not my type.
False
</pre>
</pre>