Execute CopyPasta Language: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (Added Perl 6 example) |
|||
Line 723: | Line 723: | ||
usage: copypasta.nq [filename.cp] |
usage: copypasta.nq [filename.cp] |
||
</pre> |
</pre> |
||
=={{header|Perl 6}}== |
|||
<lang perl6>sub CopyPasta ($code) { |
|||
my @code = $code.split("\n")>>.trim.grep: *.so; |
|||
return "Program never ends!" unless grep { $_ eq 'Pasta!' }, @code; |
|||
my @cb; |
|||
my $PC = 0; |
|||
loop { |
|||
given @code[$PC] { |
|||
when 'Copy' { @cb.push: @code[++$PC] } |
|||
when 'CopyFile' { $PC++; @cb.push: @code[$PC] eq 'TheF*ckingCode' ?? @code !! slurp @code[$PC] } |
|||
when 'Duplicate' { @cb = (flat @cb) xx @code[++$PC] } |
|||
when 'Pasta!' { return @cb } |
|||
default { return "Does not compute: @code[$PC]" } |
|||
} |
|||
$PC++; |
|||
} |
|||
} |
|||
spurt 'pasta.txt', 'I am the pasta.txt file.'; |
|||
(say $_ for .&CopyPasta; say '') |
|||
for |
|||
qq{Copy \nRosetta Code\n\tDuplicate\n2\n\nPasta!\nLa Vista}, |
|||
qq{CopyFile\npasta.txt\nDuplicate\n1\nPasta!}, |
|||
qq{Copy\nInvalid\n Duplicate\n1\n\nGoto\n3\nPasta!}, |
|||
qq{CopyFile\nTheF*ckingCode\nDuplicate\n2\nPasta!}, |
|||
qq{Copy\nRosetta Code\nDuplicate\n2\n\nPasta}; |
|||
unlink 'pasta.txt';</lang> |
|||
{{out}} |
|||
<pre>Rosetta Code |
|||
Rosetta Code |
|||
I am the pasta.txt file. |
|||
Does not compute: Goto |
|||
CopyFile TheF*ckingCode Duplicate 2 Pasta! |
|||
CopyFile TheF*ckingCode Duplicate 2 Pasta! |
|||
Program never ends!</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |