WeixiangYan/CodeTransOcean huggingface dataset:
Task: Arrays








VB: Option Base {0|1}


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. arrays.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  fixed-length-table.
           03  fixed-table-elt      PIC X OCCURS 5 TIMES.

       01  table-length             PIC 9(5) VALUE 1.
       01  variable-length-table.
           03  variable-table-elt   PIC X OCCURS 1 TO 5 TIMES
               DEPENDING ON table-length.

       01  initial-value-area.
           03  initial-values.
               05  FILLER           PIC X(10) VALUE "One".
               05  FILLER           PIC X(10) VALUE "Two".
               05  FILLER           PIC X(10) VALUE "Three".
           03 initial-value-table REDEFINES initial-values.
              05  initial-table-elt PIC X(10) OCCURS 3 TIMES.

       01  indexed-table.
           03  indexed-elt          PIC X OCCURS 5 TIMES
               INDEXED BY table-index.

       PROCEDURE DIVISION.
           
           MOVE "12345" TO fixed-length-table
           
           
           MOVE 1 TO table-index
           MOVE "1" TO indexed-elt (table-index)

           
           ADD 1 TO table-length
           MOVE "1" TO variable-table-elt (2)

           GOBACK
           .
Task: Arrays




Go: package main

import (
    "fmt"
)

func main() {
    
    
    
    var a [5]int

    
    
    fmt.Println("len(a) =", len(a))

    
    fmt.Println("a =", a)

    
    a[0] = 3
    fmt.Println("a =", a)

    
    fmt.Println("a[0] =", a[0])

    
    s := a[:4] 
    fmt.Println("s =", s)

    
    
    
    fmt.Println("len(s) =", len(s), " cap(s) =", cap(s))

    
    
    s = s[:5]
    fmt.Println("s =", s)

    
    a[0] = 22
    fmt.Println("a =", a)
    fmt.Println("s =", s)

    
    s = append(s, 4, 5, 6)
    fmt.Println("s =", s)
    fmt.Println("len(s) =", len(s), " cap(s) =", cap(s))

    
    a[4] = -1
    fmt.Println("a =", a)
    fmt.Println("s =", s)

    
    s = make([]int, 8)
    fmt.Println("s =", s)
    fmt.Println("len(s) =", len(s), " cap(s) =", cap(s))

    
    
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. arrays.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  fixed-length-table.
           03  fixed-table-elt      PIC X OCCURS 5 TIMES.

       01  table-length             PIC 9(5) VALUE 1.
       01  variable-length-table.
           03  variable-table-elt   PIC X OCCURS 1 TO 5 TIMES
               DEPENDING ON table-length.

       01  initial-value-area.
           03  initial-values.
               05  FILLER           PIC X(10) VALUE "One".
               05  FILLER           PIC X(10) VALUE "Two".
               05  FILLER           PIC X(10) VALUE "Three".
           03 initial-value-table REDEFINES initial-values.
              05  initial-table-elt PIC X(10) OCCURS 3 TIMES.

       01  indexed-table.
           03  indexed-elt          PIC X OCCURS 5 TIMES
               INDEXED BY table-index.

       PROCEDURE DIVISION.
           
           MOVE "12345" TO fixed-length-table
           
           
           MOVE 1 TO table-index
           MOVE "1" TO indexed-elt (table-index)

           
           ADD 1 TO table-length
           MOVE "1" TO variable-table-elt (2)

           GOBACK
           .
Task: Arrays






PHP: $NumberArray = array(0, 1, 2, 3, 4, 5, 6);
$LetterArray = array("a", "b", "c", "d", "e", "f");
$simpleForm = ['apple', 'orange'];
Task: Arrays






PHP: $NumberArray = array(0, 1, 2, 3, 4, 5, 6);
$LetterArray = array("a", "b", "c", "d", "e", "f");
$simpleForm = ['apple', 'orange'];






Ada: procedure Array_Test is

   A, B : array (1..20) of Integer;

   
   C : array (-37..20) of integer

   
   
   type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
   type Activities is (Work, Fish);
   type Daily_Activities is array(Days) of Activities;
   This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);

   
   type Fingers is range 1..4; 
   type Fingers_Extended_Type is array(fingers) of Boolean;
   Fingers_Extended : Fingers_Extended_Type;

   
   
   type Arr is array (Integer range <>) of Integer;
   Uninitialized : Arr (1 .. 10);
   Initialized_1 : Arr (1 .. 20) := (others => 1);
   Initialized_2 : Arr := (1 .. 30 => 2);
   Const         : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
   Centered      : Arr (-50..50) := (0 => 1, Others => 0);

   Result        : Integer
begin

   A := (others => 0);     
   B := (1 => 1, 2 => 1, 3 => 2, others => 0); 
                           
   A (1) := -1;            
   A (2..4) := B (1..3);   
   A (3..5) := (2, 4, -1); 
   A (3..5) := A (4..6);   
   
   Fingers_Extended'First := False; 
   Fingers_Extended'Last := False;  

end Array_Test;
Task: Arrays






PHP: $NumberArray = array(0, 1, 2, 3, 4, 5, 6);
$LetterArray = array("a", "b", "c", "d", "e", "f");
$simpleForm = ['apple', 'orange'];




COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. arrays.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  fixed-length-table.
           03  fixed-table-elt      PIC X OCCURS 5 TIMES.

       01  table-length             PIC 9(5) VALUE 1.
       01  variable-length-table.
           03  variable-table-elt   PIC X OCCURS 1 TO 5 TIMES
               DEPENDING ON table-length.

       01  initial-value-area.
           03  initial-values.
               05  FILLER           PIC X(10) VALUE "One".
               05  FILLER           PIC X(10) VALUE "Two".
               05  FILLER           PIC X(10) VALUE "Three".
           03 initial-value-table REDEFINES initial-values.
              05  initial-table-elt PIC X(10) OCCURS 3 TIMES.

       01  indexed-table.
           03  indexed-elt          PIC X OCCURS 5 TIMES
               INDEXED BY table-index.

       PROCEDURE DIVISION.
           
           MOVE "12345" TO fixed-length-table
           
           
           MOVE 1 TO table-index
           MOVE "1" TO indexed-elt (table-index)

           
           ADD 1 TO table-length
           MOVE "1" TO variable-table-elt (2)

           GOBACK
           .
Task: Arrays







Python: array = []

array.append(1)
array.append(3)

array[0] = 2

print array[0]
Task: Partial function application



C#: using System;
using System.Collections.Generic;
using System.Linq;

class PartialFunctionApplication
{
    static Func<T1, TResult> PartiallyApply<T1, T2, TResult>(Func<T1, T2, TResult> function, T2 argument2)
    {
        return argument1 => function(argument1, argument2);
    }

    static void Main()
    {
        var fs = (Func<IEnumerable<int>, Func<int, int>, IEnumerable<int>>)Enumerable.Select;
        var f1 = (Func<int, int>)(n => n * 2);
        var f2 = (Func<int, int>)(n => n * n);
        var fsf1 = PartiallyApply(fs, f1);
        var fsf2 = PartiallyApply(fs, f2);

        var s = new[] { 0, 1, 2, 3 };
        Console.WriteLine(string.Join(", ", fsf1(s)));
        Console.WriteLine(string.Join(", ", fsf2(s)));

        s = new[] { 2, 4, 6, 8 };
        Console.WriteLine(string.Join(", ", fsf1(s)));
        Console.WriteLine(string.Join(", ", fsf2(s)));
    }
}









Ada: with Ada.Text_IO;

procedure Partial_Function_Application is

   type Sequence is array(Positive range <>) of Integer;

   
   generic
      with function F(I: Integer) return Integer; 
   function FS (S: Sequence) return Sequence;

   
   function FS (S: Sequence) return Sequence is
      Result: Sequence(S'First .. S'Last);
   begin
      for Idx in S'Range loop
         Result(Idx) := F(S(Idx));
      end loop;
      return Result;
   end FS;

   
   function F1(I: Integer) return Integer is
   begin
      return 2*I;
   end F1;

   function F2(I: Integer) return Integer is
   begin
      return I**2;
   end F2;

   
   function FSF1 is new FS(F1);
   function FSF2 is new FS(F2);

   procedure Print(S: Sequence) is
   begin
      for Idx in S'Range loop
         Ada.Text_IO.Put(Integer'Image(S(Idx)));
      end loop;
      Ada.Text_IO.New_Line;
   end Print;

begin
   Print(FSF1((0,1,2,3)));
   Print(FSF2((0,1,2,3)));
   Print(FSF1((2,4,6,8)));
   Print(FSF2((2,4,6,8)));
end Partial_Function_Application;
Task: Partial function application

C: #include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <sys/wait.h>
#include <err.h>

typedef int (*intfunc)(int);
typedef void (*pfunc)(int*, int);

pfunc partial(intfunc fin)
{
	pfunc f;
	static int idx = 0;
	char cc[256], lib[256];
	FILE *fp;
	sprintf(lib, "/tmp/stuff%d.so", ++idx);
	sprintf(cc, "cc -pipe -x c -shared -o %s -", lib);

	fp = popen(cc, "w");
	fprintf(fp, "#define t typedef\xat int _i,*i;t _i(*__)(_i);__ p =(__)%p;"
		"void _(i _1, _i l){while(--l>-1)l[_1]=p(l[_1]);}", fin);
	fclose(fp);

	*(void **)(&f) = dlsym(dlopen(lib, RTLD_LAZY), "_");
	unlink(lib);
	return f;
}

int square(int a)
{
	return a * a;
}

int dbl(int a)
{
	return a + a;
}

int main()
{
	int x[] = { 1, 2, 3, 4 };
	int y[] = { 1, 2, 3, 4 };
	int i;

	pfunc f = partial(square);
	pfunc g = partial(dbl);

	printf("partial square:\n");
	f(x, 4);
	for (i = 0; i < 4; i++) printf("%d\n", x[i]);

	printf("partial double:\n");
	g(y, 4);
	for (i = 0; i < 4; i++) printf("%d\n", y[i]);

	return 0;
}











Ada: with Ada.Text_IO;

procedure Partial_Function_Application is

   type Sequence is array(Positive range <>) of Integer;

   
   generic
      with function F(I: Integer) return Integer; 
   function FS (S: Sequence) return Sequence;

   
   function FS (S: Sequence) return Sequence is
      Result: Sequence(S'First .. S'Last);
   begin
      for Idx in S'Range loop
         Result(Idx) := F(S(Idx));
      end loop;
      return Result;
   end FS;

   
   function F1(I: Integer) return Integer is
   begin
      return 2*I;
   end F1;

   function F2(I: Integer) return Integer is
   begin
      return I**2;
   end F2;

   
   function FSF1 is new FS(F1);
   function FSF2 is new FS(F2);

   procedure Print(S: Sequence) is
   begin
      for Idx in S'Range loop
         Ada.Text_IO.Put(Integer'Image(S(Idx)));
      end loop;
      Ada.Text_IO.New_Line;
   end Print;

begin
   Print(FSF1((0,1,2,3)));
   Print(FSF2((0,1,2,3)));
   Print(FSF1((2,4,6,8)));
   Print(FSF2((2,4,6,8)));
end Partial_Function_Application;
Task: Partial function application


C++: #include <utility> 
#include <algorithm>
#include <array>
#include <iterator>
#include <iostream>


template< class F, class Arg >
struct PApply
{
    F f;
    Arg arg;

    template< class F_, class Arg_ >
    PApply( F_&& f, Arg_&& arg )
        : f(std::forward<F_>(f)), arg(std::forward<Arg_>(arg))
    {
    }

    
    template< class ... Args >
    auto operator() ( Args&& ...args )
        -> decltype( f(arg,std::declval<Args>()...) )
    {
        return f( arg, std::forward<Args>(args)... );
    }
};

template< class F, class Arg >
PApply<F,Arg> papply( F&& f, Arg&& arg )
{
    return PApply<F,Arg>( std::forward<F>(f), std::forward<Arg>(arg) );
}


template< class F >
std::array<int,4> fs( F&& f, std::array<int,4> cont )
{
    std::transform( std::begin(cont), std::end(cont), std::begin(cont), 
                    std::forward<F>(f) );
    return cont;
}

std::ostream& operator << ( std::ostream& out, const std::array<int,4>& c )
{
    std::copy( std::begin(c), std::end(c), 
               std::ostream_iterator<int>(out, ", ") );
    return out;
}

int f1( int x ) { return x * 2; }
int f2( int x ) { return x * x; }

int main()
{
    std::array<int,4> xs = {{ 0, 1, 2, 3 }};
    std::array<int,4> ys = {{ 2, 4, 6, 8 }};

    auto fsf1 = papply( fs<decltype(f1)>, f1 );
    auto fsf2 = papply( fs<decltype(f2)>, f2 );

    std::cout << "xs:\n"
              << "\tfsf1: " << fsf1(xs) << '\n'
              << "\tfsf2: " << fsf2(xs) << "\n\n"
              << "ys:\n"
              << "\tfsf1: " << fsf1(ys) << '\n'
              << "\tfsf2: " << fsf2(ys) << '\n';
}










Ada: with Ada.Text_IO;

procedure Partial_Function_Application is

   type Sequence is array(Positive range <>) of Integer;

   
   generic
      with function F(I: Integer) return Integer; 
   function FS (S: Sequence) return Sequence;

   
   function FS (S: Sequence) return Sequence is
      Result: Sequence(S'First .. S'Last);
   begin
      for Idx in S'Range loop
         Result(Idx) := F(S(Idx));
      end loop;
      return Result;
   end FS;

   
   function F1(I: Integer) return Integer is
   begin
      return 2*I;
   end F1;

   function F2(I: Integer) return Integer is
   begin
      return I**2;
   end F2;

   
   function FSF1 is new FS(F1);
   function FSF2 is new FS(F2);

   procedure Print(S: Sequence) is
   begin
      for Idx in S'Range loop
         Ada.Text_IO.Put(Integer'Image(S(Idx)));
      end loop;
      Ada.Text_IO.New_Line;
   end Print;

begin
   Print(FSF1((0,1,2,3)));
   Print(FSF2((0,1,2,3)));
   Print(FSF1((2,4,6,8)));
   Print(FSF2((2,4,6,8)));
end Partial_Function_Application;
Task: Partial function application




Go: package main

import "fmt"




type fn func(int) int


func (f fn) fs(s ...int) (r []int) {
	for _, i := range s {
		r = append(r, f(i))
	}
	return r
}


func f1(i int) int { return i * 2 }
func f2(i int) int { return i * i }




func addn(n int) func(...int) []int {
	return func(s ...int) []int {
		var r []int
		for _, i := range s {
			r = append(r, n+i)
		}
		return r
	}
}

func main() {
	
	fsf1 := fn(f1).fs
	fsf2 := fn(f2).fs
	
	fsf3 := addn(100)

	s := []int{0, 1, 2, 3}
	fmt.Println("For s =", s)
	fmt.Println("  fsf1:", fsf1(s...))       
	fmt.Println("  fsf2:", fsf2(0, 1, 2, 3)) 
	fmt.Println("  fsf3:", fsf3(0, 1, 2, 3))
	fmt.Println("  fsf2(fsf1):", fsf2(fsf1(s...)...))

	s = []int{2, 4, 6, 8}
	fmt.Println("For s =", s)
	fmt.Println("  fsf1:", fsf1(2, 4, 6, 8))
	fmt.Println("  fsf2:", fsf2(s...))
	fmt.Println("  fsf3:", fsf3(s...))
	fmt.Println("  fsf3(fsf1):", fsf3(fsf1(s...)...))
}








Ada: with Ada.Text_IO;

procedure Partial_Function_Application is

   type Sequence is array(Positive range <>) of Integer;

   
   generic
      with function F(I: Integer) return Integer; 
   function FS (S: Sequence) return Sequence;

   
   function FS (S: Sequence) return Sequence is
      Result: Sequence(S'First .. S'Last);
   begin
      for Idx in S'Range loop
         Result(Idx) := F(S(Idx));
      end loop;
      return Result;
   end FS;

   
   function F1(I: Integer) return Integer is
   begin
      return 2*I;
   end F1;

   function F2(I: Integer) return Integer is
   begin
      return I**2;
   end F2;

   
   function FSF1 is new FS(F1);
   function FSF2 is new FS(F2);

   procedure Print(S: Sequence) is
   begin
      for Idx in S'Range loop
         Ada.Text_IO.Put(Integer'Image(S(Idx)));
      end loop;
      Ada.Text_IO.New_Line;
   end Print;

begin
   Print(FSF1((0,1,2,3)));
   Print(FSF2((0,1,2,3)));
   Print(FSF1((2,4,6,8)));
   Print(FSF2((2,4,6,8)));
end Partial_Function_Application;
Task: Partial function application





Java: import java.util.Arrays;

public class PartialApplication {
	interface IntegerFunction {
		int call(int arg);
	}

	
	static int[] fs(IntegerFunction f, int[] s) {
		int[] r = new int[s.length];
		for (int i = 0; i < s.length; i++)
			r[i] = f.call(s[i]);
		return r;		
	}

	interface SequenceFunction {
		int[] call(int[] arg);
	}

	
	
	static SequenceFunction fs(final IntegerFunction f) {
		return new SequenceFunction() {
			public int[] call(int[] s) {
				
				return fs(f, s);
			}
		};
	}

	static IntegerFunction f1 = new IntegerFunction() {
		public int call(int i) {
			return i * 2;
		}
	};

	static IntegerFunction f2 = new IntegerFunction() {
		public int call(int i) {
			return i * i;
		}
	};

	static SequenceFunction fsf1 = fs(f1); 

	static SequenceFunction fsf2 = fs(f2);

	public static void main(String[] args) {
		int[][] sequences = {
			{ 0, 1, 2, 3 },
			{ 2, 4, 6, 8 },
		};

		for (int[] array : sequences) {
			System.out.printf(
			    "array: %s\n" +
			    "  fsf1(array): %s\n" +
			    "  fsf2(array): %s\n",
			    Arrays.toString(array),
			    Arrays.toString(fsf1.call(array)),
			    Arrays.toString(fsf2.call(array)));
		}
	}
}







Ada: with Ada.Text_IO;

procedure Partial_Function_Application is

   type Sequence is array(Positive range <>) of Integer;

   
   generic
      with function F(I: Integer) return Integer; 
   function FS (S: Sequence) return Sequence;

   
   function FS (S: Sequence) return Sequence is
      Result: Sequence(S'First .. S'Last);
   begin
      for Idx in S'Range loop
         Result(Idx) := F(S(Idx));
      end loop;
      return Result;
   end FS;

   
   function F1(I: Integer) return Integer is
   begin
      return 2*I;
   end F1;

   function F2(I: Integer) return Integer is
   begin
      return I**2;
   end F2;

   
   function FSF1 is new FS(F1);
   function FSF2 is new FS(F2);

   procedure Print(S: Sequence) is
   begin
      for Idx in S'Range loop
         Ada.Text_IO.Put(Integer'Image(S(Idx)));
      end loop;
      Ada.Text_IO.New_Line;
   end Print;

begin
   Print(FSF1((0,1,2,3)));
   Print(FSF2((0,1,2,3)));
   Print(FSF1((2,4,6,8)));
   Print(FSF2((2,4,6,8)));
end Partial_Function_Application;
Task: Partial function application







Python: from functools import partial

def fs(f, s): return [f(value) for value in s]

def f1(value): return value * 2

def f2(value): return value ** 2

fsf1 = partial(fs, f1)
fsf2 = partial(fs, f2)

s = [0, 1, 2, 3]
assert fs(f1, s) == fsf1(s) 
assert fs(f2, s) == fsf2(s) 

s = [2, 4, 6, 8]
assert fs(f1, s) == fsf1(s) 
assert fs(f2, s) == fsf2(s) 





Ada: with Ada.Text_IO;

procedure Partial_Function_Application is

   type Sequence is array(Positive range <>) of Integer;

   
   generic
      with function F(I: Integer) return Integer; 
   function FS (S: Sequence) return Sequence;

   
   function FS (S: Sequence) return Sequence is
      Result: Sequence(S'First .. S'Last);
   begin
      for Idx in S'Range loop
         Result(Idx) := F(S(Idx));
      end loop;
      return Result;
   end FS;

   
   function F1(I: Integer) return Integer is
   begin
      return 2*I;
   end F1;

   function F2(I: Integer) return Integer is
   begin
      return I**2;
   end F2;

   
   function FSF1 is new FS(F1);
   function FSF2 is new FS(F2);

   procedure Print(S: Sequence) is
   begin
      for Idx in S'Range loop
         Ada.Text_IO.Put(Integer'Image(S(Idx)));
      end loop;
      Ada.Text_IO.New_Line;
   end Print;

begin
   Print(FSF1((0,1,2,3)));
   Print(FSF2((0,1,2,3)));
   Print(FSF1((2,4,6,8)));
   Print(FSF2((2,4,6,8)));
end Partial_Function_Application;
Task: Partial function application








VB: Module PartialApplication
    Function fs(Of TSource, TResult)(f As Func(Of TSource, TResult), s As IEnumerable(Of TSource)) As IEnumerable(Of TResult)
        
        Return s.Select(f)
    End Function

    Function f1(x As Integer) As Integer
        Return x * 2
    End Function

    Function f2(x As Integer) As Integer
        Return x * x
    End Function

    
    Function PartialApply(Of T1, T2, TResult)(f As Func(Of T1, T2, TResult), arg As T1) As Func(Of T2, TResult)
        Return Function(arg2) f(arg, arg2)
    End Function

    Sub Main()
        Dim args1 As Integer() = {0, 1, 2, 3}
        Dim args2 As Integer() = {2, 4, 6, 8}

        Dim fsf1 = PartialApply(Of Func(Of Integer, Integer), IEnumerable(Of Integer), IEnumerable(Of Integer))(AddressOf fs, AddressOf f1)
        Dim fsf2 = PartialApply(Of Func(Of Integer, Integer), IEnumerable(Of Integer), IEnumerable(Of Integer))(AddressOf fs, AddressOf f2)

        Console.WriteLine("fsf1, 0-3: " & String.Join(", ", fsf1(args1)))
        Console.WriteLine("fsf1, evens: " & String.Join(", ", fsf1(args2)))
        Console.WriteLine("fsf2, 0-3: " & String.Join(", ", fsf2(args1)))
        Console.WriteLine("fsf2, evens: " & String.Join(", ", fsf2(args2)))
    End Sub
End Module




Ada: with Ada.Text_IO;

procedure Partial_Function_Application is

   type Sequence is array(Positive range <>) of Integer;

   
   generic
      with function F(I: Integer) return Integer; 
   function FS (S: Sequence) return Sequence;

   
   function FS (S: Sequence) return Sequence is
      Result: Sequence(S'First .. S'Last);
   begin
      for Idx in S'Range loop
         Result(Idx) := F(S(Idx));
      end loop;
      return Result;
   end FS;

   
   function F1(I: Integer) return Integer is
   begin
      return 2*I;
   end F1;

   function F2(I: Integer) return Integer is
   begin
      return I**2;
   end F2;

   
   function FSF1 is new FS(F1);
   function FSF2 is new FS(F2);

   procedure Print(S: Sequence) is
   begin
      for Idx in S'Range loop
         Ada.Text_IO.Put(Integer'Image(S(Idx)));
      end loop;
      Ada.Text_IO.New_Line;
   end Print;

begin
   Print(FSF1((0,1,2,3)));
   Print(FSF2((0,1,2,3)));
   Print(FSF1((2,4,6,8)));
   Print(FSF2((2,4,6,8)));
end Partial_Function_Application;
Task: Partial function application

C: #include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <sys/wait.h>
#include <err.h>

typedef int (*intfunc)(int);
typedef void (*pfunc)(int*, int);

pfunc partial(intfunc fin)
{
	pfunc f;
	static int idx = 0;
	char cc[256], lib[256];
	FILE *fp;
	sprintf(lib, "/tmp/stuff%d.so", ++idx);
	sprintf(cc, "cc -pipe -x c -shared -o %s -", lib);

	fp = popen(cc, "w");
	fprintf(fp, "#define t typedef\xat int _i,*i;t _i(*__)(_i);__ p =(__)%p;"
		"void _(i _1, _i l){while(--l>-1)l[_1]=p(l[_1]);}", fin);
	fclose(fp);

	*(void **)(&f) = dlsym(dlopen(lib, RTLD_LAZY), "_");
	unlink(lib);
	return f;
}

int square(int a)
{
	return a * a;
}

int dbl(int a)
{
	return a + a;
}

int main()
{
	int x[] = { 1, 2, 3, 4 };
	int y[] = { 1, 2, 3, 4 };
	int i;

	pfunc f = partial(square);
	pfunc g = partial(dbl);

	printf("partial square:\n");
	f(x, 4);
	for (i = 0; i < 4; i++) printf("%d\n", x[i]);

	printf("partial double:\n");
	g(y, 4);
	for (i = 0; i < 4; i++) printf("%d\n", y[i]);

	return 0;
}
Task: Partial function application



C#: using System;
using System.Collections.Generic;
using System.Linq;

class PartialFunctionApplication
{
    static Func<T1, TResult> PartiallyApply<T1, T2, TResult>(Func<T1, T2, TResult> function, T2 argument2)
    {
        return argument1 => function(argument1, argument2);
    }

    static void Main()
    {
        var fs = (Func<IEnumerable<int>, Func<int, int>, IEnumerable<int>>)Enumerable.Select;
        var f1 = (Func<int, int>)(n => n * 2);
        var f2 = (Func<int, int>)(n => n * n);
        var fsf1 = PartiallyApply(fs, f1);
        var fsf2 = PartiallyApply(fs, f2);

        var s = new[] { 0, 1, 2, 3 };
        Console.WriteLine(string.Join(", ", fsf1(s)));
        Console.WriteLine(string.Join(", ", fsf2(s)));

        s = new[] { 2, 4, 6, 8 };
        Console.WriteLine(string.Join(", ", fsf1(s)));
        Console.WriteLine(string.Join(", ", fsf2(s)));
    }
}