kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Currying
Java: module CurryPower
    {
    @Inject Console console;
    void run()
        {
        function Int(Int, Int) divide = (x,y) -> x / y;

        function Int(Int) half = divide(_, 2);
        function Int(Int) partsOf120 = divide(120, _);

        console.print($|half of a dozen is {half(12)}
                       |half of 120 is {partsOf120(2)}
                       |a third is {partsOf120(3)}
                       |and a quarter is {partsOf120(4)}
                     );
        }
    }

Python:  def addN(n):
     def adder(x):
         return x + n
     return adder
Task: Currying
Java: module CurryPower
    {
    @Inject Console console;
    void run()
        {
        function Int(Int, Int) divide = (x,y) -> x / y;

        function Int(Int) half = divide(_, 2);
        function Int(Int) partsOf120 = divide(120, _);

        console.print($|half of a dozen is {half(12)}
                       |half of 120 is {partsOf120(2)}
                       |a third is {partsOf120(3)}
                       |and a quarter is {partsOf120(4)}
                     );
        }
    }

VB: Option Explicit On
Option Infer On
Option Strict On

Module Currying
    
    Function Curry(Of T1, TResult)(func As Func(Of T1, TResult)) As Func(Of T1, TResult)
        
        Return Function(a) func(a)
    End Function

    Function Curry(Of T1, T2, TResult)(func As Func(Of T1, T2, TResult)) As Func(Of T1, Func(Of T2, TResult))
        Return Function(a) Function(b) func(a, b)
    End Function

    Function Curry(Of T1, T2, T3, TResult)(func As Func(Of T1, T2, T3, TResult)) As Func(Of T1, Func(Of T2, Func(Of T3, TResult)))
        Return Function(a) Function(b) Function(c) func(a, b, c)
    End Function

    
End Module
Task: Currying
Go: package main

import (
        "fmt"
        "math"
)

func PowN(b float64) func(float64) float64 {
        return func(e float64) float64 { return math.Pow(b, e) }
}

func PowE(e float64) func(float64) float64 {
        return func(b float64) float64 { return math.Pow(b, e) }
}

type Foo int

func (f Foo) Method(b int) int {
        return int(f) + b
}

func main() {
        pow2 := PowN(2)
        cube := PowE(3)

        fmt.Println("2^8 =", pow2(8))
        fmt.Println("4³ =", cube(4))

        var a Foo = 2
        fn1 := a.Method   
        fn2 := Foo.Method 

        fmt.Println("2 + 2 =", a.Method(2)) 
        fmt.Println("2 + 3 =", fn1(3))
        fmt.Println("2 + 4 =", fn2(a, 4))
        fmt.Println("3 + 5 =", fn2(Foo(3), 5))
}

Python:  def addN(n):
     def adder(x):
         return x + n
     return adder
Task: Currying
Go: package main

import (
        "fmt"
        "math"
)

func PowN(b float64) func(float64) float64 {
        return func(e float64) float64 { return math.Pow(b, e) }
}

func PowE(e float64) func(float64) float64 {
        return func(b float64) float64 { return math.Pow(b, e) }
}

type Foo int

func (f Foo) Method(b int) int {
        return int(f) + b
}

func main() {
        pow2 := PowN(2)
        cube := PowE(3)

        fmt.Println("2^8 =", pow2(8))
        fmt.Println("4³ =", cube(4))

        var a Foo = 2
        fn1 := a.Method   
        fn2 := Foo.Method 

        fmt.Println("2 + 2 =", a.Method(2)) 
        fmt.Println("2 + 3 =", fn1(3))
        fmt.Println("2 + 4 =", fn2(a, 4))
        fmt.Println("3 + 5 =", fn2(Foo(3), 5))
}

VB: Option Explicit On
Option Infer On
Option Strict On

Module Currying
    
    Function Curry(Of T1, TResult)(func As Func(Of T1, TResult)) As Func(Of T1, TResult)
        
        Return Function(a) func(a)
    End Function

    Function Curry(Of T1, T2, TResult)(func As Func(Of T1, T2, TResult)) As Func(Of T1, Func(Of T2, TResult))
        Return Function(a) Function(b) func(a, b)
    End Function

    Function Curry(Of T1, T2, T3, TResult)(func As Func(Of T1, T2, T3, TResult)) As Func(Of T1, Func(Of T2, Func(Of T3, TResult)))
        Return Function(a) Function(b) Function(c) func(a, b, c)
    End Function

    
End Module
Task: Currying
Python:  def addN(n):
     def adder(x):
         return x + n
     return adder

VB: Option Explicit On
Option Infer On
Option Strict On

Module Currying
    
    Function Curry(Of T1, TResult)(func As Func(Of T1, TResult)) As Func(Of T1, TResult)
        
        Return Function(a) func(a)
    End Function

    Function Curry(Of T1, T2, TResult)(func As Func(Of T1, T2, TResult)) As Func(Of T1, Func(Of T2, TResult))
        Return Function(a) Function(b) func(a, b)
    End Function

    Function Curry(Of T1, T2, T3, TResult)(func As Func(Of T1, T2, T3, TResult)) As Func(Of T1, Func(Of T2, Func(Of T3, TResult)))
        Return Function(a) Function(b) Function(c) func(a, b, c)
    End Function

    
End Module
Task: Currying
C: #include<stdarg.h>
#include<stdio.h>

long int factorial(int n){
	if(n>1)
		return n*factorial(n-1);
	return 1;
}

long int sumOfFactorials(int num,...){
	va_list vaList;
	long int sum = 0;
	
	va_start(vaList,num);
	
	while(num--)
		sum += factorial(va_arg(vaList,int));
	
	va_end(vaList);
	
	return sum;
}

int main()
{
	printf("\nSum of factorials of [1,5] : %ld",sumOfFactorials(5,1,2,3,4,5));
	printf("\nSum of factorials of [3,5] : %ld",sumOfFactorials(3,3,4,5));
	printf("\nSum of factorials of [1,3] : %ld",sumOfFactorials(3,1,2,3));
	
	return 0;
}

Go: package main

import (
        "fmt"
        "math"
)

func PowN(b float64) func(float64) float64 {
        return func(e float64) float64 { return math.Pow(b, e) }
}

func PowE(e float64) func(float64) float64 {
        return func(b float64) float64 { return math.Pow(b, e) }
}

type Foo int

func (f Foo) Method(b int) int {
        return int(f) + b
}

func main() {
        pow2 := PowN(2)
        cube := PowE(3)

        fmt.Println("2^8 =", pow2(8))
        fmt.Println("4³ =", cube(4))

        var a Foo = 2
        fn1 := a.Method   
        fn2 := Foo.Method 

        fmt.Println("2 + 2 =", a.Method(2)) 
        fmt.Println("2 + 3 =", fn1(3))
        fmt.Println("2 + 4 =", fn2(a, 4))
        fmt.Println("3 + 5 =", fn2(Foo(3), 5))
}
Task: Currying
C: #include<stdarg.h>
#include<stdio.h>

long int factorial(int n){
	if(n>1)
		return n*factorial(n-1);
	return 1;
}

long int sumOfFactorials(int num,...){
	va_list vaList;
	long int sum = 0;
	
	va_start(vaList,num);
	
	while(num--)
		sum += factorial(va_arg(vaList,int));
	
	va_end(vaList);
	
	return sum;
}

int main()
{
	printf("\nSum of factorials of [1,5] : %ld",sumOfFactorials(5,1,2,3,4,5));
	printf("\nSum of factorials of [3,5] : %ld",sumOfFactorials(3,3,4,5));
	printf("\nSum of factorials of [1,3] : %ld",sumOfFactorials(3,1,2,3));
	
	return 0;
}

PHP: <?php

function curry($callable)
{
    if (_number_of_required_params($callable) === 0) {
        return _make_function($callable);
    }
    if (_number_of_required_params($callable) === 1) {
        return _curry_array_args($callable, _rest(func_get_args()));
    }
    return _curry_array_args($callable, _rest(func_get_args()));
}

function _curry_array_args($callable, $args, $left = true)
{
    return function () use ($callable, $args, $left) {
        if (_is_fullfilled($callable, $args)) {
            return _execute($callable, $args, $left);
        }
        $newArgs = array_merge($args, func_get_args());
        if (_is_fullfilled($callable, $newArgs)) {
            return _execute($callable, $newArgs, $left);
        }
        return _curry_array_args($callable, $newArgs, $left);
    };
}

function _number_of_required_params($callable)
{
    if (is_array($callable)) {
        $refl = new \ReflectionClass($callable[0]);
        $method = $refl->getMethod($callable[1]);
        return $method->getNumberOfRequiredParameters();
    }
    $refl = new \ReflectionFunction($callable);
    return $refl->getNumberOfRequiredParameters();
}

function _make_function($callable)
{
    if (is_array($callable))
        return function() use($callable) {
            return call_user_func_array($callable, func_get_args());
        };
    return $callable;
}

function _execute($callable, $args, $left)
{
    if (! $left) {
        $args = array_reverse($args);
    }
    $placeholders = _placeholder_positions($args);
    if (0 < count($placeholders)) {
        $n = _number_of_required_params($callable);
        if ($n <= _last($placeholders[count($placeholders) - 1])) {
            throw new \Exception('Argument Placeholder found on unexpected position!');
        }
        foreach ($placeholders as $i) {
            $args[$i] = $args[$n];
            array_splice($args, $n, 1);
        }
    }
    return call_user_func_array($callable, $args);
}

function _placeholder_positions($args)
{
    return array_keys(array_filter($args, '_is_placeholder'));
}

function _is_fullfilled($callable, $args)
{
    $args = array_filter($args, function($arg) {
        return ! _is_placeholder($arg);
    });
    return count($args) >= _number_of_required_params($callable);
}

function _is_placeholder($arg)
{
    return $arg instanceof Placeholder;
}

function _rest(array $args)
{
    return array_slice($args, 1);
}

function product($a, $b)
{
    return $a * $b;
}

echo json_encode(array_map(curry('product', 7), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
Task: Currying
C#: public delegate int Plus(int y); 
public delegate Plus CurriedPlus(int x);
public static CurriedPlus plus = 
      delegate(int x) {return delegate(int y) {return x + y;};};
static void Main()
{
    int sum = plus(3)(4); 
    int sum2= plus(2)(plus(3)(4)) 
}

PHP: <?php

function curry($callable)
{
    if (_number_of_required_params($callable) === 0) {
        return _make_function($callable);
    }
    if (_number_of_required_params($callable) === 1) {
        return _curry_array_args($callable, _rest(func_get_args()));
    }
    return _curry_array_args($callable, _rest(func_get_args()));
}

function _curry_array_args($callable, $args, $left = true)
{
    return function () use ($callable, $args, $left) {
        if (_is_fullfilled($callable, $args)) {
            return _execute($callable, $args, $left);
        }
        $newArgs = array_merge($args, func_get_args());
        if (_is_fullfilled($callable, $newArgs)) {
            return _execute($callable, $newArgs, $left);
        }
        return _curry_array_args($callable, $newArgs, $left);
    };
}

function _number_of_required_params($callable)
{
    if (is_array($callable)) {
        $refl = new \ReflectionClass($callable[0]);
        $method = $refl->getMethod($callable[1]);
        return $method->getNumberOfRequiredParameters();
    }
    $refl = new \ReflectionFunction($callable);
    return $refl->getNumberOfRequiredParameters();
}

function _make_function($callable)
{
    if (is_array($callable))
        return function() use($callable) {
            return call_user_func_array($callable, func_get_args());
        };
    return $callable;
}

function _execute($callable, $args, $left)
{
    if (! $left) {
        $args = array_reverse($args);
    }
    $placeholders = _placeholder_positions($args);
    if (0 < count($placeholders)) {
        $n = _number_of_required_params($callable);
        if ($n <= _last($placeholders[count($placeholders) - 1])) {
            throw new \Exception('Argument Placeholder found on unexpected position!');
        }
        foreach ($placeholders as $i) {
            $args[$i] = $args[$n];
            array_splice($args, $n, 1);
        }
    }
    return call_user_func_array($callable, $args);
}

function _placeholder_positions($args)
{
    return array_keys(array_filter($args, '_is_placeholder'));
}

function _is_fullfilled($callable, $args)
{
    $args = array_filter($args, function($arg) {
        return ! _is_placeholder($arg);
    });
    return count($args) >= _number_of_required_params($callable);
}

function _is_placeholder($arg)
{
    return $arg instanceof Placeholder;
}

function _rest(array $args)
{
    return array_slice($args, 1);
}

function product($a, $b)
{
    return $a * $b;
}

echo json_encode(array_map(curry('product', 7), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
Task: Currying
Java: module CurryPower
    {
    @Inject Console console;
    void run()
        {
        function Int(Int, Int) divide = (x,y) -> x / y;

        function Int(Int) half = divide(_, 2);
        function Int(Int) partsOf120 = divide(120, _);

        console.print($|half of a dozen is {half(12)}
                       |half of 120 is {partsOf120(2)}
                       |a third is {partsOf120(3)}
                       |and a quarter is {partsOf120(4)}
                     );
        }
    }

PHP: <?php

function curry($callable)
{
    if (_number_of_required_params($callable) === 0) {
        return _make_function($callable);
    }
    if (_number_of_required_params($callable) === 1) {
        return _curry_array_args($callable, _rest(func_get_args()));
    }
    return _curry_array_args($callable, _rest(func_get_args()));
}

function _curry_array_args($callable, $args, $left = true)
{
    return function () use ($callable, $args, $left) {
        if (_is_fullfilled($callable, $args)) {
            return _execute($callable, $args, $left);
        }
        $newArgs = array_merge($args, func_get_args());
        if (_is_fullfilled($callable, $newArgs)) {
            return _execute($callable, $newArgs, $left);
        }
        return _curry_array_args($callable, $newArgs, $left);
    };
}

function _number_of_required_params($callable)
{
    if (is_array($callable)) {
        $refl = new \ReflectionClass($callable[0]);
        $method = $refl->getMethod($callable[1]);
        return $method->getNumberOfRequiredParameters();
    }
    $refl = new \ReflectionFunction($callable);
    return $refl->getNumberOfRequiredParameters();
}

function _make_function($callable)
{
    if (is_array($callable))
        return function() use($callable) {
            return call_user_func_array($callable, func_get_args());
        };
    return $callable;
}

function _execute($callable, $args, $left)
{
    if (! $left) {
        $args = array_reverse($args);
    }
    $placeholders = _placeholder_positions($args);
    if (0 < count($placeholders)) {
        $n = _number_of_required_params($callable);
        if ($n <= _last($placeholders[count($placeholders) - 1])) {
            throw new \Exception('Argument Placeholder found on unexpected position!');
        }
        foreach ($placeholders as $i) {
            $args[$i] = $args[$n];
            array_splice($args, $n, 1);
        }
    }
    return call_user_func_array($callable, $args);
}

function _placeholder_positions($args)
{
    return array_keys(array_filter($args, '_is_placeholder'));
}

function _is_fullfilled($callable, $args)
{
    $args = array_filter($args, function($arg) {
        return ! _is_placeholder($arg);
    });
    return count($args) >= _number_of_required_params($callable);
}

function _is_placeholder($arg)
{
    return $arg instanceof Placeholder;
}

function _rest(array $args)
{
    return array_slice($args, 1);
}

function product($a, $b)
{
    return $a * $b;
}

echo json_encode(array_map(curry('product', 7), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
Task: Currying
Python:  def addN(n):
     def adder(x):
         return x + n
     return adder

PHP: <?php

function curry($callable)
{
    if (_number_of_required_params($callable) === 0) {
        return _make_function($callable);
    }
    if (_number_of_required_params($callable) === 1) {
        return _curry_array_args($callable, _rest(func_get_args()));
    }
    return _curry_array_args($callable, _rest(func_get_args()));
}

function _curry_array_args($callable, $args, $left = true)
{
    return function () use ($callable, $args, $left) {
        if (_is_fullfilled($callable, $args)) {
            return _execute($callable, $args, $left);
        }
        $newArgs = array_merge($args, func_get_args());
        if (_is_fullfilled($callable, $newArgs)) {
            return _execute($callable, $newArgs, $left);
        }
        return _curry_array_args($callable, $newArgs, $left);
    };
}

function _number_of_required_params($callable)
{
    if (is_array($callable)) {
        $refl = new \ReflectionClass($callable[0]);
        $method = $refl->getMethod($callable[1]);
        return $method->getNumberOfRequiredParameters();
    }
    $refl = new \ReflectionFunction($callable);
    return $refl->getNumberOfRequiredParameters();
}

function _make_function($callable)
{
    if (is_array($callable))
        return function() use($callable) {
            return call_user_func_array($callable, func_get_args());
        };
    return $callable;
}

function _execute($callable, $args, $left)
{
    if (! $left) {
        $args = array_reverse($args);
    }
    $placeholders = _placeholder_positions($args);
    if (0 < count($placeholders)) {
        $n = _number_of_required_params($callable);
        if ($n <= _last($placeholders[count($placeholders) - 1])) {
            throw new \Exception('Argument Placeholder found on unexpected position!');
        }
        foreach ($placeholders as $i) {
            $args[$i] = $args[$n];
            array_splice($args, $n, 1);
        }
    }
    return call_user_func_array($callable, $args);
}

function _placeholder_positions($args)
{
    return array_keys(array_filter($args, '_is_placeholder'));
}

function _is_fullfilled($callable, $args)
{
    $args = array_filter($args, function($arg) {
        return ! _is_placeholder($arg);
    });
    return count($args) >= _number_of_required_params($callable);
}

function _is_placeholder($arg)
{
    return $arg instanceof Placeholder;
}

function _rest(array $args)
{
    return array_slice($args, 1);
}

function product($a, $b)
{
    return $a * $b;
}

echo json_encode(array_map(curry('product', 7), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
Task: HTTPS_Client-authenticated
C#: using System;
using System.Net;

class Program
{
    class MyWebClient : WebClient
    {
        protected override WebRequest GetWebRequest(Uri address)
        {
            HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
            request.ClientCertificates.Add(new X509Certificate());
            return request;
        }
    }
    static void Main(string[] args)
    {
        var client = new MyWebClient();

        var data = client.DownloadString("https:

        Console.WriteLine(data);
    }
}

Go: package main

import (
	"crypto/tls"
	"io/ioutil"
	"log"
	"net/http"
)

func main() {

	
	cert, err := tls.LoadX509KeyPair(
		"./client.local.tld/client.local.tld.crt",
		"./client.local.tld/client.local.tld.key",
	)

	if err != nil {
		log.Fatal("Error while loading x509 key pair", err)
	}

	
	tlsConfig := &tls.Config{Certificates: []tls.Certificate{cert}}

	tlsConfig.BuildNameToCertificate()
	transport := &http.Transport{TLSClientConfig: tlsConfig}

	
	client := &http.Client{Transport: transport}

	res, err := client.Get("https:
	if err != nil {
		log.Fatal(err)
	}
	contents, err := ioutil.ReadAll(res.Body)
	log.Print(string(contents))

}
Task: HTTPS_Client-authenticated
C#: using System;
using System.Net;

class Program
{
    class MyWebClient : WebClient
    {
        protected override WebRequest GetWebRequest(Uri address)
        {
            HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
            request.ClientCertificates.Add(new X509Certificate());
            return request;
        }
    }
    static void Main(string[] args)
    {
        var client = new MyWebClient();

        var data = client.DownloadString("https:

        Console.WriteLine(data);
    }
}

Python: import httplib

connection = httplib.HTTPSConnection('www.example.com',cert_file='myCert.PEM')
connection.request('GET','/index.html')
response = connection.getresponse()
data = response.read()
Task: HTTPS_Client-authenticated
Go: package main

import (
	"crypto/tls"
	"io/ioutil"
	"log"
	"net/http"
)

func main() {

	
	cert, err := tls.LoadX509KeyPair(
		"./client.local.tld/client.local.tld.crt",
		"./client.local.tld/client.local.tld.key",
	)

	if err != nil {
		log.Fatal("Error while loading x509 key pair", err)
	}

	
	tlsConfig := &tls.Config{Certificates: []tls.Certificate{cert}}

	tlsConfig.BuildNameToCertificate()
	transport := &http.Transport{TLSClientConfig: tlsConfig}

	
	client := &http.Client{Transport: transport}

	res, err := client.Get("https:
	if err != nil {
		log.Fatal(err)
	}
	contents, err := ioutil.ReadAll(res.Body)
	log.Print(string(contents))

}

Python: import httplib

connection = httplib.HTTPSConnection('www.example.com',cert_file='myCert.PEM')
connection.request('GET','/index.html')
response = connection.getresponse()
data = response.read()
Task: Yahoo! search interface
Go: package main

import (
    "fmt"
    "golang.org/x/net/html"
    "io/ioutil"
    "net/http"
    "regexp"
    "strings"
)

var (
    expr = `<h3 class="title"><a class=.*?href="(.*?)".*?>(.*?)</a></h3>` +
        `.*?<div class="compText aAbs" ><p class=.*?>(.*?)</p></div>`
    rx = regexp.MustCompile(expr)
)

type YahooResult struct {
    title, url, content string
}

func (yr YahooResult) String() string {
    return fmt.Sprintf("Title  : %s\nUrl    : %s\nContent: %s\n", yr.title, yr.url, yr.content)
}

type YahooSearch struct {
    query string
    page  int
}

func (ys YahooSearch) results() []YahooResult {
    search := fmt.Sprintf("http:
    resp, _ := http.Get(search)
    body, _ := ioutil.ReadAll(resp.Body)
    s := string(body)
    defer resp.Body.Close()
    var results []YahooResult
    for _, f := range rx.FindAllStringSubmatch(s, -1) {
        yr := YahooResult{}
        yr.title = html.UnescapeString(strings.ReplaceAll(strings.ReplaceAll(f[2], "<b>", ""), "</b>", ""))
        yr.url = f[1]
        yr.content = html.UnescapeString(strings.ReplaceAll(strings.ReplaceAll(f[3], "<b>", ""), "</b>", ""))
        results = append(results, yr)
    }
    return results
}

func (ys YahooSearch) nextPage() YahooSearch {
    return YahooSearch{ys.query, ys.page + 1}
}

func main() {
    ys := YahooSearch{"rosettacode", 0}
    
    fmt.Println("PAGE 1 =>\n")
    for _, res := range ys.results()[0:5] {
        fmt.Println(res)
    }
    fmt.Println("PAGE 2 =>\n")
    for _, res := range ys.nextPage().results()[0:5] {
        fmt.Println(res)
    }
}

Python: import urllib
import re

def fix(x):
    p = re.compile(r'<[^<]*?>')
    return p.sub('', x).replace('&amp;', '&')
 
class YahooSearch:
    def __init__(self, query, page=1):       
        self.query = query
        self.page = page
        self.url = "http://search.yahoo.com/search?p=%s&b=%s" %(self.query, ((self.page - 1) * 10 + 1))
        self.content = urllib.urlopen(self.url).read()        
 
    def getresults(self):
        self.results = []
 
        for i in re.findall('<a class="yschttl spt" href=".+?">(.+?)</a></h3></div>(.+?)</div>.*?<span class=url>(.+?)</span>', self.content):
 
            title = fix(i[0])
            content = fix(i[1])
            url = fix(i[2])
 
            self.results.append(YahooResult(title, content, url))
 
        return self.results
 
    def getnextpage(self):
        return YahooSearch(self.query, self.page+1)
 
    search_results = property(fget=getresults)
    nextpage = property(fget=getnextpage)
 
class YahooResult:
    def __init__(self,title,content,url):
        self.title = title
        self.content = content
        self.url = url
 

 
x = YahooSearch("test")
 
for result in x.search_results:
    print result.title