Execute CopyPasta Language: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Added 11l)
m (→‎{{header|Wren}}: Changed to Wren S/H)
(2 intermediate revisions by 2 users not shown)
Line 20:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">:start:
V source = File(:argv[1]).read()
 
Line 50:
exit(‘error while executing command '’command‘' on line ’(loc + 1))
 
loc += 2</langsyntaxhighlight>
 
=={{header|C++}}==
{{trans|Nanoquery}}
<langsyntaxhighlight lang="cpp">#include <fstream>
#include <iostream>
#include <sstream>
Line 186:
// return in case we never hit a 'Pasta!' statement
return 0;
}</langsyntaxhighlight>
 
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.
<langsyntaxhighlight lang="go">// copypasta.go
package main
 
Line 360:
err = clipboard.WriteAll("") // clear clipboard
check(err)
}</langsyntaxhighlight>
 
{{out}}
Line 414:
=={{header|Java}}==
{{trans|Nanoquery}}
<langsyntaxhighlight Javalang="java">import java.io.File;
import java.nio.file.Files;
import java.util.ArrayList;
Line 498:
}
}
}</langsyntaxhighlight>
 
The following files were used for testing:
Line 562:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">
function interpretCopyPasta()
clipboard = String[]
Line 601:
 
interpretCopyPasta()
</langsyntaxhighlight>{{out}}
If run on the following CopyPasta "code" file:
<pre>
Line 643:
 
=={{header|Nanoquery}}==
<langsyntaxhighlight Nanoquerylang="nanoquery">// a function to handle fatal errors
def fatal_error(errtext)
println "%" + errtext
Line 696:
// increment past the command and the next line
loc += 2
end</langsyntaxhighlight>
 
The following files were used for testing:
Line 760:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import os, strutils
 
type CopyPastaError = object of CatchableError
Line 825:
copyPasta()
except CopyPastaError:
quit getCurrentExceptionMsg(), QuitFailure</langsyntaxhighlight>
 
{{out}}
Line 874:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 909:
}
 
unlink 'pasta.txt';</langsyntaxhighlight>
{{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 ".
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">JS</span><span style="color: #0000FF;">?{</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">}:</span><span style="color: #7060A8;">command_line</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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,031 ⟶ 1,032:
=={{header|Python}}==
{{trans|Nanoquery}}
<langsyntaxhighlight Pythonlang="python">import sys
 
# a function to handle fatal errors
Line 1,081 ⟶ 1,082:
# increment past the command and the next line
loc += 2
</syntaxhighlight>
</lang>
 
The following files were used for testing:
Line 1,146 ⟶ 1,147:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>sub CopyPasta ($code) {
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';</langsyntaxhighlight>
{{out}}
<pre>Rosetta Code
Line 1,190 ⟶ 1,191:
=={{header|Wren}}==
{{trans|Go}}
<langsyntaxhighlight ecmascriptlang="wren">import "os" for Platform, Process
import "io" for File
 
Line 1,243 ⟶ 1,244:
}
var s = File.read(args[0])
interpret.call(s)</langsyntaxhighlight>
 
{{out}}
Line 1,251 ⟶ 1,252:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">var clipBoard=Data(), srcNm=vm.arglist[0];
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: ") }
}</langsyntaxhighlight>
Input programs:
<pre style="height:15ex">
9,482

edits