Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Keep all operations the same but rewrite the snippet in PHP. | print defined($x) ? 'Defined' : 'Undefined', ".\n";
| $x = NULL;
if (is_null($x))
echo "\$x is null\n";
|
Generate an equivalent PHP version of this PowerShell code. | if ($null -eq $object) {
...
}
| $x = NULL;
if (is_null($x))
echo "\$x is null\n";
|
Preserve the algorithm and functionality while converting the code from R to PHP. | is.null(NULL)
is.null(123)
is.null(NA)
123==NULL
foo <- function(){}
foo()
| $x = NULL;
if (is_null($x))
echo "\$x is null\n";
|
Write the same algorithm in PHP as shown in this Racket implementation. | -> null
'()
-> (null? null)
#t
-> (null? 3)
#f
| $x = NULL;
if (is_null($x))
echo "\$x is null\n";
|
Port the provided COBOL code into PHP while preserving the original functionality. | identification division.
program-id. null-objects.
remarks. test with cobc -x -j null-objects.cob
data division.
working-storage section.
01 thing-not-thing usage pointer.
procedure division.
call "test-null" using thing-n... | $x = NULL;
if (is_null($x))
echo "\$x is null\n";
|
Please provide an equivalent version of this REXX code in PHP. |
options replace format comments java crossref symbols binary
robject = Rexx -- create an object for which the value is undefined
say String.valueOf(robject) -- will report the text "null"
if robject = null then say 'Really, it''s "null"!'
| $x = NULL;
if (is_null($x))
echo "\$x is null\n";
|
Preserve the algorithm and functionality while converting the code from Ruby to PHP. | puts "@object is nil" if @object.nil?
puts "$object is nil" if $object.nil?
object = 1 if false
puts "object is nil" if object.nil?
puts nil.class
| $x = NULL;
if (is_null($x))
echo "\$x is null\n";
|
Convert the following code from Scala to PHP, ensuring the logic remains intact. |
fun main(args: Array<String>) {
val i: Int = 3
println(i)
val j: Int? = null
println(j)
println(null is Nothing?)
}
| $x = NULL;
if (is_null($x))
echo "\$x is null\n";
|
Write a version of this C function in Rust with identical behavior. | #include <stdio.h>
int main()
{
char *object = 0;
if (object == NULL) {
puts("object is null");
}
return 0;
}
|
fn check_number(num: &Option<u8>) {
if num.is_none() {
println!("Number is: None");
} else {
println!("Number is: {}", num.unwrap());
}
}
fn main() {
let mut possible_number: Option<u8> = None;
check_number(&possible_number);
possible_number = Some(31);
check_number(&p... |
Convert this C# snippet to Rust and keep its semantics consistent. | if (foo == null)
Console.WriteLine("foo is null");
|
fn check_number(num: &Option<u8>) {
if num.is_none() {
println!("Number is: None");
} else {
println!("Number is: {}", num.unwrap());
}
}
fn main() {
let mut possible_number: Option<u8> = None;
check_number(&possible_number);
possible_number = Some(31);
check_number(&p... |
Change the following Java code into Rust without altering its purpose. | module NullObject
{
void run()
{
@Inject Console console;
console.print($"Null value={Null}, Null.toString()={Null.toString()}");
String? s = Null;
String s2 = "test";
console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");
Int len = s?.siz... |
fn check_number(num: &Option<u8>) {
if num.is_none() {
println!("Number is: None");
} else {
println!("Number is: {}", num.unwrap());
}
}
fn main() {
let mut possible_number: Option<u8> = None;
check_number(&possible_number);
possible_number = Some(31);
check_number(&p... |
Keep all operations the same but rewrite the snippet in Rust. | package main
import "fmt"
var (
s []int
p *int
f func()
i interface{}
m map[int]int
c chan int
)
func main() {
fmt.Println(s == nil)
fmt.Println(p == nil)
fmt.Println(f == nil)
fmt.Println(i == nil)
fmt.Println(m == nil)
fmt.Println(c == nil)... |
fn check_number(num: &Option<u8>) {
if num.is_none() {
println!("Number is: None");
} else {
println!("Number is: {}", num.unwrap());
}
}
fn main() {
let mut possible_number: Option<u8> = None;
check_number(&possible_number);
possible_number = Some(31);
check_number(&p... |
Write the same algorithm in Python as shown in this Rust implementation. |
fn check_number(num: &Option<u8>) {
if num.is_none() {
println!("Number is: None");
} else {
println!("Number is: {}", num.unwrap());
}
}
fn main() {
let mut possible_number: Option<u8> = None;
check_number(&possible_number);
possible_number = Some(31);
check_number(&p... | x = None
if x is None:
print "x is None"
else:
print "x is not None"
|
Can you help me rewrite this code in Rust instead of C++, keeping it the same logically? | #include <iostream>
#include <cstdlib>
if (object == 0) {
std::cout << "object is null";
}
|
fn check_number(num: &Option<u8>) {
if num.is_none() {
println!("Number is: None");
} else {
println!("Number is: {}", num.unwrap());
}
}
fn main() {
let mut possible_number: Option<u8> = None;
check_number(&possible_number);
possible_number = Some(31);
check_number(&p... |
Transform the following Rust implementation into VB, maintaining the same output and logic. |
fn check_number(num: &Option<u8>) {
if num.is_none() {
println!("Number is: None");
} else {
println!("Number is: {}", num.unwrap());
}
}
fn main() {
let mut possible_number: Option<u8> = None;
check_number(&possible_number);
possible_number = Some(31);
check_number(&p... | Public Sub Main()
Dim c As VBA.Collection
Debug.Print c Is Nothing
Set c = New VBA.Collection
Debug.Print Not c Is Nothing
Set c = Nothing
Debug.Print c Is Nothing
End Sub
|
Produce a functionally identical C# code for the snippet given in Ada. | with Ada.Containers.Vectors;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Sockets; use Sockets;
procedure Chat_Server is
package Client_Vectors is new Ada.Containe... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Generate a C translation of this Ada snippet without changing its computational steps. | with Ada.Containers.Vectors;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Sockets; use Sockets;
procedure Chat_Server is
package Client_Vectors is new Ada.Containe... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Port the following code from Ada to Go with equivalent syntax and logic. | with Ada.Containers.Vectors;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Sockets; use Sockets;
procedure Chat_Server is
package Client_Vectors is new Ada.Containe... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Preserve the algorithm and functionality while converting the code from Ada to Java. | with Ada.Containers.Vectors;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Sockets; use Sockets;
procedure Chat_Server is
package Client_Vectors is new Ada.Containe... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Write the same algorithm in Python as shown in this Ada implementation. | with Ada.Containers.Vectors;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Sockets; use Sockets;
procedure Chat_Server is
package Client_Vectors is new Ada.Containe... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Write a version of this Ada function in VB with identical behavior. | with Ada.Containers.Vectors;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Sockets; use Sockets;
procedure Chat_Server is
package Client_Vectors is new Ada.Containe... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Produce a language-to-language conversion: from D to C, same semantics. | import std.getopt;
import std.socket;
import std.stdio;
import std.string;
struct client {
int pos;
char[] name;
char[] buffer;
Socket socket;
}
void broadcast(client[] connections, size_t self, const char[] message) {
writeln(message);
for (size_t i = 0; i < connections.length; i++) {
... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Preserve the algorithm and functionality while converting the code from D to C#. | import std.getopt;
import std.socket;
import std.stdio;
import std.string;
struct client {
int pos;
char[] name;
char[] buffer;
Socket socket;
}
void broadcast(client[] connections, size_t self, const char[] message) {
writeln(message);
for (size_t i = 0; i < connections.length; i++) {
... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Change the following D code into Java without altering its purpose. | import std.getopt;
import std.socket;
import std.stdio;
import std.string;
struct client {
int pos;
char[] name;
char[] buffer;
Socket socket;
}
void broadcast(client[] connections, size_t self, const char[] message) {
writeln(message);
for (size_t i = 0; i < connections.length; i++) {
... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Ensure the translated Python code behaves exactly like the original D snippet. | import std.getopt;
import std.socket;
import std.stdio;
import std.string;
struct client {
int pos;
char[] name;
char[] buffer;
Socket socket;
}
void broadcast(client[] connections, size_t self, const char[] message) {
writeln(message);
for (size_t i = 0; i < connections.length; i++) {
... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Maintain the same structure and functionality when rewriting this code in VB. | import std.getopt;
import std.socket;
import std.stdio;
import std.string;
struct client {
int pos;
char[] name;
char[] buffer;
Socket socket;
}
void broadcast(client[] connections, size_t self, const char[] message) {
writeln(message);
for (size_t i = 0; i < connections.length; i++) {
... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Convert this D snippet to Go and keep its semantics consistent. | import std.getopt;
import std.socket;
import std.stdio;
import std.string;
struct client {
int pos;
char[] name;
char[] buffer;
Socket socket;
}
void broadcast(client[] connections, size_t self, const char[] message) {
writeln(message);
for (size_t i = 0; i < connections.length; i++) {
... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Change the following Erlang code into C without altering its purpose. | -module(chat).
-export([start/0, start/1]).
-record(client, {name=none, socket=none}).
start() -> start(8080).
start(Port) ->
register(server, spawn(fun() -> server() end)),
{ok, LSocket} = gen_tcp:listen(Port, [binary, {packet, 0}, {active, false}, {reuseaddr, true}]),
accept(LSocket).
server() -> ser... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Keep all operations the same but rewrite the snippet in C#. | -module(chat).
-export([start/0, start/1]).
-record(client, {name=none, socket=none}).
start() -> start(8080).
start(Port) ->
register(server, spawn(fun() -> server() end)),
{ok, LSocket} = gen_tcp:listen(Port, [binary, {packet, 0}, {active, false}, {reuseaddr, true}]),
accept(LSocket).
server() -> ser... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Maintain the same structure and functionality when rewriting this code in Java. | -module(chat).
-export([start/0, start/1]).
-record(client, {name=none, socket=none}).
start() -> start(8080).
start(Port) ->
register(server, spawn(fun() -> server() end)),
{ok, LSocket} = gen_tcp:listen(Port, [binary, {packet, 0}, {active, false}, {reuseaddr, true}]),
accept(LSocket).
server() -> ser... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Produce a language-to-language conversion: from Erlang to Python, same semantics. | -module(chat).
-export([start/0, start/1]).
-record(client, {name=none, socket=none}).
start() -> start(8080).
start(Port) ->
register(server, spawn(fun() -> server() end)),
{ok, LSocket} = gen_tcp:listen(Port, [binary, {packet, 0}, {active, false}, {reuseaddr, true}]),
accept(LSocket).
server() -> ser... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Please provide an equivalent version of this Erlang code in VB. | -module(chat).
-export([start/0, start/1]).
-record(client, {name=none, socket=none}).
start() -> start(8080).
start(Port) ->
register(server, spawn(fun() -> server() end)),
{ok, LSocket} = gen_tcp:listen(Port, [binary, {packet, 0}, {active, false}, {reuseaddr, true}]),
accept(LSocket).
server() -> ser... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Convert the following code from Erlang to Go, ensuring the logic remains intact. | -module(chat).
-export([start/0, start/1]).
-record(client, {name=none, socket=none}).
start() -> start(8080).
start(Port) ->
register(server, spawn(fun() -> server() end)),
{ok, LSocket} = gen_tcp:listen(Port, [binary, {packet, 0}, {active, false}, {reuseaddr, true}]),
accept(LSocket).
server() -> ser... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Port the provided Groovy code into C while preserving the original functionality. | class ChatServer implements Runnable {
private int port = 0
private List<Client> clientList = new ArrayList<>()
ChatServer(int port) {
this.port = port
}
@SuppressWarnings("GroovyInfiniteLoopStatement")
@Override
void run() {
try {
ServerSocket serverSocket = ne... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Convert this Groovy block to C#, preserving its control flow and logic. | class ChatServer implements Runnable {
private int port = 0
private List<Client> clientList = new ArrayList<>()
ChatServer(int port) {
this.port = port
}
@SuppressWarnings("GroovyInfiniteLoopStatement")
@Override
void run() {
try {
ServerSocket serverSocket = ne... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Ensure the translated Java code behaves exactly like the original Groovy snippet. | class ChatServer implements Runnable {
private int port = 0
private List<Client> clientList = new ArrayList<>()
ChatServer(int port) {
this.port = port
}
@SuppressWarnings("GroovyInfiniteLoopStatement")
@Override
void run() {
try {
ServerSocket serverSocket = ne... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Convert this Groovy block to Python, preserving its control flow and logic. | class ChatServer implements Runnable {
private int port = 0
private List<Client> clientList = new ArrayList<>()
ChatServer(int port) {
this.port = port
}
@SuppressWarnings("GroovyInfiniteLoopStatement")
@Override
void run() {
try {
ServerSocket serverSocket = ne... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Please provide an equivalent version of this Groovy code in VB. | class ChatServer implements Runnable {
private int port = 0
private List<Client> clientList = new ArrayList<>()
ChatServer(int port) {
this.port = port
}
@SuppressWarnings("GroovyInfiniteLoopStatement")
@Override
void run() {
try {
ServerSocket serverSocket = ne... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Produce a language-to-language conversion: from Groovy to Go, same semantics. | class ChatServer implements Runnable {
private int port = 0
private List<Client> clientList = new ArrayList<>()
ChatServer(int port) {
this.port = port
}
@SuppressWarnings("GroovyInfiniteLoopStatement")
@Override
void run() {
try {
ServerSocket serverSocket = ne... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Convert this Haskell block to C, preserving its control flow and logic. |
import Network
import System.IO
import Control.Concurrent
import qualified Data.Text as T
import Data.Text (Text)
import qualified Data.Text.IO as T
import qualified Data.Map as M
import Data.Map (Map)
import Control.Monad.Reader
import Control.Monad.Error
import Control.Exception
import Data.Monoid
import Control.Ap... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Transform the following Haskell implementation into C#, maintaining the same output and logic. |
import Network
import System.IO
import Control.Concurrent
import qualified Data.Text as T
import Data.Text (Text)
import qualified Data.Text.IO as T
import qualified Data.Map as M
import Data.Map (Map)
import Control.Monad.Reader
import Control.Monad.Error
import Control.Exception
import Data.Monoid
import Control.Ap... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Convert this Haskell block to Java, preserving its control flow and logic. |
import Network
import System.IO
import Control.Concurrent
import qualified Data.Text as T
import Data.Text (Text)
import qualified Data.Text.IO as T
import qualified Data.Map as M
import Data.Map (Map)
import Control.Monad.Reader
import Control.Monad.Error
import Control.Exception
import Data.Monoid
import Control.Ap... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Port the provided Haskell code into Python while preserving the original functionality. |
import Network
import System.IO
import Control.Concurrent
import qualified Data.Text as T
import Data.Text (Text)
import qualified Data.Text.IO as T
import qualified Data.Map as M
import Data.Map (Map)
import Control.Monad.Reader
import Control.Monad.Error
import Control.Exception
import Data.Monoid
import Control.Ap... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Port the following code from Haskell to VB with equivalent syntax and logic. |
import Network
import System.IO
import Control.Concurrent
import qualified Data.Text as T
import Data.Text (Text)
import qualified Data.Text.IO as T
import qualified Data.Map as M
import Data.Map (Map)
import Control.Monad.Reader
import Control.Monad.Error
import Control.Exception
import Data.Monoid
import Control.Ap... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Write the same code in Go as shown below in Haskell. |
import Network
import System.IO
import Control.Concurrent
import qualified Data.Text as T
import Data.Text (Text)
import qualified Data.Text.IO as T
import qualified Data.Map as M
import Data.Map (Map)
import Control.Monad.Reader
import Control.Monad.Error
import Control.Exception
import Data.Monoid
import Control.Ap... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Change the programming language of this snippet from Julia to C without modifying what it does. | using HttpServer
using WebSockets
const connections = Dict{Int,WebSocket}()
const usernames = Dict{Int,String}()
function decodeMessage( msg )
String(copy(msg))
end
wsh = WebSocketHandler() do req, client
global connections
@show connections[client.id] = client
println("req is $req")
notifyonl... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Maintain the same structure and functionality when rewriting this code in C#. | using HttpServer
using WebSockets
const connections = Dict{Int,WebSocket}()
const usernames = Dict{Int,String}()
function decodeMessage( msg )
String(copy(msg))
end
wsh = WebSocketHandler() do req, client
global connections
@show connections[client.id] = client
println("req is $req")
notifyonl... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Change the programming language of this snippet from Julia to Java without modifying what it does. | using HttpServer
using WebSockets
const connections = Dict{Int,WebSocket}()
const usernames = Dict{Int,String}()
function decodeMessage( msg )
String(copy(msg))
end
wsh = WebSocketHandler() do req, client
global connections
@show connections[client.id] = client
println("req is $req")
notifyonl... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Convert this Julia block to Python, preserving its control flow and logic. | using HttpServer
using WebSockets
const connections = Dict{Int,WebSocket}()
const usernames = Dict{Int,String}()
function decodeMessage( msg )
String(copy(msg))
end
wsh = WebSocketHandler() do req, client
global connections
@show connections[client.id] = client
println("req is $req")
notifyonl... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Ensure the translated VB code behaves exactly like the original Julia snippet. | using HttpServer
using WebSockets
const connections = Dict{Int,WebSocket}()
const usernames = Dict{Int,String}()
function decodeMessage( msg )
String(copy(msg))
end
wsh = WebSocketHandler() do req, client
global connections
@show connections[client.id] = client
println("req is $req")
notifyonl... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Generate a Go translation of this Julia snippet without changing its computational steps. | using HttpServer
using WebSockets
const connections = Dict{Int,WebSocket}()
const usernames = Dict{Int,String}()
function decodeMessage( msg )
String(copy(msg))
end
wsh = WebSocketHandler() do req, client
global connections
@show connections[client.id] = client
println("req is $req")
notifyonl... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Port the provided Nim code into C while preserving the original functionality. | import asyncnet, asyncdispatch
type
Client = tuple
socket: AsyncSocket
name: string
connected: bool
var clients {.threadvar.}: seq[Client]
proc sendOthers(client: Client, line: string) {.async.} =
for c in clients:
if c != client and c.connected:
await c.socket.send(line & "\c\L")
proc pro... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Ensure the translated C# code behaves exactly like the original Nim snippet. | import asyncnet, asyncdispatch
type
Client = tuple
socket: AsyncSocket
name: string
connected: bool
var clients {.threadvar.}: seq[Client]
proc sendOthers(client: Client, line: string) {.async.} =
for c in clients:
if c != client and c.connected:
await c.socket.send(line & "\c\L")
proc pro... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Write the same algorithm in Java as shown in this Nim implementation. | import asyncnet, asyncdispatch
type
Client = tuple
socket: AsyncSocket
name: string
connected: bool
var clients {.threadvar.}: seq[Client]
proc sendOthers(client: Client, line: string) {.async.} =
for c in clients:
if c != client and c.connected:
await c.socket.send(line & "\c\L")
proc pro... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Write the same code in Python as shown below in Nim. | import asyncnet, asyncdispatch
type
Client = tuple
socket: AsyncSocket
name: string
connected: bool
var clients {.threadvar.}: seq[Client]
proc sendOthers(client: Client, line: string) {.async.} =
for c in clients:
if c != client and c.connected:
await c.socket.send(line & "\c\L")
proc pro... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Please provide an equivalent version of this Nim code in VB. | import asyncnet, asyncdispatch
type
Client = tuple
socket: AsyncSocket
name: string
connected: bool
var clients {.threadvar.}: seq[Client]
proc sendOthers(client: Client, line: string) {.async.} =
for c in clients:
if c != client and c.connected:
await c.socket.send(line & "\c\L")
proc pro... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Translate this program into Go but keep the logic exactly as in Nim. | import asyncnet, asyncdispatch
type
Client = tuple
socket: AsyncSocket
name: string
connected: bool
var clients {.threadvar.}: seq[Client]
proc sendOthers(client: Client, line: string) {.async.} =
for c in clients:
if c != client and c.connected:
await c.socket.send(line & "\c\L")
proc pro... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Rewrite this program in C while keeping its functionality equivalent to the Perl version. | use 5.010;
use strict;
use warnings;
use threads;
use threads::shared;
use IO::Socket::INET;
use Time::HiRes qw(sleep ualarm);
my $HOST = "localhost";
my $PORT = 4004;
my @open;
my %users : shared;
sub broadcast {
my ($id, $message) = @_;
print "$message\n";
foreach my $i (keys %users) {
if ($i... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Port the following code from Perl to C# with equivalent syntax and logic. | use 5.010;
use strict;
use warnings;
use threads;
use threads::shared;
use IO::Socket::INET;
use Time::HiRes qw(sleep ualarm);
my $HOST = "localhost";
my $PORT = 4004;
my @open;
my %users : shared;
sub broadcast {
my ($id, $message) = @_;
print "$message\n";
foreach my $i (keys %users) {
if ($i... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Rewrite the snippet below in Java so it works the same as the original Perl code. | use 5.010;
use strict;
use warnings;
use threads;
use threads::shared;
use IO::Socket::INET;
use Time::HiRes qw(sleep ualarm);
my $HOST = "localhost";
my $PORT = 4004;
my @open;
my %users : shared;
sub broadcast {
my ($id, $message) = @_;
print "$message\n";
foreach my $i (keys %users) {
if ($i... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Ensure the translated Python code behaves exactly like the original Perl snippet. | use 5.010;
use strict;
use warnings;
use threads;
use threads::shared;
use IO::Socket::INET;
use Time::HiRes qw(sleep ualarm);
my $HOST = "localhost";
my $PORT = 4004;
my @open;
my %users : shared;
sub broadcast {
my ($id, $message) = @_;
print "$message\n";
foreach my $i (keys %users) {
if ($i... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Rewrite the snippet below in VB so it works the same as the original Perl code. | use 5.010;
use strict;
use warnings;
use threads;
use threads::shared;
use IO::Socket::INET;
use Time::HiRes qw(sleep ualarm);
my $HOST = "localhost";
my $PORT = 4004;
my @open;
my %users : shared;
sub broadcast {
my ($id, $message) = @_;
print "$message\n";
foreach my $i (keys %users) {
if ($i... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Write a version of this Perl function in Go with identical behavior. | use 5.010;
use strict;
use warnings;
use threads;
use threads::shared;
use IO::Socket::INET;
use Time::HiRes qw(sleep ualarm);
my $HOST = "localhost";
my $PORT = 4004;
my @open;
my %users : shared;
sub broadcast {
my ($id, $message) = @_;
print "$message\n";
foreach my $i (keys %users) {
if ($i... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Rewrite the snippet below in C so it works the same as the original R code. | chat_loop <- function(server, sockets, delay = 0.5) {
repeat {
Sys.sleep(delay)
while (in_queue(server))
sockets <- new_socket_entry(server, sockets)
sockets <- check_messages(sockets)
if (nrow(sockets) == 0)
next
... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Keep all operations the same but rewrite the snippet in C#. | chat_loop <- function(server, sockets, delay = 0.5) {
repeat {
Sys.sleep(delay)
while (in_queue(server))
sockets <- new_socket_entry(server, sockets)
sockets <- check_messages(sockets)
if (nrow(sockets) == 0)
next
... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Maintain the same structure and functionality when rewriting this code in Java. | chat_loop <- function(server, sockets, delay = 0.5) {
repeat {
Sys.sleep(delay)
while (in_queue(server))
sockets <- new_socket_entry(server, sockets)
sockets <- check_messages(sockets)
if (nrow(sockets) == 0)
next
... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Produce a language-to-language conversion: from R to Python, same semantics. | chat_loop <- function(server, sockets, delay = 0.5) {
repeat {
Sys.sleep(delay)
while (in_queue(server))
sockets <- new_socket_entry(server, sockets)
sockets <- check_messages(sockets)
if (nrow(sockets) == 0)
next
... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Port the provided R code into VB while preserving the original functionality. | chat_loop <- function(server, sockets, delay = 0.5) {
repeat {
Sys.sleep(delay)
while (in_queue(server))
sockets <- new_socket_entry(server, sockets)
sockets <- check_messages(sockets)
if (nrow(sockets) == 0)
next
... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Preserve the algorithm and functionality while converting the code from R to Go. | chat_loop <- function(server, sockets, delay = 0.5) {
repeat {
Sys.sleep(delay)
while (in_queue(server))
sockets <- new_socket_entry(server, sockets)
sockets <- check_messages(sockets)
if (nrow(sockets) == 0)
next
... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Rewrite this program in C while keeping its functionality equivalent to the Racket version. | #lang racket
(define outs (list (current-output-port)))
(define ((tell-all who o) line)
(for ([c outs] #:unless (eq? o c)) (displayln (~a who ": " line) c)))
(define ((client i o))
(define nick (begin (display "Nick: " o) (read-line i)))
(define tell (tell-all nick o))
(let loop ([line "(joined)"])
(if (e... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Generate an equivalent C# version of this Racket code. | #lang racket
(define outs (list (current-output-port)))
(define ((tell-all who o) line)
(for ([c outs] #:unless (eq? o c)) (displayln (~a who ": " line) c)))
(define ((client i o))
(define nick (begin (display "Nick: " o) (read-line i)))
(define tell (tell-all nick o))
(let loop ([line "(joined)"])
(if (e... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Change the following Racket code into Java without altering its purpose. | #lang racket
(define outs (list (current-output-port)))
(define ((tell-all who o) line)
(for ([c outs] #:unless (eq? o c)) (displayln (~a who ": " line) c)))
(define ((client i o))
(define nick (begin (display "Nick: " o) (read-line i)))
(define tell (tell-all nick o))
(let loop ([line "(joined)"])
(if (e... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Produce a language-to-language conversion: from Racket to Python, same semantics. | #lang racket
(define outs (list (current-output-port)))
(define ((tell-all who o) line)
(for ([c outs] #:unless (eq? o c)) (displayln (~a who ": " line) c)))
(define ((client i o))
(define nick (begin (display "Nick: " o) (read-line i)))
(define tell (tell-all nick o))
(let loop ([line "(joined)"])
(if (e... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Translate this program into VB but keep the logic exactly as in Racket. | #lang racket
(define outs (list (current-output-port)))
(define ((tell-all who o) line)
(for ([c outs] #:unless (eq? o c)) (displayln (~a who ": " line) c)))
(define ((client i o))
(define nick (begin (display "Nick: " o) (read-line i)))
(define tell (tell-all nick o))
(let loop ([line "(joined)"])
(if (e... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Translate this program into Go but keep the logic exactly as in Racket. | #lang racket
(define outs (list (current-output-port)))
(define ((tell-all who o) line)
(for ([c outs] #:unless (eq? o c)) (displayln (~a who ": " line) c)))
(define ((client i o))
(define nick (begin (display "Nick: " o) (read-line i)))
(define tell (tell-all nick o))
(let loop ([line "(joined)"])
(if (e... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Change the following Ruby code into C without altering its purpose. | require 'gserver'
class ChatServer < GServer
def initialize *args
super
@chatters = []
@mutex = Mutex.new
end
def broadcast message, sender = nil
message = message.strip << "\r\n"
@mutex.synchronize do
@chatters.each do |chatter|
begin
chatt... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Write a version of this Ruby function in C# with identical behavior. | require 'gserver'
class ChatServer < GServer
def initialize *args
super
@chatters = []
@mutex = Mutex.new
end
def broadcast message, sender = nil
message = message.strip << "\r\n"
@mutex.synchronize do
@chatters.each do |chatter|
begin
chatt... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Convert this Ruby snippet to Java and keep its semantics consistent. | require 'gserver'
class ChatServer < GServer
def initialize *args
super
@chatters = []
@mutex = Mutex.new
end
def broadcast message, sender = nil
message = message.strip << "\r\n"
@mutex.synchronize do
@chatters.each do |chatter|
begin
chatt... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Translate this program into Python but keep the logic exactly as in Ruby. | require 'gserver'
class ChatServer < GServer
def initialize *args
super
@chatters = []
@mutex = Mutex.new
end
def broadcast message, sender = nil
message = message.strip << "\r\n"
@mutex.synchronize do
@chatters.each do |chatter|
begin
chatt... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Translate the given Ruby code snippet into VB without altering its behavior. | require 'gserver'
class ChatServer < GServer
def initialize *args
super
@chatters = []
@mutex = Mutex.new
end
def broadcast message, sender = nil
message = message.strip << "\r\n"
@mutex.synchronize do
@chatters.each do |chatter|
begin
chatt... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Produce a functionally identical Go code for the snippet given in Ruby. | require 'gserver'
class ChatServer < GServer
def initialize *args
super
@chatters = []
@mutex = Mutex.new
end
def broadcast message, sender = nil
message = message.strip << "\r\n"
@mutex.synchronize do
@chatters.each do |chatter|
begin
chatt... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Rewrite this program in C while keeping its functionality equivalent to the Scala version. | import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.Writer
import java.net.ServerSocket
import java.net.Socket
import java.util.ArrayList
import java.util.Collections
class ChatServer private constructor(private val port: Int) : Run... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Ensure the translated C# code behaves exactly like the original Scala snippet. | import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.Writer
import java.net.ServerSocket
import java.net.Socket
import java.util.ArrayList
import java.util.Collections
class ChatServer private constructor(private val port: Int) : Run... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Can you help me rewrite this code in Java instead of Scala, keeping it the same logically? | import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.Writer
import java.net.ServerSocket
import java.net.Socket
import java.util.ArrayList
import java.util.Collections
class ChatServer private constructor(private val port: Int) : Run... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Generate a Python translation of this Scala snippet without changing its computational steps. | import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.Writer
import java.net.ServerSocket
import java.net.Socket
import java.util.ArrayList
import java.util.Collections
class ChatServer private constructor(private val port: Int) : Run... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Can you help me rewrite this code in VB instead of Scala, keeping it the same logically? | import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.Writer
import java.net.ServerSocket
import java.net.Socket
import java.util.ArrayList
import java.util.Collections
class ChatServer private constructor(private val port: Int) : Run... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Translate the given Scala code snippet into Go without altering its behavior. | import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.Writer
import java.net.ServerSocket
import java.net.Socket
import java.util.ArrayList
import java.util.Collections
class ChatServer private constructor(private val port: Int) : Run... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Write the same code in C as shown below in Tcl. | package require Tcl 8.6
proc writeEveryoneElse {sender message} {
dict for {who ch} $::cmap {
if {$who ne $sender} {
puts $ch $message
}
}
}
proc cgets {ch var} {
upvar 1 $var v
while {[gets $ch v] < 0} {
if {[eof $ch] || [chan pending input $ch] > 256} {
return false
}
yield
}
... | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... |
Translate the given Tcl code snippet into C# without altering its behavior. | package require Tcl 8.6
proc writeEveryoneElse {sender message} {
dict for {who ch} $::cmap {
if {$who ne $sender} {
puts $ch $message
}
}
}
proc cgets {ch var} {
upvar 1 $var v
while {[gets $ch v] < 0} {
if {[eof $ch] || [chan pending input $ch] > 256} {
return false
}
yield
}
... | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... |
Change the programming language of this snippet from Tcl to Java without modifying what it does. | package require Tcl 8.6
proc writeEveryoneElse {sender message} {
dict for {who ch} $::cmap {
if {$who ne $sender} {
puts $ch $message
}
}
}
proc cgets {ch var} {
upvar 1 $var v
while {[gets $ch v] < 0} {
if {[eof $ch] || [chan pending input $ch] > 256} {
return false
}
yield
}
... | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... |
Translate this program into Python but keep the logic exactly as in Tcl. | package require Tcl 8.6
proc writeEveryoneElse {sender message} {
dict for {who ch} $::cmap {
if {$who ne $sender} {
puts $ch $message
}
}
}
proc cgets {ch var} {
upvar 1 $var v
while {[gets $ch v] < 0} {
if {[eof $ch] || [chan pending input $ch] > 256} {
return false
}
yield
}
... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Port the following code from Tcl to VB with equivalent syntax and logic. | package require Tcl 8.6
proc writeEveryoneElse {sender message} {
dict for {who ch} $::cmap {
if {$who ne $sender} {
puts $ch $message
}
}
}
proc cgets {ch var} {
upvar 1 $var v
while {[gets $ch v] < 0} {
if {[eof $ch] || [chan pending input $ch] > 256} {
return false
}
yield
}
... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Produce a functionally identical Go code for the snippet given in Tcl. | package require Tcl 8.6
proc writeEveryoneElse {sender message} {
dict for {who ch} $::cmap {
if {$who ne $sender} {
puts $ch $message
}
}
}
proc cgets {ch var} {
upvar 1 $var v
while {[gets $ch v] < 0} {
if {[eof $ch] || [chan pending input $ch] > 256} {
return false
}
yield
}
... | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... |
Generate a Rust translation of this C snippet without changing its computational steps. | #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char na... | use std::collections::HashMap;
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::net::{TcpListener, TcpStream};
use std::sync::{Arc, RwLock};
use std::thread;
type Username = String;
fn broadcast_message(
user: &str,
clients: &mut HashMap<String, TcpStream>,
message: &str,
) -> io::R... |
Write a version of this C# function in Rust with identical behavior. | using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace ChatServer {
class State {
private TcpClient client;
private StringBuilder sb = new StringBuilder();
public string Name { get; }
public State(string name,... | use std::collections::HashMap;
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::net::{TcpListener, TcpStream};
use std::sync::{Arc, RwLock};
use std::thread;
type Username = String;
fn broadcast_message(
user: &str,
clients: &mut HashMap<String, TcpStream>,
message: &str,
) -> io::R... |
Write a version of this Go function in Rust with identical behavior. | package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"strings"
"time"
)
func main() {
log.SetPrefix("chat: ")
addr := flag.String("addr", "localhost:4000", "listen address")
flag.Parse()
log.Fatal(ListenAndServe(*addr))
}
type Server struct {
add chan *conn
rem chan string
msg chan string
st... | use std::collections::HashMap;
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::net::{TcpListener, TcpStream};
use std::sync::{Arc, RwLock};
use std::thread;
type Username = String;
fn broadcast_message(
user: &str,
clients: &mut HashMap<String, TcpStream>,
message: &str,
) -> io::R... |
Write the same algorithm in Python as shown in this Rust implementation. | use std::collections::HashMap;
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::net::{TcpListener, TcpStream};
use std::sync::{Arc, RwLock};
use std::thread;
type Username = String;
fn broadcast_message(
user: &str,
clients: &mut HashMap<String, TcpStream>,
message: &str,
) -> io::R... |
import socket
import thread
import time
HOST = ""
PORT = 4004
def accept(conn):
def threaded():
while True:
conn.send("Please enter your name: ")
try:
name = conn.recv(1024).strip()
except socket.error:
continue
if name... |
Rewrite the snippet below in Rust so it works the same as the original Java code. | import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer implements Runnable
{
private int port = 0;
private List<Client> clients = new ArrayList<Client>();
public ChatServer(int port)
{ this.port = port; }
public void run()
{
try
{
ServerSocket ss = new Server... | use std::collections::HashMap;
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::net::{TcpListener, TcpStream};
use std::sync::{Arc, RwLock};
use std::thread;
type Username = String;
fn broadcast_message(
user: &str,
clients: &mut HashMap<String, TcpStream>,
message: &str,
) -> io::R... |
Generate a VB translation of this Rust snippet without changing its computational steps. | use std::collections::HashMap;
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::net::{TcpListener, TcpStream};
use std::sync::{Arc, RwLock};
use std::thread;
type Username = String;
fn broadcast_message(
user: &str,
clients: &mut HashMap<String, TcpStream>,
message: &str,
) -> io::R... | Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Module Module1
Class State
Private ReadOnly client As TcpClient
Private ReadOnly sb As New StringBuilder
Public Sub New(name As String, client As TcpClient)
Me.Name = name
Me.client = client
... |
Convert this Ada block to C#, preserving its control flow and logic. | type Count is mod 2**64;
| using System;
using System.Drawing;
class Program
{
static void Main()
{
Bitmap img1 = new Bitmap("Lenna50.jpg");
Bitmap img2 = new Bitmap("Lenna100.jpg");
if (img1.Size != img2.Size)
{
Console.Error.WriteLine("Images are of different sizes");
return;
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.