Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Produce a functionally identical C code for the snippet given in Delphi. | program Project1;
type
TFuncIntResult = reference to function: Integer;
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := CreateFunc(i);
for i := Low(Funcs) to High(Funcs) do
Writeln(Funcs[i]());
end.
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Generate an equivalent C# version of this Delphi code. | program Project1;
type
TFuncIntResult = reference to function: Integer;
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := CreateFunc(i);
for i := Low(Funcs) to High(Funcs) do
Writeln(Funcs[i]());
end.
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Rewrite this program in C# while keeping its functionality equivalent to the Delphi version. | program Project1;
type
TFuncIntResult = reference to function: Integer;
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := CreateFunc(i);
for i := Low(Funcs) to High(Funcs) do
Writeln(Funcs[i]());
end.
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Translate this program into C++ but keep the logic exactly as in Delphi. | program Project1;
type
TFuncIntResult = reference to function: Integer;
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := CreateFunc(i);
for i := Low(Funcs) to High(Funcs) do
Writeln(Funcs[i]());
end.
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Port the following code from Delphi to C++ with equivalent syntax and logic. | program Project1;
type
TFuncIntResult = reference to function: Integer;
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := CreateFunc(i);
for i := Low(Funcs) to High(Funcs) do
Writeln(Funcs[i]());
end.
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Translate this program into Java but keep the logic exactly as in Delphi. | program Project1;
type
TFuncIntResult = reference to function: Integer;
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := CreateFunc(i);
for i := Low(Funcs) to High(Funcs) do
Writeln(Funcs[i]());
end.
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Port the following code from Delphi to Java with equivalent syntax and logic. | program Project1;
type
TFuncIntResult = reference to function: Integer;
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := CreateFunc(i);
for i := Low(Funcs) to High(Funcs) do
Writeln(Funcs[i]());
end.
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Ensure the translated Python code behaves exactly like the original Delphi snippet. | program Project1;
type
TFuncIntResult = reference to function: Integer;
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := CreateFunc(i);
for i := Low(Funcs) to High(Funcs) do
Writeln(Funcs[i]());
end.
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Convert this Delphi snippet to Python and keep its semantics consistent. | program Project1;
type
TFuncIntResult = reference to function: Integer;
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := CreateFunc(i);
for i := Low(Funcs) to High(Funcs) do
Writeln(Funcs[i]());
end.
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Convert the following code from Delphi to Go, ensuring the logic remains intact. | program Project1;
type
TFuncIntResult = reference to function: Integer;
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := CreateFunc(i);
for i := Low(Funcs) to High(Funcs) do
Writeln(Funcs[i]());
end.
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Rewrite this program in Go while keeping its functionality equivalent to the Delphi version. | program Project1;
type
TFuncIntResult = reference to function: Integer;
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := CreateFunc(i);
for i := Low(Funcs) to High(Funcs) do
Writeln(Funcs[i]());
end.
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Ensure the translated C code behaves exactly like the original Elixir snippet. | funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Please provide an equivalent version of this Elixir code in C. | funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Please provide an equivalent version of this Elixir code in C#. | funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Rewrite this program in C# while keeping its functionality equivalent to the Elixir version. | funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Maintain the same structure and functionality when rewriting this code in C++. | funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Change the programming language of this snippet from Elixir to C++ without modifying what it does. | funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Port the provided Elixir code into Java while preserving the original functionality. | funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Rewrite the snippet below in Java so it works the same as the original Elixir code. | funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Produce a language-to-language conversion: from Elixir to Python, same semantics. | funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Port the following code from Elixir to Python with equivalent syntax and logic. | funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Ensure the translated Go code behaves exactly like the original Elixir snippet. | funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Preserve the algorithm and functionality while converting the code from Elixir to Go. | funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Rewrite this program in C while keeping its functionality equivalent to the Erlang version. | -module(capture_demo).
-export([demo/0]).
demo() ->
Funs = lists:map(fun (X) ->
fun () ->
X * X
end
end,
lists:seq(1,10)),
lists:foreach(fun (F) ->
io:fwrite("~B~n",[F()])
end, Funs).
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Generate a C translation of this Erlang snippet without changing its computational steps. | -module(capture_demo).
-export([demo/0]).
demo() ->
Funs = lists:map(fun (X) ->
fun () ->
X * X
end
end,
lists:seq(1,10)),
lists:foreach(fun (F) ->
io:fwrite("~B~n",[F()])
end, Funs).
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Translate this program into C# but keep the logic exactly as in Erlang. | -module(capture_demo).
-export([demo/0]).
demo() ->
Funs = lists:map(fun (X) ->
fun () ->
X * X
end
end,
lists:seq(1,10)),
lists:foreach(fun (F) ->
io:fwrite("~B~n",[F()])
end, Funs).
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Produce a functionally identical C# code for the snippet given in Erlang. | -module(capture_demo).
-export([demo/0]).
demo() ->
Funs = lists:map(fun (X) ->
fun () ->
X * X
end
end,
lists:seq(1,10)),
lists:foreach(fun (F) ->
io:fwrite("~B~n",[F()])
end, Funs).
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Produce a functionally identical C++ code for the snippet given in Erlang. | -module(capture_demo).
-export([demo/0]).
demo() ->
Funs = lists:map(fun (X) ->
fun () ->
X * X
end
end,
lists:seq(1,10)),
lists:foreach(fun (F) ->
io:fwrite("~B~n",[F()])
end, Funs).
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Port the provided Erlang code into Java while preserving the original functionality. | -module(capture_demo).
-export([demo/0]).
demo() ->
Funs = lists:map(fun (X) ->
fun () ->
X * X
end
end,
lists:seq(1,10)),
lists:foreach(fun (F) ->
io:fwrite("~B~n",[F()])
end, Funs).
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Keep all operations the same but rewrite the snippet in Java. | -module(capture_demo).
-export([demo/0]).
demo() ->
Funs = lists:map(fun (X) ->
fun () ->
X * X
end
end,
lists:seq(1,10)),
lists:foreach(fun (F) ->
io:fwrite("~B~n",[F()])
end, Funs).
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Keep all operations the same but rewrite the snippet in Python. | -module(capture_demo).
-export([demo/0]).
demo() ->
Funs = lists:map(fun (X) ->
fun () ->
X * X
end
end,
lists:seq(1,10)),
lists:foreach(fun (F) ->
io:fwrite("~B~n",[F()])
end, Funs).
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Rewrite this program in Python while keeping its functionality equivalent to the Erlang version. | -module(capture_demo).
-export([demo/0]).
demo() ->
Funs = lists:map(fun (X) ->
fun () ->
X * X
end
end,
lists:seq(1,10)),
lists:foreach(fun (F) ->
io:fwrite("~B~n",[F()])
end, Funs).
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Convert this Erlang snippet to Go and keep its semantics consistent. | -module(capture_demo).
-export([demo/0]).
demo() ->
Funs = lists:map(fun (X) ->
fun () ->
X * X
end
end,
lists:seq(1,10)),
lists:foreach(fun (F) ->
io:fwrite("~B~n",[F()])
end, Funs).
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Port the following code from Erlang to Go with equivalent syntax and logic. | -module(capture_demo).
-export([demo/0]).
demo() ->
Funs = lists:map(fun (X) ->
fun () ->
X * X
end
end,
lists:seq(1,10)),
lists:foreach(fun (F) ->
io:fwrite("~B~n",[F()])
end, Funs).
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Generate an equivalent C version of this F# code. | [<EntryPoint>]
let main argv =
let fs = List.init 10 (fun i -> fun () -> i*i)
do List.iter (fun f -> printfn "%d" <| f()) fs
0
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Keep all operations the same but rewrite the snippet in C. | [<EntryPoint>]
let main argv =
let fs = List.init 10 (fun i -> fun () -> i*i)
do List.iter (fun f -> printfn "%d" <| f()) fs
0
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Ensure the translated C# code behaves exactly like the original F# snippet. | [<EntryPoint>]
let main argv =
let fs = List.init 10 (fun i -> fun () -> i*i)
do List.iter (fun f -> printfn "%d" <| f()) fs
0
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Write the same code in C# as shown below in F#. | [<EntryPoint>]
let main argv =
let fs = List.init 10 (fun i -> fun () -> i*i)
do List.iter (fun f -> printfn "%d" <| f()) fs
0
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Change the programming language of this snippet from F# to C++ without modifying what it does. | [<EntryPoint>]
let main argv =
let fs = List.init 10 (fun i -> fun () -> i*i)
do List.iter (fun f -> printfn "%d" <| f()) fs
0
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Port the provided F# code into C++ while preserving the original functionality. | [<EntryPoint>]
let main argv =
let fs = List.init 10 (fun i -> fun () -> i*i)
do List.iter (fun f -> printfn "%d" <| f()) fs
0
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Rewrite the snippet below in Java so it works the same as the original F# code. | [<EntryPoint>]
let main argv =
let fs = List.init 10 (fun i -> fun () -> i*i)
do List.iter (fun f -> printfn "%d" <| f()) fs
0
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Convert the following code from F# to Java, ensuring the logic remains intact. | [<EntryPoint>]
let main argv =
let fs = List.init 10 (fun i -> fun () -> i*i)
do List.iter (fun f -> printfn "%d" <| f()) fs
0
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Rewrite the snippet below in Python so it works the same as the original F# code. | [<EntryPoint>]
let main argv =
let fs = List.init 10 (fun i -> fun () -> i*i)
do List.iter (fun f -> printfn "%d" <| f()) fs
0
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Transform the following F# implementation into Python, maintaining the same output and logic. | [<EntryPoint>]
let main argv =
let fs = List.init 10 (fun i -> fun () -> i*i)
do List.iter (fun f -> printfn "%d" <| f()) fs
0
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Rewrite the snippet below in Go so it works the same as the original F# code. | [<EntryPoint>]
let main argv =
let fs = List.init 10 (fun i -> fun () -> i*i)
do List.iter (fun f -> printfn "%d" <| f()) fs
0
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Write the same algorithm in Go as shown in this F# implementation. | [<EntryPoint>]
let main argv =
let fs = List.init 10 (fun i -> fun () -> i*i)
do List.iter (fun f -> printfn "%d" <| f()) fs
0
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Please provide an equivalent version of this Factor code in C. | USING: io kernel locals math prettyprint sequences ;
[let
10 iota [
:> i
[ i i * ]
] map :> seq
{ 3 8 } [
dup pprint " squared is " write
seq nth call .
] each
]
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Rewrite this program in C while keeping its functionality equivalent to the Factor version. | USING: io kernel locals math prettyprint sequences ;
[let
10 iota [
:> i
[ i i * ]
] map :> seq
{ 3 8 } [
dup pprint " squared is " write
seq nth call .
] each
]
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Translate the given Factor code snippet into C# without altering its behavior. | USING: io kernel locals math prettyprint sequences ;
[let
10 iota [
:> i
[ i i * ]
] map :> seq
{ 3 8 } [
dup pprint " squared is " write
seq nth call .
] each
]
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Rewrite the snippet below in C# so it works the same as the original Factor code. | USING: io kernel locals math prettyprint sequences ;
[let
10 iota [
:> i
[ i i * ]
] map :> seq
{ 3 8 } [
dup pprint " squared is " write
seq nth call .
] each
]
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Port the following code from Factor to C++ with equivalent syntax and logic. | USING: io kernel locals math prettyprint sequences ;
[let
10 iota [
:> i
[ i i * ]
] map :> seq
{ 3 8 } [
dup pprint " squared is " write
seq nth call .
] each
]
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Please provide an equivalent version of this Factor code in C++. | USING: io kernel locals math prettyprint sequences ;
[let
10 iota [
:> i
[ i i * ]
] map :> seq
{ 3 8 } [
dup pprint " squared is " write
seq nth call .
] each
]
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Generate an equivalent Java version of this Factor code. | USING: io kernel locals math prettyprint sequences ;
[let
10 iota [
:> i
[ i i * ]
] map :> seq
{ 3 8 } [
dup pprint " squared is " write
seq nth call .
] each
]
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Please provide an equivalent version of this Factor code in Java. | USING: io kernel locals math prettyprint sequences ;
[let
10 iota [
:> i
[ i i * ]
] map :> seq
{ 3 8 } [
dup pprint " squared is " write
seq nth call .
] each
]
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Translate the given Factor code snippet into Python without altering its behavior. | USING: io kernel locals math prettyprint sequences ;
[let
10 iota [
:> i
[ i i * ]
] map :> seq
{ 3 8 } [
dup pprint " squared is " write
seq nth call .
] each
]
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Convert the following code from Factor to Python, ensuring the logic remains intact. | USING: io kernel locals math prettyprint sequences ;
[let
10 iota [
:> i
[ i i * ]
] map :> seq
{ 3 8 } [
dup pprint " squared is " write
seq nth call .
] each
]
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Change the programming language of this snippet from Factor to Go without modifying what it does. | USING: io kernel locals math prettyprint sequences ;
[let
10 iota [
:> i
[ i i * ]
] map :> seq
{ 3 8 } [
dup pprint " squared is " write
seq nth call .
] each
]
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Convert the following code from Factor to Go, ensuring the logic remains intact. | USING: io kernel locals math prettyprint sequences ;
[let
10 iota [
:> i
[ i i * ]
] map :> seq
{ 3 8 } [
dup pprint " squared is " write
seq nth call .
] each
]
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Change the following Forth code into C without altering its purpose. | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute .
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Change the following Forth code into C without altering its purpose. | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute .
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Convert this Forth block to C#, preserving its control flow and logic. | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute .
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Change the following Forth code into C# without altering its purpose. | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute .
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Please provide an equivalent version of this Forth code in C++. | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute .
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Ensure the translated C++ code behaves exactly like the original Forth snippet. | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute .
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Convert the following code from Forth to Java, ensuring the logic remains intact. | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute .
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Produce a functionally identical Java code for the snippet given in Forth. | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute .
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Write the same algorithm in Python as shown in this Forth implementation. | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute .
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Write a version of this Forth function in Python with identical behavior. | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute .
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Translate this program into Go but keep the logic exactly as in Forth. | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute .
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Write the same algorithm in Go as shown in this Forth implementation. | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute .
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Change the following Groovy code into C without altering its purpose. | def closures = (0..9).collect{ i -> { -> i*i } }
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Produce a language-to-language conversion: from Groovy to C, same semantics. | def closures = (0..9).collect{ i -> { -> i*i } }
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Convert this Groovy block to C#, preserving its control flow and logic. | def closures = (0..9).collect{ i -> { -> i*i } }
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Convert this Groovy block to C#, preserving its control flow and logic. | def closures = (0..9).collect{ i -> { -> i*i } }
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Write the same code in C++ as shown below in Groovy. | def closures = (0..9).collect{ i -> { -> i*i } }
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Preserve the algorithm and functionality while converting the code from Groovy to C++. | def closures = (0..9).collect{ i -> { -> i*i } }
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Produce a functionally identical Java code for the snippet given in Groovy. | def closures = (0..9).collect{ i -> { -> i*i } }
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Generate a Java translation of this Groovy snippet without changing its computational steps. | def closures = (0..9).collect{ i -> { -> i*i } }
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Port the following code from Groovy to Python with equivalent syntax and logic. | def closures = (0..9).collect{ i -> { -> i*i } }
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Transform the following Groovy implementation into Python, maintaining the same output and logic. | def closures = (0..9).collect{ i -> { -> i*i } }
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Maintain the same structure and functionality when rewriting this code in Go. | def closures = (0..9).collect{ i -> { -> i*i } }
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Convert the following code from Groovy to Go, ensuring the logic remains intact. | def closures = (0..9).collect{ i -> { -> i*i } }
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Change the following Haskell code into C without altering its purpose. | fs = map (\i _ -> i * i) [1 .. 10]
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Port the following code from Haskell to C with equivalent syntax and logic. | fs = map (\i _ -> i * i) [1 .. 10]
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Maintain the same structure and functionality when rewriting this code in C#. | fs = map (\i _ -> i * i) [1 .. 10]
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Rewrite this program in C# while keeping its functionality equivalent to the Haskell version. | fs = map (\i _ -> i * i) [1 .. 10]
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Write the same code in C++ as shown below in Haskell. | fs = map (\i _ -> i * i) [1 .. 10]
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Ensure the translated C++ code behaves exactly like the original Haskell snippet. | fs = map (\i _ -> i * i) [1 .. 10]
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Convert this Haskell snippet to Java and keep its semantics consistent. | fs = map (\i _ -> i * i) [1 .. 10]
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Ensure the translated Java code behaves exactly like the original Haskell snippet. | fs = map (\i _ -> i * i) [1 .. 10]
| import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
System.out.println(foo.get());
}
}
|
Change the following Haskell code into Python without altering its purpose. | fs = map (\i _ -> i * i) [1 .. 10]
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Translate this program into Python but keep the logic exactly as in Haskell. | fs = map (\i _ -> i * i) [1 .. 10]
| funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]()
|
Keep all operations the same but rewrite the snippet in Go. | fs = map (\i _ -> i * i) [1 .. 10]
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Preserve the algorithm and functionality while converting the code from Haskell to Go. | fs = map (\i _ -> i * i) [1 .. 10]
| package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}
|
Translate the given J code snippet into C without altering its behavior. | constF=:3 :0
{.''`(y "_)
)
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Preserve the algorithm and functionality while converting the code from J to C. | constF=:3 :0
{.''`(y "_)
)
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*f_int)();
#define TAG 0xdeadbeef
int _tmpl() {
volatile int x = TAG;
return x * x;
}
#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
f_int dupf(int v)
{
size_t len = (void*)dupf - (void*)_tmpl;
f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
char *p;
if(ret == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ret, _tmpl, len);
for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
if (*(int *)p == TAG) *(int *)p = v;
return ret;
}
int main()
{
f_int funcs[10];
int i;
for (i = 0; i < 10; i++) funcs[i] = dupf(i);
for (i = 0; i < 9; i++)
printf("func[%d]: %d\n", i, funcs[i]());
return 0;
}
|
Keep all operations the same but rewrite the snippet in C#. | constF=:3 :0
{.''`(y "_)
)
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Write the same code in C# as shown below in J. | constF=:3 :0
{.''`(y "_)
)
| using System;
using System.Linq;
class Program
{
static void Main()
{
var captor = (Func<int, Func<int>>)(number => () => number * number);
var functions = Enumerable.Range(0, 10).Select(captor);
foreach (var function in functions.Take(9))
{
Console.WriteLine(function());
}
}
}
|
Keep all operations the same but rewrite the snippet in C++. | constF=:3 :0
{.''`(y "_)
)
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Translate the given J code snippet into C++ without altering its behavior. | constF=:3 :0
{.''`(y "_)
)
| #include <iostream>
#include <functional>
#include <vector>
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
for ( std::function<int( )> f : funcs )
std::cout << f( ) << std::endl ;
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.