Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Write the same code in PHP as shown below in Erlang. | -module(stack_traces).
-export([main/0]).
main() ->
{ok,A} = outer(),
io:format("~p\n", [A]).
outer() ->
{ok,A} = middle(),
{ok,A}.
middle() ->
{ok,A} = inner(),
{ok,A}.
inner() ->
try throw(42) catch 42 -> {ok,erlang:get_stacktrace()} end.
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Convert this F# snippet to PHP and keep its semantics consistent. | open System.Diagnostics
type myClass() =
member this.inner() = printfn "%A" (new StackTrace())
member this.middle() = this.inner()
member this.outer() = this.middle()
[<EntryPoint>]
let main args =
let that = new myClass()
that.outer()
0
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Write the same algorithm in PHP as shown in this Factor implementation. | USE: prettyprint
get-callstack callstack.
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Please provide an equivalent version of this Forth code in PHP. | [UNDEFINED] R.S [IF]
: RDEPTH STACK-CELLS -2 [+] CELLS RP@ - ;
: R.S R> CR RDEPTH DUP 0> IF DUP
BEGIN DUP WHILE R> -ROT 1- REPEAT DROP DUP
BEGIN DUP WHILE ROT DUP . >R 1- REPEAT DROP
THEN ." " DROP >R ;
[THEN]
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Can you help me rewrite this code in PHP instead of Groovy, keeping it the same logically? | def rawTrace = { Thread.currentThread().stackTrace }
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Convert this J snippet to PHP and keep its semantics consistent. | 13!:0]1
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Transform the following Julia implementation into PHP, maintaining the same output and logic. | f() = g()
g() = println.(stacktrace())
f()
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Transform the following Lua implementation into PHP, maintaining the same output and logic. | function Inner( k )
print( debug.traceback() )
print "Program continues..."
end
function Middle( x, y )
Inner( x+y )
end
function Outer( a, b, c )
Middle( a*b, c )
end
Outer( 2, 3, 5 )
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Port the provided Mathematica code into PHP while preserving the original functionality. | f[g[1, Print[Stack[]]; 2]]
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Write the same code in PHP as shown below in Nim. | proc g() =
writeStackTrace()
echo "----"
for e in getStackTraceEntries():
echo e.filename, "@", e.line, " in ", e.procname
proc f() =
g()
f()
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Rewrite the snippet below in PHP so it works the same as the original OCaml code. | let div a b = a / b
let () =
try let _ = div 3 0 in ()
with e ->
prerr_endline(Printexc.to_string e);
Printexc.print_backtrace stderr;
;;
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Write a version of this Perl function in PHP with identical behavior. | use Carp 'cluck';
sub g {cluck 'Hello from &g';}
sub f {g;}
f;
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Produce a functionally identical PHP code for the snippet given in R. | foo <- function()
{
bar <- function()
{
sys.calls()
}
bar()
}
foo()
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Keep all operations the same but rewrite the snippet in PHP. | #lang racket
(define foo #f)
(set! foo (λ() (bar) (void)))
(define bar #f)
(set! bar (λ() (show-stacktrace) (void)))
(define (show-stacktrace)
(for ([s (continuation-mark-set->context (current-continuation-marks))]
[i (in-naturals)])
(when (car s) (printf "~s: ~s\n" i (car s)))))
(foo)
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Can you help me rewrite this code in PHP instead of REXX, keeping it the same logically? |
options replace format comments java crossref symbols nobinary
class RStackTraces
method inner() static
StackTracer.printStackTrace()
method middle() static
inner()
method outer() static
middle()
method main(args = String[]) public static
outer()
class RStackTraces.StackTracer
method printStackTrace() public static
elems = Thread.currentThread().getStackTrace()
say 'Stack trace:'
j_ = 2
loop i_ = elems.length - 1 to 2 by -1
say ''.left(j_) || elems[i_].getClassName()'.'elems[i_].getMethodName()
j_ = j_ + 2
end i_
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Please provide an equivalent version of this Ruby code in PHP. | def outer(a,b,c)
middle a+b, b+c
end
def middle(d,e)
inner d+e
end
def inner(f)
puts caller(0)
puts "continuing... my arg is
end
outer 2,3,5
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Generate an equivalent PHP version of this Scala code. |
fun myFunc() {
println(Throwable().stackTrace.joinToString("\n"))
}
fun main(args:Array<String>) {
myFunc()
println("\nContinuing ... ")
}
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Produce a functionally identical PHP code for the snippet given in Tcl. | proc printStackTrace {} {
puts "Stack trace:"
for {set i 1} {$i < [info level]} {incr i} {
puts [string repeat " " $i][info level $i]
}
}
| <?php
class StackTraceDemo {
static function inner() {
debug_print_backtrace();
}
static function middle() {
self::inner();
}
static function outer() {
self::middle();
}
}
StackTraceDemo::outer();
?>
|
Rewrite the snippet below in C# so it works the same as the original Ada code. | with Ada.Integer_Text_IO, Ada.Text_IO;
procedure Introspection is
use Ada.Integer_Text_IO, Ada.Text_IO;
begin
Put ("Integer range: ");
Put (Integer'First);
Put (" .. ");
Put (Integer'Last);
New_Line;
Put ("Float digits: ");
Put (Float'Digits);
New_Line;
end Introspection;
| 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 code in C as shown below in Ada. | with Ada.Integer_Text_IO, Ada.Text_IO;
procedure Introspection is
use Ada.Integer_Text_IO, Ada.Text_IO;
begin
Put ("Integer range: ");
Put (Integer'First);
Put (" .. ");
Put (Integer'Last);
New_Line;
Put ("Float digits: ");
Put (Float'Digits);
New_Line;
end Introspection;
| #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 provided Ada code into C++ while preserving the original functionality. | with Ada.Integer_Text_IO, Ada.Text_IO;
procedure Introspection is
use Ada.Integer_Text_IO, Ada.Text_IO;
begin
Put ("Integer range: ");
Put (Integer'First);
Put (" .. ");
Put (Integer'Last);
New_Line;
Put ("Float digits: ");
Put (Float'Digits);
New_Line;
end Introspection;
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Rewrite the snippet below in Go so it works the same as the original Ada code. | with Ada.Integer_Text_IO, Ada.Text_IO;
procedure Introspection is
use Ada.Integer_Text_IO, Ada.Text_IO;
begin
Put ("Integer range: ");
Put (Integer'First);
Put (" .. ");
Put (Integer'Last);
New_Line;
Put ("Float digits: ");
Put (Float'Digits);
New_Line;
end Introspection;
| 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 Java while keeping its functionality equivalent to the Ada version. | with Ada.Integer_Text_IO, Ada.Text_IO;
procedure Introspection is
use Ada.Integer_Text_IO, Ada.Text_IO;
begin
Put ("Integer range: ");
Put (Integer'First);
Put (" .. ");
Put (Integer'Last);
New_Line;
Put ("Float digits: ");
Put (Float'Digits);
New_Line;
end Introspection;
| 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 Ada. | with Ada.Integer_Text_IO, Ada.Text_IO;
procedure Introspection is
use Ada.Integer_Text_IO, Ada.Text_IO;
begin
Put ("Integer range: ");
Put (Integer'First);
Put (" .. ");
Put (Integer'Last);
New_Line;
Put ("Float digits: ");
Put (Float'Digits);
New_Line;
end Introspection;
|
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 Ada to VB with equivalent syntax and logic. | with Ada.Integer_Text_IO, Ada.Text_IO;
procedure Introspection is
use Ada.Integer_Text_IO, Ada.Text_IO;
begin
Put ("Integer range: ");
Put (Integer'First);
Put (" .. ");
Put (Integer'Last);
New_Line;
Put ("Float digits: ");
Put (Float'Digits);
New_Line;
end Introspection;
| If Application.Version < 15 Then Exit Sub
|
Convert the following code from Arturo to C, ensuring the logic remains intact. | if not? sys\version > 0.9.0 -> panic "version too old!"
bloop: 3 - 5
if? set? 'bloop -> "variable 'bloop' is set"
else -> "variable 'bloop' is not set"
if set? 'abs -> print ["the absolute value of bloop is:" abs bloop]
print [
"The sum of all globally defined integers is:"
sum map select keys symbols 'sym -> integer? var sym
'sym -> var sym
]
| #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 Arturo snippet to C# and keep its semantics consistent. | if not? sys\version > 0.9.0 -> panic "version too old!"
bloop: 3 - 5
if? set? 'bloop -> "variable 'bloop' is set"
else -> "variable 'bloop' is not set"
if set? 'abs -> print ["the absolute value of bloop is:" abs bloop]
print [
"The sum of all globally defined integers is:"
sum map select keys symbols 'sym -> integer? var sym
'sym -> var sym
]
| 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();
}
}
}
|
Generate an equivalent C++ version of this Arturo code. | if not? sys\version > 0.9.0 -> panic "version too old!"
bloop: 3 - 5
if? set? 'bloop -> "variable 'bloop' is set"
else -> "variable 'bloop' is not set"
if set? 'abs -> print ["the absolute value of bloop is:" abs bloop]
print [
"The sum of all globally defined integers is:"
sum map select keys symbols 'sym -> integer? var sym
'sym -> var sym
]
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Generate an equivalent Java version of this Arturo code. | if not? sys\version > 0.9.0 -> panic "version too old!"
bloop: 3 - 5
if? set? 'bloop -> "variable 'bloop' is set"
else -> "variable 'bloop' is not set"
if set? 'abs -> print ["the absolute value of bloop is:" abs bloop]
print [
"The sum of all globally defined integers is:"
sum map select keys symbols 'sym -> integer? var sym
'sym -> var sym
]
| 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 Arturo. | if not? sys\version > 0.9.0 -> panic "version too old!"
bloop: 3 - 5
if? set? 'bloop -> "variable 'bloop' is set"
else -> "variable 'bloop' is not set"
if set? 'abs -> print ["the absolute value of bloop is:" abs bloop]
print [
"The sum of all globally defined integers is:"
sum map select keys symbols 'sym -> integer? var sym
'sym -> var sym
]
|
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)
|
Keep all operations the same but rewrite the snippet in VB. | if not? sys\version > 0.9.0 -> panic "version too old!"
bloop: 3 - 5
if? set? 'bloop -> "variable 'bloop' is set"
else -> "variable 'bloop' is not set"
if set? 'abs -> print ["the absolute value of bloop is:" abs bloop]
print [
"The sum of all globally defined integers is:"
sum map select keys symbols 'sym -> integer? var sym
'sym -> var sym
]
| If Application.Version < 15 Then Exit Sub
|
Rewrite the snippet below in Go so it works the same as the original Arturo code. | if not? sys\version > 0.9.0 -> panic "version too old!"
bloop: 3 - 5
if? set? 'bloop -> "variable 'bloop' is set"
else -> "variable 'bloop' is not set"
if set? 'abs -> print ["the absolute value of bloop is:" abs bloop]
print [
"The sum of all globally defined integers is:"
sum map select keys symbols 'sym -> integer? var sym
'sym -> var sym
]
| 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))
}
}
|
Transform the following AutoHotKey implementation into C, maintaining the same output and logic. | if (A_AhkVersion < "1.0.48.03")
{
MsgBox % "you are using" . A_AhkVersion . "`nplease upgrade to" . "1.0.48.03"
ExitApp
}
bloop = -3
if bloop
if IsFunc("abs")
MsgBox % abs(bloop)
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 AutoHotKey to C#, same semantics. | if (A_AhkVersion < "1.0.48.03")
{
MsgBox % "you are using" . A_AhkVersion . "`nplease upgrade to" . "1.0.48.03"
ExitApp
}
bloop = -3
if bloop
if IsFunc("abs")
MsgBox % abs(bloop)
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();
}
}
}
|
Translate this program into C++ but keep the logic exactly as in AutoHotKey. | if (A_AhkVersion < "1.0.48.03")
{
MsgBox % "you are using" . A_AhkVersion . "`nplease upgrade to" . "1.0.48.03"
ExitApp
}
bloop = -3
if bloop
if IsFunc("abs")
MsgBox % abs(bloop)
return
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Change the following AutoHotKey code into Java without altering its purpose. | if (A_AhkVersion < "1.0.48.03")
{
MsgBox % "you are using" . A_AhkVersion . "`nplease upgrade to" . "1.0.48.03"
ExitApp
}
bloop = -3
if bloop
if IsFunc("abs")
MsgBox % abs(bloop)
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");
}
}
}
|
Convert this AutoHotKey snippet to Python and keep its semantics consistent. | if (A_AhkVersion < "1.0.48.03")
{
MsgBox % "you are using" . A_AhkVersion . "`nplease upgrade to" . "1.0.48.03"
ExitApp
}
bloop = -3
if bloop
if IsFunc("abs")
MsgBox % abs(bloop)
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)
|
Change the following AutoHotKey code into VB without altering its purpose. | if (A_AhkVersion < "1.0.48.03")
{
MsgBox % "you are using" . A_AhkVersion . "`nplease upgrade to" . "1.0.48.03"
ExitApp
}
bloop = -3
if bloop
if IsFunc("abs")
MsgBox % abs(bloop)
return
| If Application.Version < 15 Then Exit Sub
|
Port the provided AutoHotKey code into Go while preserving the original functionality. | if (A_AhkVersion < "1.0.48.03")
{
MsgBox % "you are using" . A_AhkVersion . "`nplease upgrade to" . "1.0.48.03"
ExitApp
}
bloop = -3
if bloop
if IsFunc("abs")
MsgBox % abs(bloop)
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))
}
}
|
Preserve the algorithm and functionality while converting the code from AWK to C. |
BEGIN {
if (PROCINFO["version"] < "4.1.0") {
print("version is too old")
exit(1)
}
bloop = -1
if (PROCINFO["identifiers"]["abs"] == "user" && bloop != "") {
printf("bloop = %s\n",bloop)
printf("abs(bloop) = %s\n",abs(bloop))
}
exit(0)
}
function abs(x) { if (x >= 0) { return x } else { return -x } }
| #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 AWK implementation into C#, maintaining the same output and logic. |
BEGIN {
if (PROCINFO["version"] < "4.1.0") {
print("version is too old")
exit(1)
}
bloop = -1
if (PROCINFO["identifiers"]["abs"] == "user" && bloop != "") {
printf("bloop = %s\n",bloop)
printf("abs(bloop) = %s\n",abs(bloop))
}
exit(0)
}
function abs(x) { if (x >= 0) { return x } else { return -x } }
| 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();
}
}
}
|
Keep all operations the same but rewrite the snippet in C++. |
BEGIN {
if (PROCINFO["version"] < "4.1.0") {
print("version is too old")
exit(1)
}
bloop = -1
if (PROCINFO["identifiers"]["abs"] == "user" && bloop != "") {
printf("bloop = %s\n",bloop)
printf("abs(bloop) = %s\n",abs(bloop))
}
exit(0)
}
function abs(x) { if (x >= 0) { return x } else { return -x } }
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Transform the following AWK implementation into Java, maintaining the same output and logic. |
BEGIN {
if (PROCINFO["version"] < "4.1.0") {
print("version is too old")
exit(1)
}
bloop = -1
if (PROCINFO["identifiers"]["abs"] == "user" && bloop != "") {
printf("bloop = %s\n",bloop)
printf("abs(bloop) = %s\n",abs(bloop))
}
exit(0)
}
function abs(x) { if (x >= 0) { return x } else { return -x } }
| 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 following code from AWK to Python with equivalent syntax and logic. |
BEGIN {
if (PROCINFO["version"] < "4.1.0") {
print("version is too old")
exit(1)
}
bloop = -1
if (PROCINFO["identifiers"]["abs"] == "user" && bloop != "") {
printf("bloop = %s\n",bloop)
printf("abs(bloop) = %s\n",abs(bloop))
}
exit(0)
}
function abs(x) { if (x >= 0) { return x } else { return -x } }
|
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 AWK. |
BEGIN {
if (PROCINFO["version"] < "4.1.0") {
print("version is too old")
exit(1)
}
bloop = -1
if (PROCINFO["identifiers"]["abs"] == "user" && bloop != "") {
printf("bloop = %s\n",bloop)
printf("abs(bloop) = %s\n",abs(bloop))
}
exit(0)
}
function abs(x) { if (x >= 0) { return x } else { return -x } }
| If Application.Version < 15 Then Exit Sub
|
Convert this AWK block to Go, preserving its control flow and logic. |
BEGIN {
if (PROCINFO["version"] < "4.1.0") {
print("version is too old")
exit(1)
}
bloop = -1
if (PROCINFO["identifiers"]["abs"] == "user" && bloop != "") {
printf("bloop = %s\n",bloop)
printf("abs(bloop) = %s\n",abs(bloop))
}
exit(0)
}
function abs(x) { if (x >= 0) { return x } else { return -x } }
| 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 a C translation of this BBC_Basic snippet without changing its computational steps. | IF VAL(FNversion) < 5.94 THEN PRINT "Version is too old" : END
ON ERROR LOCAL PRINT "Variable 'bloop' doesn't exist" : END
test = bloop
RESTORE ERROR
ON ERROR LOCAL PRINT "Function 'FNabs()' is not defined" : END
test = ^FNabs()
RESTORE ERROR
PRINT FNabs(bloop)
END
DEF FNversion
LOCAL F%, V$
F% = OPENOUT(@tmp$+"version.txt")
OSCLI "OUTPUT "+STR$F%
*HELP
*OUTPUT 0
PTR #F% = 0
INPUT #F%,V$
CLOSE #F%
= RIGHT$(V$,5)
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Keep all operations the same but rewrite the snippet in C#. | IF VAL(FNversion) < 5.94 THEN PRINT "Version is too old" : END
ON ERROR LOCAL PRINT "Variable 'bloop' doesn't exist" : END
test = bloop
RESTORE ERROR
ON ERROR LOCAL PRINT "Function 'FNabs()' is not defined" : END
test = ^FNabs()
RESTORE ERROR
PRINT FNabs(bloop)
END
DEF FNversion
LOCAL F%, V$
F% = OPENOUT(@tmp$+"version.txt")
OSCLI "OUTPUT "+STR$F%
*HELP
*OUTPUT 0
PTR #F% = 0
INPUT #F%,V$
CLOSE #F%
= RIGHT$(V$,5)
| 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 BBC_Basic code into C++ without altering its purpose. | IF VAL(FNversion) < 5.94 THEN PRINT "Version is too old" : END
ON ERROR LOCAL PRINT "Variable 'bloop' doesn't exist" : END
test = bloop
RESTORE ERROR
ON ERROR LOCAL PRINT "Function 'FNabs()' is not defined" : END
test = ^FNabs()
RESTORE ERROR
PRINT FNabs(bloop)
END
DEF FNversion
LOCAL F%, V$
F% = OPENOUT(@tmp$+"version.txt")
OSCLI "OUTPUT "+STR$F%
*HELP
*OUTPUT 0
PTR #F% = 0
INPUT #F%,V$
CLOSE #F%
= RIGHT$(V$,5)
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Please provide an equivalent version of this BBC_Basic code in Java. | IF VAL(FNversion) < 5.94 THEN PRINT "Version is too old" : END
ON ERROR LOCAL PRINT "Variable 'bloop' doesn't exist" : END
test = bloop
RESTORE ERROR
ON ERROR LOCAL PRINT "Function 'FNabs()' is not defined" : END
test = ^FNabs()
RESTORE ERROR
PRINT FNabs(bloop)
END
DEF FNversion
LOCAL F%, V$
F% = OPENOUT(@tmp$+"version.txt")
OSCLI "OUTPUT "+STR$F%
*HELP
*OUTPUT 0
PTR #F% = 0
INPUT #F%,V$
CLOSE #F%
= RIGHT$(V$,5)
| 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");
}
}
}
|
Maintain the same structure and functionality when rewriting this code in Python. | IF VAL(FNversion) < 5.94 THEN PRINT "Version is too old" : END
ON ERROR LOCAL PRINT "Variable 'bloop' doesn't exist" : END
test = bloop
RESTORE ERROR
ON ERROR LOCAL PRINT "Function 'FNabs()' is not defined" : END
test = ^FNabs()
RESTORE ERROR
PRINT FNabs(bloop)
END
DEF FNversion
LOCAL F%, V$
F% = OPENOUT(@tmp$+"version.txt")
OSCLI "OUTPUT "+STR$F%
*HELP
*OUTPUT 0
PTR #F% = 0
INPUT #F%,V$
CLOSE #F%
= RIGHT$(V$,5)
|
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)
|
Preserve the algorithm and functionality while converting the code from BBC_Basic to VB. | IF VAL(FNversion) < 5.94 THEN PRINT "Version is too old" : END
ON ERROR LOCAL PRINT "Variable 'bloop' doesn't exist" : END
test = bloop
RESTORE ERROR
ON ERROR LOCAL PRINT "Function 'FNabs()' is not defined" : END
test = ^FNabs()
RESTORE ERROR
PRINT FNabs(bloop)
END
DEF FNversion
LOCAL F%, V$
F% = OPENOUT(@tmp$+"version.txt")
OSCLI "OUTPUT "+STR$F%
*HELP
*OUTPUT 0
PTR #F% = 0
INPUT #F%,V$
CLOSE #F%
= RIGHT$(V$,5)
| If Application.Version < 15 Then Exit Sub
|
Port the provided BBC_Basic code into Go while preserving the original functionality. | IF VAL(FNversion) < 5.94 THEN PRINT "Version is too old" : END
ON ERROR LOCAL PRINT "Variable 'bloop' doesn't exist" : END
test = bloop
RESTORE ERROR
ON ERROR LOCAL PRINT "Function 'FNabs()' is not defined" : END
test = ^FNabs()
RESTORE ERROR
PRINT FNabs(bloop)
END
DEF FNversion
LOCAL F%, V$
F% = OPENOUT(@tmp$+"version.txt")
OSCLI "OUTPUT "+STR$F%
*HELP
*OUTPUT 0
PTR #F% = 0
INPUT #F%,V$
CLOSE #F%
= RIGHT$(V$,5)
| 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 Clojure code into C without altering its purpose. |
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (System/getProperty "java.version")))]
(if (>= version 1.5)
(println "Version ok")
(throw (Error. "Bad version"))))
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (clojure-version)))]
(if (>= version 1.0)
(println "Version ok")
(throw (Error. "Bad version"))))
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Change the programming language of this snippet from Clojure to C# without modifying what it does. |
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (System/getProperty "java.version")))]
(if (>= version 1.5)
(println "Version ok")
(throw (Error. "Bad version"))))
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (clojure-version)))]
(if (>= version 1.0)
(println "Version ok")
(throw (Error. "Bad 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();
}
}
}
|
Rewrite this program in C++ while keeping its functionality equivalent to the Clojure version. |
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (System/getProperty "java.version")))]
(if (>= version 1.5)
(println "Version ok")
(throw (Error. "Bad version"))))
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (clojure-version)))]
(if (>= version 1.0)
(println "Version ok")
(throw (Error. "Bad version"))))
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Transform the following Clojure implementation into Java, maintaining the same output and logic. |
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (System/getProperty "java.version")))]
(if (>= version 1.5)
(println "Version ok")
(throw (Error. "Bad version"))))
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (clojure-version)))]
(if (>= version 1.0)
(println "Version ok")
(throw (Error. "Bad 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");
}
}
}
|
Produce a functionally identical Python code for the snippet given in Clojure. |
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (System/getProperty "java.version")))]
(if (>= version 1.5)
(println "Version ok")
(throw (Error. "Bad version"))))
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (clojure-version)))]
(if (>= version 1.0)
(println "Version ok")
(throw (Error. "Bad 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)
|
Please provide an equivalent version of this Clojure code in VB. |
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (System/getProperty "java.version")))]
(if (>= version 1.5)
(println "Version ok")
(throw (Error. "Bad version"))))
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (clojure-version)))]
(if (>= version 1.0)
(println "Version ok")
(throw (Error. "Bad version"))))
| If Application.Version < 15 Then Exit Sub
|
Convert the following code from Clojure to Go, ensuring the logic remains intact. |
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (System/getProperty "java.version")))]
(if (>= version 1.5)
(println "Version ok")
(throw (Error. "Bad version"))))
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (clojure-version)))]
(if (>= version 1.0)
(println "Version ok")
(throw (Error. "Bad 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))
}
}
|
Convert this Common_Lisp snippet to C and keep its semantics consistent. | (let* ((ver (lisp-implementation-version))
(major (parse-integer ver :start 0 :end (position #\. ver))))
#+lispworks (assert (>= 5 major) () "Requires Lispworks version 5 or above")
#+clisp (assert (>= 2 major) () "Requires CLISP 2.n")
)
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Convert the following code from Common_Lisp to C#, ensuring the logic remains intact. | (let* ((ver (lisp-implementation-version))
(major (parse-integer ver :start 0 :end (position #\. ver))))
#+lispworks (assert (>= 5 major) () "Requires Lispworks version 5 or above")
#+clisp (assert (>= 2 major) () "Requires CLISP 2.n")
)
| 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 functionally identical C++ code for the snippet given in Common_Lisp. | (let* ((ver (lisp-implementation-version))
(major (parse-integer ver :start 0 :end (position #\. ver))))
#+lispworks (assert (>= 5 major) () "Requires Lispworks version 5 or above")
#+clisp (assert (>= 2 major) () "Requires CLISP 2.n")
)
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Port the following code from Common_Lisp to Java with equivalent syntax and logic. | (let* ((ver (lisp-implementation-version))
(major (parse-integer ver :start 0 :end (position #\. ver))))
#+lispworks (assert (>= 5 major) () "Requires Lispworks version 5 or above")
#+clisp (assert (>= 2 major) () "Requires CLISP 2.n")
)
| 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 the snippet below in Python so it works the same as the original Common_Lisp code. | (let* ((ver (lisp-implementation-version))
(major (parse-integer ver :start 0 :end (position #\. ver))))
#+lispworks (assert (>= 5 major) () "Requires Lispworks version 5 or above")
#+clisp (assert (>= 2 major) () "Requires CLISP 2.n")
)
|
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 Common_Lisp code snippet into VB without altering its behavior. | (let* ((ver (lisp-implementation-version))
(major (parse-integer ver :start 0 :end (position #\. ver))))
#+lispworks (assert (>= 5 major) () "Requires Lispworks version 5 or above")
#+clisp (assert (>= 2 major) () "Requires CLISP 2.n")
)
| If Application.Version < 15 Then Exit Sub
|
Change the programming language of this snippet from Common_Lisp to Go without modifying what it does. | (let* ((ver (lisp-implementation-version))
(major (parse-integer ver :start 0 :end (position #\. ver))))
#+lispworks (assert (>= 5 major) () "Requires Lispworks version 5 or above")
#+clisp (assert (>= 2 major) () "Requires CLISP 2.n")
)
| 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 D snippet to C and keep its semantics consistent. |
immutable x = 3, y = 100, z = 3_000;
short w = 1;
immutable s = "some string";
void main() {
import std.compiler, std.math, std.traits;
static assert(version_major > 1 && version_minor > 50,
"I can't cope with this compiler version.");
immutable bloop = 10;
static if (__traits(compiles, bloop.abs)) {
pragma(msg, "The expression is compilable.");
auto x = bloop.abs;
} else {
pragma(msg, "The expression can't be compiled.");
}
import std.stdio;
immutable s = 10_000;
int tot = 0;
foreach (name; __traits(allMembers, mixin(__MODULE__)))
static if (name != "object" &&
is(int == Unqual!(typeof(mixin("." ~ name)))))
tot += mixin("." ~ name);
writeln("Total of the module-level ints (could overflow): ", tot);
}
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Keep all operations the same but rewrite the snippet in C#. |
immutable x = 3, y = 100, z = 3_000;
short w = 1;
immutable s = "some string";
void main() {
import std.compiler, std.math, std.traits;
static assert(version_major > 1 && version_minor > 50,
"I can't cope with this compiler version.");
immutable bloop = 10;
static if (__traits(compiles, bloop.abs)) {
pragma(msg, "The expression is compilable.");
auto x = bloop.abs;
} else {
pragma(msg, "The expression can't be compiled.");
}
import std.stdio;
immutable s = 10_000;
int tot = 0;
foreach (name; __traits(allMembers, mixin(__MODULE__)))
static if (name != "object" &&
is(int == Unqual!(typeof(mixin("." ~ name)))))
tot += mixin("." ~ name);
writeln("Total of the module-level ints (could overflow): ", tot);
}
| 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();
}
}
}
|
Please provide an equivalent version of this D code in C++. |
immutable x = 3, y = 100, z = 3_000;
short w = 1;
immutable s = "some string";
void main() {
import std.compiler, std.math, std.traits;
static assert(version_major > 1 && version_minor > 50,
"I can't cope with this compiler version.");
immutable bloop = 10;
static if (__traits(compiles, bloop.abs)) {
pragma(msg, "The expression is compilable.");
auto x = bloop.abs;
} else {
pragma(msg, "The expression can't be compiled.");
}
import std.stdio;
immutable s = 10_000;
int tot = 0;
foreach (name; __traits(allMembers, mixin(__MODULE__)))
static if (name != "object" &&
is(int == Unqual!(typeof(mixin("." ~ name)))))
tot += mixin("." ~ name);
writeln("Total of the module-level ints (could overflow): ", tot);
}
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Convert this D snippet to Java and keep its semantics consistent. |
immutable x = 3, y = 100, z = 3_000;
short w = 1;
immutable s = "some string";
void main() {
import std.compiler, std.math, std.traits;
static assert(version_major > 1 && version_minor > 50,
"I can't cope with this compiler version.");
immutable bloop = 10;
static if (__traits(compiles, bloop.abs)) {
pragma(msg, "The expression is compilable.");
auto x = bloop.abs;
} else {
pragma(msg, "The expression can't be compiled.");
}
import std.stdio;
immutable s = 10_000;
int tot = 0;
foreach (name; __traits(allMembers, mixin(__MODULE__)))
static if (name != "object" &&
is(int == Unqual!(typeof(mixin("." ~ name)))))
tot += mixin("." ~ name);
writeln("Total of the module-level ints (could overflow): ", tot);
}
| 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");
}
}
}
|
Produce a functionally identical Python code for the snippet given in D. |
immutable x = 3, y = 100, z = 3_000;
short w = 1;
immutable s = "some string";
void main() {
import std.compiler, std.math, std.traits;
static assert(version_major > 1 && version_minor > 50,
"I can't cope with this compiler version.");
immutable bloop = 10;
static if (__traits(compiles, bloop.abs)) {
pragma(msg, "The expression is compilable.");
auto x = bloop.abs;
} else {
pragma(msg, "The expression can't be compiled.");
}
import std.stdio;
immutable s = 10_000;
int tot = 0;
foreach (name; __traits(allMembers, mixin(__MODULE__)))
static if (name != "object" &&
is(int == Unqual!(typeof(mixin("." ~ name)))))
tot += mixin("." ~ name);
writeln("Total of the module-level ints (could overflow): ", tot);
}
|
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)
|
Preserve the algorithm and functionality while converting the code from D to VB. |
immutable x = 3, y = 100, z = 3_000;
short w = 1;
immutable s = "some string";
void main() {
import std.compiler, std.math, std.traits;
static assert(version_major > 1 && version_minor > 50,
"I can't cope with this compiler version.");
immutable bloop = 10;
static if (__traits(compiles, bloop.abs)) {
pragma(msg, "The expression is compilable.");
auto x = bloop.abs;
} else {
pragma(msg, "The expression can't be compiled.");
}
import std.stdio;
immutable s = 10_000;
int tot = 0;
foreach (name; __traits(allMembers, mixin(__MODULE__)))
static if (name != "object" &&
is(int == Unqual!(typeof(mixin("." ~ name)))))
tot += mixin("." ~ name);
writeln("Total of the module-level ints (could overflow): ", tot);
}
| If Application.Version < 15 Then Exit Sub
|
Ensure the translated Go code behaves exactly like the original D snippet. |
immutable x = 3, y = 100, z = 3_000;
short w = 1;
immutable s = "some string";
void main() {
import std.compiler, std.math, std.traits;
static assert(version_major > 1 && version_minor > 50,
"I can't cope with this compiler version.");
immutable bloop = 10;
static if (__traits(compiles, bloop.abs)) {
pragma(msg, "The expression is compilable.");
auto x = bloop.abs;
} else {
pragma(msg, "The expression can't be compiled.");
}
import std.stdio;
immutable s = 10_000;
int tot = 0;
foreach (name; __traits(allMembers, mixin(__MODULE__)))
static if (name != "object" &&
is(int == Unqual!(typeof(mixin("." ~ name)))))
tot += mixin("." ~ name);
writeln("Total of the module-level ints (could overflow): ", tot);
}
| 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 Erlang version. | -module( introspection ).
-export( [task/0] ).
task() ->
exit_if_too_old( erlang:system_info(otp_release) ),
Bloop = lists:keyfind( bloop, 1, ?MODULE:module_info(functions) ),
Abs = lists:keyfind( abs, 1, erlang:module_info(exports) ),
io:fwrite( "abs( bloop ) => ~p~n", [call_abs_with_bloop(Abs, Bloop)] ),
io:fwrite( "Number of modules: ~p~n", [erlang:length(code:all_loaded())] ).
bloop() -> -1.
call_abs_with_bloop( {abs, 1}, {bloop, 0} ) -> erlang:abs( bloop() );
call_abs_with_bloop( _Missing, _Not_here ) -> abs_and_bloop_missing.
exit_if_too_old( Release ) when Release < "R13A" -> erlang:exit( too_old_release );
exit_if_too_old( _Release ) -> ok.
| #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#pragma error("C compiler must adhere to at least C99 for the following code.")
#else
#endif
|
Convert the following code from Erlang to C#, ensuring the logic remains intact. | -module( introspection ).
-export( [task/0] ).
task() ->
exit_if_too_old( erlang:system_info(otp_release) ),
Bloop = lists:keyfind( bloop, 1, ?MODULE:module_info(functions) ),
Abs = lists:keyfind( abs, 1, erlang:module_info(exports) ),
io:fwrite( "abs( bloop ) => ~p~n", [call_abs_with_bloop(Abs, Bloop)] ),
io:fwrite( "Number of modules: ~p~n", [erlang:length(code:all_loaded())] ).
bloop() -> -1.
call_abs_with_bloop( {abs, 1}, {bloop, 0} ) -> erlang:abs( bloop() );
call_abs_with_bloop( _Missing, _Not_here ) -> abs_and_bloop_missing.
exit_if_too_old( Release ) when Release < "R13A" -> erlang:exit( too_old_release );
exit_if_too_old( _Release ) -> ok.
| 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 Erlang to C++ with equivalent syntax and logic. | -module( introspection ).
-export( [task/0] ).
task() ->
exit_if_too_old( erlang:system_info(otp_release) ),
Bloop = lists:keyfind( bloop, 1, ?MODULE:module_info(functions) ),
Abs = lists:keyfind( abs, 1, erlang:module_info(exports) ),
io:fwrite( "abs( bloop ) => ~p~n", [call_abs_with_bloop(Abs, Bloop)] ),
io:fwrite( "Number of modules: ~p~n", [erlang:length(code:all_loaded())] ).
bloop() -> -1.
call_abs_with_bloop( {abs, 1}, {bloop, 0} ) -> erlang:abs( bloop() );
call_abs_with_bloop( _Missing, _Not_here ) -> abs_and_bloop_missing.
exit_if_too_old( Release ) when Release < "R13A" -> erlang:exit( too_old_release );
exit_if_too_old( _Release ) -> ok.
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Change the following Erlang code into Java without altering its purpose. | -module( introspection ).
-export( [task/0] ).
task() ->
exit_if_too_old( erlang:system_info(otp_release) ),
Bloop = lists:keyfind( bloop, 1, ?MODULE:module_info(functions) ),
Abs = lists:keyfind( abs, 1, erlang:module_info(exports) ),
io:fwrite( "abs( bloop ) => ~p~n", [call_abs_with_bloop(Abs, Bloop)] ),
io:fwrite( "Number of modules: ~p~n", [erlang:length(code:all_loaded())] ).
bloop() -> -1.
call_abs_with_bloop( {abs, 1}, {bloop, 0} ) -> erlang:abs( bloop() );
call_abs_with_bloop( _Missing, _Not_here ) -> abs_and_bloop_missing.
exit_if_too_old( Release ) when Release < "R13A" -> erlang:exit( too_old_release );
exit_if_too_old( _Release ) -> ok.
| 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 Erlang code snippet into Python without altering its behavior. | -module( introspection ).
-export( [task/0] ).
task() ->
exit_if_too_old( erlang:system_info(otp_release) ),
Bloop = lists:keyfind( bloop, 1, ?MODULE:module_info(functions) ),
Abs = lists:keyfind( abs, 1, erlang:module_info(exports) ),
io:fwrite( "abs( bloop ) => ~p~n", [call_abs_with_bloop(Abs, Bloop)] ),
io:fwrite( "Number of modules: ~p~n", [erlang:length(code:all_loaded())] ).
bloop() -> -1.
call_abs_with_bloop( {abs, 1}, {bloop, 0} ) -> erlang:abs( bloop() );
call_abs_with_bloop( _Missing, _Not_here ) -> abs_and_bloop_missing.
exit_if_too_old( Release ) when Release < "R13A" -> erlang:exit( too_old_release );
exit_if_too_old( _Release ) -> ok.
|
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 VB while keeping its functionality equivalent to the Erlang version. | -module( introspection ).
-export( [task/0] ).
task() ->
exit_if_too_old( erlang:system_info(otp_release) ),
Bloop = lists:keyfind( bloop, 1, ?MODULE:module_info(functions) ),
Abs = lists:keyfind( abs, 1, erlang:module_info(exports) ),
io:fwrite( "abs( bloop ) => ~p~n", [call_abs_with_bloop(Abs, Bloop)] ),
io:fwrite( "Number of modules: ~p~n", [erlang:length(code:all_loaded())] ).
bloop() -> -1.
call_abs_with_bloop( {abs, 1}, {bloop, 0} ) -> erlang:abs( bloop() );
call_abs_with_bloop( _Missing, _Not_here ) -> abs_and_bloop_missing.
exit_if_too_old( Release ) when Release < "R13A" -> erlang:exit( too_old_release );
exit_if_too_old( _Release ) -> ok.
| If Application.Version < 15 Then Exit Sub
|
Write a version of this Erlang function in Go with identical behavior. | -module( introspection ).
-export( [task/0] ).
task() ->
exit_if_too_old( erlang:system_info(otp_release) ),
Bloop = lists:keyfind( bloop, 1, ?MODULE:module_info(functions) ),
Abs = lists:keyfind( abs, 1, erlang:module_info(exports) ),
io:fwrite( "abs( bloop ) => ~p~n", [call_abs_with_bloop(Abs, Bloop)] ),
io:fwrite( "Number of modules: ~p~n", [erlang:length(code:all_loaded())] ).
bloop() -> -1.
call_abs_with_bloop( {abs, 1}, {bloop, 0} ) -> erlang:abs( bloop() );
call_abs_with_bloop( _Missing, _Not_here ) -> abs_and_bloop_missing.
exit_if_too_old( Release ) when Release < "R13A" -> erlang:exit( too_old_release );
exit_if_too_old( _Release ) -> ok.
| 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))
}
}
|
Transform the following Factor implementation into C, maintaining the same output and logic. | : if-older ( n true false -- )
[ build > ] 2dip if ; inline
: when-older ( n true -- )
[ ] if-older ; inline
: unless-older ( n false -- )
[ [ ] ] dip if-older ; inline
900 [ "Your version of Factor is too old." print 1 exit ] when-older
| #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 provided Factor code into C# while preserving the original functionality. | : if-older ( n true false -- )
[ build > ] 2dip if ; inline
: when-older ( n true -- )
[ ] if-older ; inline
: unless-older ( n false -- )
[ [ ] ] dip if-older ; inline
900 [ "Your version of Factor is too old." print 1 exit ] when-older
| 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 this Factor block to C++, preserving its control flow and logic. | : if-older ( n true false -- )
[ build > ] 2dip if ; inline
: when-older ( n true -- )
[ ] if-older ; inline
: unless-older ( n false -- )
[ [ ] ] dip if-older ; inline
900 [ "Your version of Factor is too old." print 1 exit ] when-older
| #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 Factor to Java. | : if-older ( n true false -- )
[ build > ] 2dip if ; inline
: when-older ( n true -- )
[ ] if-older ; inline
: unless-older ( n false -- )
[ [ ] ] dip if-older ; inline
900 [ "Your version of Factor is too old." print 1 exit ] when-older
| 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 Factor code into Python while preserving the original functionality. | : if-older ( n true false -- )
[ build > ] 2dip if ; inline
: when-older ( n true -- )
[ ] if-older ; inline
: unless-older ( n false -- )
[ [ ] ] dip if-older ; inline
900 [ "Your version of Factor is too old." print 1 exit ] when-older
|
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 Factor snippet. | : if-older ( n true false -- )
[ build > ] 2dip if ; inline
: when-older ( n true -- )
[ ] if-older ; inline
: unless-older ( n false -- )
[ [ ] ] dip if-older ; inline
900 [ "Your version of Factor is too old." print 1 exit ] when-older
| If Application.Version < 15 Then Exit Sub
|
Translate the given Factor code snippet into Go without altering its behavior. | : if-older ( n true false -- )
[ build > ] 2dip if ; inline
: when-older ( n true -- )
[ ] if-older ; inline
: unless-older ( n false -- )
[ [ ] ] dip if-older ; inline
900 [ "Your version of Factor is too old." print 1 exit ] when-older
| 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 Forth snippet to C and keep its semantics consistent. | s" MAX-U" environment? [IF]
0xffffffff <> [IF] . bye [THEN]
[THEN]
[defined] bloop [if]
[defined] abs [if]
bloop @ abs
[then] [then]
| #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 Forth, keeping it the same logically? | s" MAX-U" environment? [IF]
0xffffffff <> [IF] . bye [THEN]
[THEN]
[defined] bloop [if]
[defined] abs [if]
bloop @ abs
[then] [then]
| 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 this Forth block to C++, preserving its control flow and logic. | s" MAX-U" environment? [IF]
0xffffffff <> [IF] . bye [THEN]
[THEN]
[defined] bloop [if]
[defined] abs [if]
bloop @ abs
[then] [then]
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Produce a language-to-language conversion: from Forth to Java, same semantics. | s" MAX-U" environment? [IF]
0xffffffff <> [IF] . bye [THEN]
[THEN]
[defined] bloop [if]
[defined] abs [if]
bloop @ abs
[then] [then]
| 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 Forth code into Python while preserving the original functionality. | s" MAX-U" environment? [IF]
0xffffffff <> [IF] . bye [THEN]
[THEN]
[defined] bloop [if]
[defined] abs [if]
bloop @ abs
[then] [then]
|
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)
|
Maintain the same structure and functionality when rewriting this code in VB. | s" MAX-U" environment? [IF]
0xffffffff <> [IF] . bye [THEN]
[THEN]
[defined] bloop [if]
[defined] abs [if]
bloop @ abs
[then] [then]
| If Application.Version < 15 Then Exit Sub
|
Convert this Forth block to Go, preserving its control flow and logic. | s" MAX-U" environment? [IF]
0xffffffff <> [IF] . bye [THEN]
[THEN]
[defined] bloop [if]
[defined] abs [if]
bloop @ abs
[then] [then]
| 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))
}
}
|
Preserve the algorithm and functionality while converting the code from Haskell to C. | import Data.Version
import Control.Monad
import System.Info
minGHCVersion = Version [6, 8] []
main = when (compilerName == "ghc" && compilerVersion < minGHCVersion) $
fail "Compiler too old."
| #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 provided Haskell code into C++ while preserving the original functionality. | import Data.Version
import Control.Monad
import System.Info
minGHCVersion = Version [6, 8] []
main = when (compilerName == "ghc" && compilerVersion < minGHCVersion) $
fail "Compiler too old."
| #if !defined(__cplusplus) || __cplusplus < 201103L
#pragma error("The following code requires at least C++11.")
#else
#endif
|
Keep all operations the same but rewrite the snippet in Java. | import Data.Version
import Control.Monad
import System.Info
minGHCVersion = Version [6, 8] []
main = when (compilerName == "ghc" && compilerVersion < minGHCVersion) $
fail "Compiler too old."
| 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");
}
}
}
|
Generate a Python translation of this Haskell snippet without changing its computational steps. | import Data.Version
import Control.Monad
import System.Info
minGHCVersion = Version [6, 8] []
main = when (compilerName == "ghc" && compilerVersion < minGHCVersion) $
fail "Compiler too old."
|
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 Haskell code. | import Data.Version
import Control.Monad
import System.Info
minGHCVersion = Version [6, 8] []
main = when (compilerName == "ghc" && compilerVersion < minGHCVersion) $
fail "Compiler too old."
| If Application.Version < 15 Then Exit Sub
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.