Execute CopyPasta Language: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
Alextretyak (talk | contribs) (Added 11l) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 20:
{{trans|Python}}
<
V source = File(:argv[1]).read()
Line 50:
exit(‘error while executing command '’command‘' on line ’(loc + 1))
loc += 2</
=={{header|C++}}==
{{trans|Nanoquery}}
<
#include <iostream>
#include <sstream>
Line 186:
// return in case we never hit a 'Pasta!' statement
return 0;
}</
The following files were used for testing:
Line 271:
8. When the program is about to end and the contents of the clipboard have (when appropriate) been printed out, the clipboard should be cleared.
<
package main
Line 360:
err = clipboard.WriteAll("") // clear clipboard
check(err)
}</
{{out}}
Line 414:
=={{header|Java}}==
{{trans|Nanoquery}}
<
import java.nio.file.Files;
import java.util.ArrayList;
Line 498:
}
}
}</
The following files were used for testing:
Line 562:
=={{header|Julia}}==
<
function interpretCopyPasta()
clipboard = String[]
Line 601:
interpretCopyPasta()
</
If run on the following CopyPasta "code" file:
<pre>
Line 643:
=={{header|Nanoquery}}==
<
def fatal_error(errtext)
println "%" + errtext
Line 696:
// increment past the command and the next line
loc += 2
end</
The following files were used for testing:
Line 760:
=={{header|Nim}}==
<
type CopyPastaError = object of CatchableError
Line 825:
copyPasta()
except CopyPastaError:
quit getCurrentExceptionMsg(), QuitFailure</
{{out}}
Line 874:
=={{header|Perl}}==
<
use warnings;
use feature 'say';
Line 909:
}
unlink 'pasta.txt';</
{{out}}
<pre>Rosetta Code
Line 927:
If run without command-line parameters it fakes four runs.<br>
Assumes if clipboard is "hello ", Duplicate 2 should leave it as "hello hello hello ".
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">prog1_cp</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
Copy
Line 994 ⟶ 995:
<span style="color: #008080;">procedure</span> <span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">cl</span> <span style="color: #0000FF;">=</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cl</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">2</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">4</span> <span style="color: #008080;">do</span>
Line 1,010 ⟶ 1,011:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</
{{out}}
<pre>
Line 1,031 ⟶ 1,032:
=={{header|Python}}==
{{trans|Nanoquery}}
<
# a function to handle fatal errors
Line 1,081 ⟶ 1,082:
# increment past the command and the next line
loc += 2
</syntaxhighlight>
The following files were used for testing:
Line 1,146 ⟶ 1,147:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
my @code = $code.split("\n")>>.trim.grep: *.so;
return "Program never ends!" unless grep { $_ eq 'Pasta!' }, @code;
Line 1,174 ⟶ 1,175:
"Copy\nRosetta Code\nDuplicate\n2\n\nPasta";
unlink 'pasta.txt';</
{{out}}
<pre>Rosetta Code
Line 1,190 ⟶ 1,191:
=={{header|Wren}}==
{{trans|Go}}
<
import "io" for File
Line 1,243 ⟶ 1,244:
}
var s = File.read(args[0])
interpret.call(s)</
{{out}}
Line 1,251 ⟶ 1,252:
=={{header|zkl}}==
<
pasta:=File(srcNm).read().howza(11); // zkl pastaprog.cp, stripped lines
foreach line in (pasta){
Line 1,282 ⟶ 1,283:
}catch(TheEnd){ error(w,"Error: End of file: ") }
catch{ error(w,wantInt and "Not an int: " or "Error: ") }
}</
Input programs:
<pre style="height:15ex">
|