Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Write a version of this Haskell function in Go with identical behavior. | import Data.Version
import Control.Monad
import System.Info
minGHCVersion = Version [6, 8] []
main = when (compilerName == "ghc" && compilerVersion < minGHCVersion) $
fail "Compiler too old."
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Produce a functionally identical C code for the snippet given in J. | 6 (2!:55@:]^:>) 0 ". 1 { 9!:14''
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Can you help me rewrite this code in C# instead of J, keeping it the same logically? | 6 (2!:55@:]^:>) 0 ". 1 { 9!:14''
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Write a version of this J function in C++ with identical behavior. | 6 (2!:55@:]^:>) 0 ". 1 { 9!:14''
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Produce a language-to-language conversion: from J to Java, same semantics. | 6 (2!:55@:]^:>) 0 ". 1 { 9!:14''
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Translate the given J code snippet into Python without altering its behavior. | 6 (2!:55@:]^:>) 0 ". 1 { 9!:14''
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Port the following code from J to Go with equivalent syntax and logic. | 6 (2!:55@:]^:>) 0 ". 1 { 9!:14''
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Generate an equivalent C version of this Julia code. | @show VERSION
VERSION < v"0.4" && exit(1)
if isdefined(Base, :bloop) && !isempty(methods(abs))
@show abs(bloop)
end
a, b, c = 1, 2, 3
vars = filter(x -> eval(x) isa Integer, names(Main))
println("Integer variables: ", join(vars, ", "), ".")
println("Sum of integers in the global scope: ", sum(eval.(vars)), ".")
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Produce a language-to-language conversion: from Julia to C#, same semantics. | @show VERSION
VERSION < v"0.4" && exit(1)
if isdefined(Base, :bloop) && !isempty(methods(abs))
@show abs(bloop)
end
a, b, c = 1, 2, 3
vars = filter(x -> eval(x) isa Integer, names(Main))
println("Integer variables: ", join(vars, ", "), ".")
println("Sum of integers in the global scope: ", sum(eval.(vars)), ".")
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Translate this program into C++ but keep the logic exactly as in Julia. | @show VERSION
VERSION < v"0.4" && exit(1)
if isdefined(Base, :bloop) && !isempty(methods(abs))
@show abs(bloop)
end
a, b, c = 1, 2, 3
vars = filter(x -> eval(x) isa Integer, names(Main))
println("Integer variables: ", join(vars, ", "), ".")
println("Sum of integers in the global scope: ", sum(eval.(vars)), ".")
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Write the same code in Java as shown below in Julia. | @show VERSION
VERSION < v"0.4" && exit(1)
if isdefined(Base, :bloop) && !isempty(methods(abs))
@show abs(bloop)
end
a, b, c = 1, 2, 3
vars = filter(x -> eval(x) isa Integer, names(Main))
println("Integer variables: ", join(vars, ", "), ".")
println("Sum of integers in the global scope: ", sum(eval.(vars)), ".")
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Translate the given Julia code snippet into Python without altering its behavior. | @show VERSION
VERSION < v"0.4" && exit(1)
if isdefined(Base, :bloop) && !isempty(methods(abs))
@show abs(bloop)
end
a, b, c = 1, 2, 3
vars = filter(x -> eval(x) isa Integer, names(Main))
println("Integer variables: ", join(vars, ", "), ".")
println("Sum of integers in the global scope: ", sum(eval.(vars)), ".")
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Write the same code in VB as shown below in Julia. | @show VERSION
VERSION < v"0.4" && exit(1)
if isdefined(Base, :bloop) && !isempty(methods(abs))
@show abs(bloop)
end
a, b, c = 1, 2, 3
vars = filter(x -> eval(x) isa Integer, names(Main))
println("Integer variables: ", join(vars, ", "), ".")
println("Sum of integers in the global scope: ", sum(eval.(vars)), ".")
| If Application.Version < 15 Then Exit Sub
|
Change the following Julia code into Go without altering its purpose. | @show VERSION
VERSION < v"0.4" && exit(1)
if isdefined(Base, :bloop) && !isempty(methods(abs))
@show abs(bloop)
end
a, b, c = 1, 2, 3
vars = filter(x -> eval(x) isa Integer, names(Main))
println("Integer variables: ", join(vars, ", "), ".")
println("Sum of integers in the global scope: ", sum(eval.(vars)), ".")
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Rewrite this program in C while keeping its functionality equivalent to the Lua version. | if _VERSION:sub(5) + 0 < 5.1 then print"too old" end
if bloop and math.abs then print(math.abs(bloop)) end
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Port the following code from Lua to C# with equivalent syntax and logic. | if _VERSION:sub(5) + 0 < 5.1 then print"too old" end
if bloop and math.abs then print(math.abs(bloop)) end
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Convert the following code from Lua to C++, ensuring the logic remains intact. | if _VERSION:sub(5) + 0 < 5.1 then print"too old" end
if bloop and math.abs then print(math.abs(bloop)) end
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Please provide an equivalent version of this Lua code in Java. | if _VERSION:sub(5) + 0 < 5.1 then print"too old" end
if bloop and math.abs then print(math.abs(bloop)) end
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Convert this Lua snippet to Python and keep its semantics consistent. | if _VERSION:sub(5) + 0 < 5.1 then print"too old" end
if bloop and math.abs then print(math.abs(bloop)) end
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Change the following Lua code into VB without altering its purpose. | if _VERSION:sub(5) + 0 < 5.1 then print"too old" end
if bloop and math.abs then print(math.abs(bloop)) end
| If Application.Version < 15 Then Exit Sub
|
Preserve the algorithm and functionality while converting the code from Lua to Go. | if _VERSION:sub(5) + 0 < 5.1 then print"too old" end
if bloop and math.abs then print(math.abs(bloop)) end
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Write the same code in C as shown below in Mathematica. | If[$VersionNumber < 8, Quit[]]
If[NameQ["bloop"] && NameQ["Abs"],
Print[Abs[bloop]]]
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Can you help me rewrite this code in C# instead of Mathematica, keeping it the same logically? | If[$VersionNumber < 8, Quit[]]
If[NameQ["bloop"] && NameQ["Abs"],
Print[Abs[bloop]]]
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Can you help me rewrite this code in C++ instead of Mathematica, keeping it the same logically? | If[$VersionNumber < 8, Quit[]]
If[NameQ["bloop"] && NameQ["Abs"],
Print[Abs[bloop]]]
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Write a version of this Mathematica function in Java with identical behavior. | If[$VersionNumber < 8, Quit[]]
If[NameQ["bloop"] && NameQ["Abs"],
Print[Abs[bloop]]]
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Rewrite this program in Python while keeping its functionality equivalent to the Mathematica version. | If[$VersionNumber < 8, Quit[]]
If[NameQ["bloop"] && NameQ["Abs"],
Print[Abs[bloop]]]
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Transform the following Mathematica implementation into VB, maintaining the same output and logic. | If[$VersionNumber < 8, Quit[]]
If[NameQ["bloop"] && NameQ["Abs"],
Print[Abs[bloop]]]
| If Application.Version < 15 Then Exit Sub
|
Produce a language-to-language conversion: from Mathematica to Go, same semantics. | If[$VersionNumber < 8, Quit[]]
If[NameQ["bloop"] && NameQ["Abs"],
Print[Abs[bloop]]]
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Write a version of this MATLAB function in C with identical behavior. |
v = version;
v(v=='.')=' ';
v = str2num(v);
if v(2)>10; v(2) = v(2)/10; end;
ver = v(1)+v(2)/10;
if exist('OCTAVE_VERSION','builtin')
if ver < 3.0,
exit
end;
else
if ver < 7.0,
exit
end;
end
if exist('bloob','var') && any(exist('abs')==[2,3,5])
printf('abs(bloob) is
return;
end;
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Transform the following MATLAB implementation into C#, maintaining the same output and logic. |
v = version;
v(v=='.')=' ';
v = str2num(v);
if v(2)>10; v(2) = v(2)/10; end;
ver = v(1)+v(2)/10;
if exist('OCTAVE_VERSION','builtin')
if ver < 3.0,
exit
end;
else
if ver < 7.0,
exit
end;
end
if exist('bloob','var') && any(exist('abs')==[2,3,5])
printf('abs(bloob) is
return;
end;
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Write a version of this MATLAB function in C++ with identical behavior. |
v = version;
v(v=='.')=' ';
v = str2num(v);
if v(2)>10; v(2) = v(2)/10; end;
ver = v(1)+v(2)/10;
if exist('OCTAVE_VERSION','builtin')
if ver < 3.0,
exit
end;
else
if ver < 7.0,
exit
end;
end
if exist('bloob','var') && any(exist('abs')==[2,3,5])
printf('abs(bloob) is
return;
end;
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Write a version of this MATLAB function in Java with identical behavior. |
v = version;
v(v=='.')=' ';
v = str2num(v);
if v(2)>10; v(2) = v(2)/10; end;
ver = v(1)+v(2)/10;
if exist('OCTAVE_VERSION','builtin')
if ver < 3.0,
exit
end;
else
if ver < 7.0,
exit
end;
end
if exist('bloob','var') && any(exist('abs')==[2,3,5])
printf('abs(bloob) is
return;
end;
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Write a version of this MATLAB function in Python with identical behavior. |
v = version;
v(v=='.')=' ';
v = str2num(v);
if v(2)>10; v(2) = v(2)/10; end;
ver = v(1)+v(2)/10;
if exist('OCTAVE_VERSION','builtin')
if ver < 3.0,
exit
end;
else
if ver < 7.0,
exit
end;
end
if exist('bloob','var') && any(exist('abs')==[2,3,5])
printf('abs(bloob) is
return;
end;
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Write a version of this MATLAB function in VB with identical behavior. |
v = version;
v(v=='.')=' ';
v = str2num(v);
if v(2)>10; v(2) = v(2)/10; end;
ver = v(1)+v(2)/10;
if exist('OCTAVE_VERSION','builtin')
if ver < 3.0,
exit
end;
else
if ver < 7.0,
exit
end;
end
if exist('bloob','var') && any(exist('abs')==[2,3,5])
printf('abs(bloob) is
return;
end;
| If Application.Version < 15 Then Exit Sub
|
Transform the following MATLAB implementation into Go, maintaining the same output and logic. |
v = version;
v(v=='.')=' ';
v = str2num(v);
if v(2)>10; v(2) = v(2)/10; end;
ver = v(1)+v(2)/10;
if exist('OCTAVE_VERSION','builtin')
if ver < 3.0,
exit
end;
else
if ver < 7.0,
exit
end;
end
if exist('bloob','var') && any(exist('abs')==[2,3,5])
printf('abs(bloob) is
return;
end;
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Port the provided Nim code into C while preserving the original functionality. | when NimVersion < "1.2":
error "This compiler is too old"
assert NimVersion >= "1.4", "This compiler is too old."
var bloop = -12
when compiles abs(bloop):
echo abs(bloop)
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Generate a C# translation of this Nim snippet without changing its computational steps. | when NimVersion < "1.2":
error "This compiler is too old"
assert NimVersion >= "1.4", "This compiler is too old."
var bloop = -12
when compiles abs(bloop):
echo abs(bloop)
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Change the following Nim code into C++ without altering its purpose. | when NimVersion < "1.2":
error "This compiler is too old"
assert NimVersion >= "1.4", "This compiler is too old."
var bloop = -12
when compiles abs(bloop):
echo abs(bloop)
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Write the same code in Java as shown below in Nim. | when NimVersion < "1.2":
error "This compiler is too old"
assert NimVersion >= "1.4", "This compiler is too old."
var bloop = -12
when compiles abs(bloop):
echo abs(bloop)
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Write the same algorithm in Python as shown in this Nim implementation. | when NimVersion < "1.2":
error "This compiler is too old"
assert NimVersion >= "1.4", "This compiler is too old."
var bloop = -12
when compiles abs(bloop):
echo abs(bloop)
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Transform the following Nim implementation into VB, maintaining the same output and logic. | when NimVersion < "1.2":
error "This compiler is too old"
assert NimVersion >= "1.4", "This compiler is too old."
var bloop = -12
when compiles abs(bloop):
echo abs(bloop)
| If Application.Version < 15 Then Exit Sub
|
Generate a Go translation of this Nim snippet without changing its computational steps. | when NimVersion < "1.2":
error "This compiler is too old"
assert NimVersion >= "1.4", "This compiler is too old."
var bloop = -12
when compiles abs(bloop):
echo abs(bloop)
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Rewrite this program in C while keeping its functionality equivalent to the OCaml version. | # Sys.ocaml_version;;
- : string = "3.10.2"
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Can you help me rewrite this code in C# instead of OCaml, keeping it the same logically? | # Sys.ocaml_version;;
- : string = "3.10.2"
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Translate this program into C++ but keep the logic exactly as in OCaml. | # Sys.ocaml_version;;
- : string = "3.10.2"
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Generate a Java translation of this OCaml snippet without changing its computational steps. | # Sys.ocaml_version;;
- : string = "3.10.2"
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Rewrite this program in Python while keeping its functionality equivalent to the OCaml version. | # Sys.ocaml_version;;
- : string = "3.10.2"
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Transform the following OCaml implementation into Go, maintaining the same output and logic. | # Sys.ocaml_version;;
- : string = "3.10.2"
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Translate the given Perl code snippet into C without altering its behavior. | require v5.6.1;
require 5.6.1;
require 5.006_001;
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Preserve the algorithm and functionality while converting the code from Perl to C#. | require v5.6.1;
require 5.6.1;
require 5.006_001;
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Convert the following code from Perl to C++, ensuring the logic remains intact. | require v5.6.1;
require 5.6.1;
require 5.006_001;
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Translate the given Perl code snippet into Java without altering its behavior. | require v5.6.1;
require 5.6.1;
require 5.006_001;
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Write the same code in Python as shown below in Perl. | require v5.6.1;
require 5.6.1;
require 5.006_001;
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Change the programming language of this snippet from Perl to VB without modifying what it does. | require v5.6.1;
require 5.6.1;
require 5.006_001;
| If Application.Version < 15 Then Exit Sub
|
Port the provided Perl code into Go while preserving the original functionality. | require v5.6.1;
require 5.6.1;
require 5.006_001;
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Convert this PowerShell snippet to C and keep its semantics consistent. |
if ($PSVersionTable['PSVersion'] -lt '2.0') {
exit
}
if ((Test-Path Variable:bloop) -and ([Math]::Abs)) {
[Math]::Abs($bloop)
}
Get-Variable -Scope global `
| Where-Object { $_.Value -is [int] } `
| Measure-Object -Sum Value `
| Select-Object Count,Sum
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Maintain the same structure and functionality when rewriting this code in C#. |
if ($PSVersionTable['PSVersion'] -lt '2.0') {
exit
}
if ((Test-Path Variable:bloop) -and ([Math]::Abs)) {
[Math]::Abs($bloop)
}
Get-Variable -Scope global `
| Where-Object { $_.Value -is [int] } `
| Measure-Object -Sum Value `
| Select-Object Count,Sum
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Rewrite this program in C++ while keeping its functionality equivalent to the PowerShell version. |
if ($PSVersionTable['PSVersion'] -lt '2.0') {
exit
}
if ((Test-Path Variable:bloop) -and ([Math]::Abs)) {
[Math]::Abs($bloop)
}
Get-Variable -Scope global `
| Where-Object { $_.Value -is [int] } `
| Measure-Object -Sum Value `
| Select-Object Count,Sum
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Port the provided PowerShell code into Java while preserving the original functionality. |
if ($PSVersionTable['PSVersion'] -lt '2.0') {
exit
}
if ((Test-Path Variable:bloop) -and ([Math]::Abs)) {
[Math]::Abs($bloop)
}
Get-Variable -Scope global `
| Where-Object { $_.Value -is [int] } `
| Measure-Object -Sum Value `
| Select-Object Count,Sum
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Write the same code in Python as shown below in PowerShell. |
if ($PSVersionTable['PSVersion'] -lt '2.0') {
exit
}
if ((Test-Path Variable:bloop) -and ([Math]::Abs)) {
[Math]::Abs($bloop)
}
Get-Variable -Scope global `
| Where-Object { $_.Value -is [int] } `
| Measure-Object -Sum Value `
| Select-Object Count,Sum
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Translate this program into VB but keep the logic exactly as in PowerShell. |
if ($PSVersionTable['PSVersion'] -lt '2.0') {
exit
}
if ((Test-Path Variable:bloop) -and ([Math]::Abs)) {
[Math]::Abs($bloop)
}
Get-Variable -Scope global `
| Where-Object { $_.Value -is [int] } `
| Measure-Object -Sum Value `
| Select-Object Count,Sum
| If Application.Version < 15 Then Exit Sub
|
Ensure the translated Go code behaves exactly like the original PowerShell snippet. |
if ($PSVersionTable['PSVersion'] -lt '2.0') {
exit
}
if ((Test-Path Variable:bloop) -and ([Math]::Abs)) {
[Math]::Abs($bloop)
}
Get-Variable -Scope global `
| Where-Object { $_.Value -is [int] } `
| Measure-Object -Sum Value `
| Select-Object Count,Sum
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Write the same algorithm in C as shown in this R implementation. | if(getRversion() < "2.14.1")
{
warning("Your version of R is older than 2.14.1")
q()
}
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Convert this R snippet to C# and keep its semantics consistent. | if(getRversion() < "2.14.1")
{
warning("Your version of R is older than 2.14.1")
q()
}
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Produce a language-to-language conversion: from R to C++, same semantics. | if(getRversion() < "2.14.1")
{
warning("Your version of R is older than 2.14.1")
q()
}
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Change the programming language of this snippet from R to Java without modifying what it does. | if(getRversion() < "2.14.1")
{
warning("Your version of R is older than 2.14.1")
q()
}
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Translate this program into Python but keep the logic exactly as in R. | if(getRversion() < "2.14.1")
{
warning("Your version of R is older than 2.14.1")
q()
}
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Translate the given R code snippet into VB without altering its behavior. | if(getRversion() < "2.14.1")
{
warning("Your version of R is older than 2.14.1")
q()
}
| If Application.Version < 15 Then Exit Sub
|
Rewrite the snippet below in Go so it works the same as the original R code. | if(getRversion() < "2.14.1")
{
warning("Your version of R is older than 2.14.1")
q()
}
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Convert this Racket block to C, preserving its control flow and logic. | #lang racket
(unless (string<=? "5.3" (version)) (error "ancient version"))
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Rewrite this program in C# while keeping its functionality equivalent to the Racket version. | #lang racket
(unless (string<=? "5.3" (version)) (error "ancient version"))
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Port the following code from Racket to C++ with equivalent syntax and logic. | #lang racket
(unless (string<=? "5.3" (version)) (error "ancient version"))
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Change the programming language of this snippet from Racket to Java without modifying what it does. | #lang racket
(unless (string<=? "5.3" (version)) (error "ancient version"))
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Translate this program into Python but keep the logic exactly as in Racket. | #lang racket
(unless (string<=? "5.3" (version)) (error "ancient version"))
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Rewrite this program in Go while keeping its functionality equivalent to the Racket version. | #lang racket
(unless (string<=? "5.3" (version)) (error "ancient version"))
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Maintain the same structure and functionality when rewriting this code in C. |
options replace format comments java crossref symbols binary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
parse arg minVersion .
if minVersion = '' then minVersion = 2.0
parse version lang ver bdate
if ver < minVersion then do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'is less than' minVersion.format(null, 2)'; exiting...'
exit
end
else do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'meets minimum requirements of' minVersion.format(null, 2)
end
return
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Produce a language-to-language conversion: from REXX to C#, same semantics. |
options replace format comments java crossref symbols binary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
parse arg minVersion .
if minVersion = '' then minVersion = 2.0
parse version lang ver bdate
if ver < minVersion then do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'is less than' minVersion.format(null, 2)'; exiting...'
exit
end
else do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'meets minimum requirements of' minVersion.format(null, 2)
end
return
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Produce a language-to-language conversion: from REXX to C++, same semantics. |
options replace format comments java crossref symbols binary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
parse arg minVersion .
if minVersion = '' then minVersion = 2.0
parse version lang ver bdate
if ver < minVersion then do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'is less than' minVersion.format(null, 2)'; exiting...'
exit
end
else do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'meets minimum requirements of' minVersion.format(null, 2)
end
return
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Preserve the algorithm and functionality while converting the code from REXX to Java. |
options replace format comments java crossref symbols binary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
parse arg minVersion .
if minVersion = '' then minVersion = 2.0
parse version lang ver bdate
if ver < minVersion then do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'is less than' minVersion.format(null, 2)'; exiting...'
exit
end
else do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'meets minimum requirements of' minVersion.format(null, 2)
end
return
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Change the following REXX code into Python without altering its purpose. |
options replace format comments java crossref symbols binary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
parse arg minVersion .
if minVersion = '' then minVersion = 2.0
parse version lang ver bdate
if ver < minVersion then do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'is less than' minVersion.format(null, 2)'; exiting...'
exit
end
else do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'meets minimum requirements of' minVersion.format(null, 2)
end
return
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Rewrite the snippet below in VB so it works the same as the original REXX code. |
options replace format comments java crossref symbols binary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
parse arg minVersion .
if minVersion = '' then minVersion = 2.0
parse version lang ver bdate
if ver < minVersion then do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'is less than' minVersion.format(null, 2)'; exiting...'
exit
end
else do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'meets minimum requirements of' minVersion.format(null, 2)
end
return
| If Application.Version < 15 Then Exit Sub
|
Convert the following code from REXX to Go, ensuring the logic remains intact. |
options replace format comments java crossref symbols binary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
parse arg minVersion .
if minVersion = '' then minVersion = 2.0
parse version lang ver bdate
if ver < minVersion then do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'is less than' minVersion.format(null, 2)'; exiting...'
exit
end
else do
say -
lang 'version' ver -
'[Build date:' bdate']' -
'meets minimum requirements of' minVersion.format(null, 2)
end
return
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Rewrite the snippet below in C so it works the same as the original Ruby code. | exit if RUBY_VERSION < '1.8.6'
puts bloop.abs if defined?(bloop) and bloop.respond_to?(:abs)
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Translate this program into C# but keep the logic exactly as in Ruby. | exit if RUBY_VERSION < '1.8.6'
puts bloop.abs if defined?(bloop) and bloop.respond_to?(:abs)
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Write the same algorithm in C++ as shown in this Ruby implementation. | exit if RUBY_VERSION < '1.8.6'
puts bloop.abs if defined?(bloop) and bloop.respond_to?(:abs)
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Transform the following Ruby implementation into Java, maintaining the same output and logic. | exit if RUBY_VERSION < '1.8.6'
puts bloop.abs if defined?(bloop) and bloop.respond_to?(:abs)
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Port the provided Ruby code into Python while preserving the original functionality. | exit if RUBY_VERSION < '1.8.6'
puts bloop.abs if defined?(bloop) and bloop.respond_to?(:abs)
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Ensure the translated VB code behaves exactly like the original Ruby snippet. | exit if RUBY_VERSION < '1.8.6'
puts bloop.abs if defined?(bloop) and bloop.respond_to?(:abs)
| If Application.Version < 15 Then Exit Sub
|
Port the following code from Ruby to Go with equivalent syntax and logic. | exit if RUBY_VERSION < '1.8.6'
puts bloop.abs if defined?(bloop) and bloop.respond_to?(:abs)
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Keep all operations the same but rewrite the snippet in C. |
import java.lang.reflect.Method
val bloop = -3
val i = 4
val j = 5
val k = 6
fun main(args: Array<String>) {
val version = System.getProperty("java.version")
if (version >= "1.6") println("The current JVM version is $version")
else println("Must use version 1.6 or later")
val topLevel = Class.forName("IntroKt")
val math = Class.forName("java.lang.Math")
val abs = math.getDeclaredMethod("abs", Int::class.java)
val methods = topLevel.getDeclaredMethods()
for (method in methods) {
if (method.name == "getBloop" && method.returnType == Int::class.java) {
println("\nabs(bloop) = ${abs.invoke(null, method.invoke(null))}")
break
}
}
var count = 0
var sum = 0
for (method in methods) {
if (method.returnType == Int::class.java) {
count++
sum += method.invoke(null) as Int
}
}
println("\nThere are $count global integer variables and their sum is $sum")
}
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Write the same code in C# as shown below in Scala. |
import java.lang.reflect.Method
val bloop = -3
val i = 4
val j = 5
val k = 6
fun main(args: Array<String>) {
val version = System.getProperty("java.version")
if (version >= "1.6") println("The current JVM version is $version")
else println("Must use version 1.6 or later")
val topLevel = Class.forName("IntroKt")
val math = Class.forName("java.lang.Math")
val abs = math.getDeclaredMethod("abs", Int::class.java)
val methods = topLevel.getDeclaredMethods()
for (method in methods) {
if (method.name == "getBloop" && method.returnType == Int::class.java) {
println("\nabs(bloop) = ${abs.invoke(null, method.invoke(null))}")
break
}
}
var count = 0
var sum = 0
for (method in methods) {
if (method.returnType == Int::class.java) {
count++
sum += method.invoke(null) as Int
}
}
println("\nThere are $count global integer variables and their sum is $sum")
}
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Preserve the algorithm and functionality while converting the code from Scala to C++. |
import java.lang.reflect.Method
val bloop = -3
val i = 4
val j = 5
val k = 6
fun main(args: Array<String>) {
val version = System.getProperty("java.version")
if (version >= "1.6") println("The current JVM version is $version")
else println("Must use version 1.6 or later")
val topLevel = Class.forName("IntroKt")
val math = Class.forName("java.lang.Math")
val abs = math.getDeclaredMethod("abs", Int::class.java)
val methods = topLevel.getDeclaredMethods()
for (method in methods) {
if (method.name == "getBloop" && method.returnType == Int::class.java) {
println("\nabs(bloop) = ${abs.invoke(null, method.invoke(null))}")
break
}
}
var count = 0
var sum = 0
for (method in methods) {
if (method.returnType == Int::class.java) {
count++
sum += method.invoke(null) as Int
}
}
println("\nThere are $count global integer variables and their sum is $sum")
}
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Convert this Scala block to Java, preserving its control flow and logic. |
import java.lang.reflect.Method
val bloop = -3
val i = 4
val j = 5
val k = 6
fun main(args: Array<String>) {
val version = System.getProperty("java.version")
if (version >= "1.6") println("The current JVM version is $version")
else println("Must use version 1.6 or later")
val topLevel = Class.forName("IntroKt")
val math = Class.forName("java.lang.Math")
val abs = math.getDeclaredMethod("abs", Int::class.java)
val methods = topLevel.getDeclaredMethods()
for (method in methods) {
if (method.name == "getBloop" && method.returnType == Int::class.java) {
println("\nabs(bloop) = ${abs.invoke(null, method.invoke(null))}")
break
}
}
var count = 0
var sum = 0
for (method in methods) {
if (method.returnType == Int::class.java) {
count++
sum += method.invoke(null) as Int
}
}
println("\nThere are $count global integer variables and their sum is $sum")
}
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Ensure the translated Python code behaves exactly like the original Scala snippet. |
import java.lang.reflect.Method
val bloop = -3
val i = 4
val j = 5
val k = 6
fun main(args: Array<String>) {
val version = System.getProperty("java.version")
if (version >= "1.6") println("The current JVM version is $version")
else println("Must use version 1.6 or later")
val topLevel = Class.forName("IntroKt")
val math = Class.forName("java.lang.Math")
val abs = math.getDeclaredMethod("abs", Int::class.java)
val methods = topLevel.getDeclaredMethods()
for (method in methods) {
if (method.name == "getBloop" && method.returnType == Int::class.java) {
println("\nabs(bloop) = ${abs.invoke(null, method.invoke(null))}")
break
}
}
var count = 0
var sum = 0
for (method in methods) {
if (method.returnType == Int::class.java) {
count++
sum += method.invoke(null) as Int
}
}
println("\nThere are $count global integer variables and their sum is $sum")
}
|
import sys
major, minor, bugfix = sys.version_info[:3]
if major < 2:
sys.exit('Python 2 is required')
def defined(name):
return name in globals() or name in locals() or name in vars(__builtins__)
def defined2(name):
try:
eval(name)
return True
except NameError:
return False
if defined('bloop') and defined('abs') and callable(abs):
print abs(bloop)
if defined2('bloop') and defined2('abs') and callable(abs):
print abs(bloop)
|
Write a version of this Scala function in VB with identical behavior. |
import java.lang.reflect.Method
val bloop = -3
val i = 4
val j = 5
val k = 6
fun main(args: Array<String>) {
val version = System.getProperty("java.version")
if (version >= "1.6") println("The current JVM version is $version")
else println("Must use version 1.6 or later")
val topLevel = Class.forName("IntroKt")
val math = Class.forName("java.lang.Math")
val abs = math.getDeclaredMethod("abs", Int::class.java)
val methods = topLevel.getDeclaredMethods()
for (method in methods) {
if (method.name == "getBloop" && method.returnType == Int::class.java) {
println("\nabs(bloop) = ${abs.invoke(null, method.invoke(null))}")
break
}
}
var count = 0
var sum = 0
for (method in methods) {
if (method.returnType == Int::class.java) {
count++
sum += method.invoke(null) as Int
}
}
println("\nThere are $count global integer variables and their sum is $sum")
}
| If Application.Version < 15 Then Exit Sub
|
Keep all operations the same but rewrite the snippet in Go. |
import java.lang.reflect.Method
val bloop = -3
val i = 4
val j = 5
val k = 6
fun main(args: Array<String>) {
val version = System.getProperty("java.version")
if (version >= "1.6") println("The current JVM version is $version")
else println("Must use version 1.6 or later")
val topLevel = Class.forName("IntroKt")
val math = Class.forName("java.lang.Math")
val abs = math.getDeclaredMethod("abs", Int::class.java)
val methods = topLevel.getDeclaredMethods()
for (method in methods) {
if (method.name == "getBloop" && method.returnType == Int::class.java) {
println("\nabs(bloop) = ${abs.invoke(null, method.invoke(null))}")
break
}
}
var count = 0
var sum = 0
for (method in methods) {
if (method.returnType == Int::class.java) {
count++
sum += method.invoke(null) as Int
}
}
println("\nThere are $count global integer variables and their sum is $sum")
}
| package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function")
f, err := elf.Open(os.Args[0])
if err != nil {
log.Fatal(err)
}
defer f.Close()
symSection := f.Section(".gosymtab")
lineSection := f.Section(".gopclntab")
textSection := f.Section(".text")
if symSection == nil || lineSection == nil || textSection == nil {
log.Fatal("symbolic information not found")
}
symData, err := symSection.Data()
if err != nil {
log.Fatal(err)
}
lineData, err := lineSection.Data()
if err != nil {
log.Fatal(err)
}
table, err := gosym.NewTable(symData,
gosym.NewLineTable(lineData, textSection.Addr))
if err != nil {
log.Fatal(" ", err)
}
var foundBloop, foundFabs bool
for _, s := range table.Syms {
if s.Name == "main.bloop" {
foundBloop = true
fmt.Println(" bloop symbol table entry:", s)
} else if s.Name == "math.Abs" {
foundFabs = true
fmt.Println(" abs symbol table entry:", s)
}
}
if foundBloop && foundFabs {
fmt.Println(" bloop: ", bloop)
fmt.Println(" abs(bloop): ", math.Abs(bloop))
}
}
|
Change the following Tcl code into C without altering its purpose. | package require Tcl 8.4 ;
if {[info exists bloop] && [llength [info functions abs]]} {
puts [expr abs($bloop)]
}
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Maintain the same structure and functionality when rewriting this code in C#. | package require Tcl 8.4 ;
if {[info exists bloop] && [llength [info functions abs]]} {
puts [expr abs($bloop)]
}
| using System;
using System.Reflection;
namespace Rosetta_Introspection
{
static public class Program
{
static public int bloop = -10;
static public int bloop2 = -20;
public static void Main()
{
var asm = Assembly.GetExecutingAssembly();
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
if (version < 4)
{
Console.WriteLine("Get with the program! I'm outta here!");
return;
}
FieldInfo bloopField = null;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.Name != "bloop")
{
continue;
}
bloopField = field;
if (bloopField.FieldType != typeof(int))
{
throw new InvalidProgramException("bloop should be an integer");
}
break;
}
if (bloopField != null)
{
break;
}
}
if (bloopField == null)
{
throw new InvalidProgramException("No bloop exported value");
}
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in refAsm.GetExportedTypes())
{
if (type.Name == "Math")
{
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
if (absMethod != null)
{
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
}
}
}
}
int intCount = 0;
int total = 0;
foreach (var type in asm.GetExportedTypes())
{
foreach (var field in type.GetFields())
{
if (field.FieldType == typeof(int))
{
intCount++;
total += (int)field.GetValue(null);
}
}
}
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
Console.ReadKey();
}
}
}
|
Can you help me rewrite this code in C++ instead of Tcl, keeping it the same logically? | package require Tcl 8.4 ;
if {[info exists bloop] && [llength [info functions abs]]} {
puts [expr abs($bloop)]
}
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Write the same algorithm in Java as shown in this Tcl implementation. | package require Tcl 8.4 ;
if {[info exists bloop] && [llength [info functions abs]]} {
puts [expr abs($bloop)]
}
| public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." +
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
if(Double.parseDouble(vers) >= 1.5){
System.out.println("YAY!");
}else{
System.err.println("Must use Java >=1.5");
}
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.