WeixiangYan/CodeTransOcean huggingface dataset:
Task: Archimedean spiral








VB: Private Sub plot_coordinate_pairs(x As Variant, y As Variant)
    Dim chrt As Chart
    Set chrt = ActiveSheet.Shapes.AddChart.Chart
    With chrt
        .ChartType = xlXYScatter
        .HasLegend = False
        .SeriesCollection.NewSeries
        .SeriesCollection.Item(1).XValues = x
        .SeriesCollection.Item(1).Values = y
    End With
End Sub
Public Sub main()
    Dim x(1000) As Single, y(1000) As Single
    a = 1
    b = 9
    For i = 0 To 1000
        theta = i * WorksheetFunction.Pi() / 60
        r = a + b * theta
        x(i) = r * Cos(theta)
        y(i) = r * Sin(theta)
    Next i
    plot_coordinate_pairs x, y
End Sub




Ada: with Ada.Numerics.Elementary_Functions;

with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Events.Events;

procedure Archimedean_Spiral is

   Width      : constant := 800;
   Height     : constant := 800;
   A          : constant := 4.2;
   B          : constant := 3.2;
   T_First    : constant := 4.0;
   T_Last     : constant := 100.0;

   Window   : SDL.Video.Windows.Window;
   Renderer : SDL.Video.Renderers.Renderer;
   Event    : SDL.Events.Events.Events;

   procedure Draw_Archimedean_Spiral is
      use type SDL.C.int;
      use Ada.Numerics.Elementary_Functions;
      Pi   : constant := Ada.Numerics.Pi;
      Step : constant := 0.002;
      T    : Float;
      R    : Float;
   begin
      T := T_First;
      loop
         R := A + B * T;
         Renderer.Draw
           (Point => (X => Width  / 2 + SDL.C.int (R * Cos (T, 2.0 * Pi)),
                      Y => Height / 2 - SDL.C.int (R * Sin (T, 2.0 * Pi))));
         exit when T >= T_Last;
         T := T + Step;
      end loop;
   end Draw_Archimedean_Spiral;

   procedure Wait is
      use type SDL.Events.Event_Types;
   begin
      loop
         while SDL.Events.Events.Poll (Event) loop
            if Event.Common.Event_Type = SDL.Events.Quit then
               return;
            end if;
         end loop;
      end loop;
   end Wait;

begin
   if not SDL.Initialise (Flags => SDL.Enable_Screen) then
      return;
   end if;

   SDL.Video.Windows.Makers.Create (Win      => Window,
                                    Title    => "Archimedean spiral",
                                    Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
                                    Size     => SDL.Positive_Sizes'(Width, Height),
                                    Flags    => 0);
   SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface);
   Renderer.Set_Draw_Colour ((0, 0, 0, 255));
   Renderer.Fill (Rectangle => (0, 0, Width, Height));
   Renderer.Set_Draw_Colour ((0, 220, 0, 255));

   Draw_Archimedean_Spiral;
   Window.Update_Surface;

   Wait;
   Window.Finalize;
   SDL.Finalise;
end Archimedean_Spiral;
Task: Archimedean spiral

C: #include <jambo.h>

Main
   Set break
   a=1.5, b=1.5, r=0, origen x=200, origen y=105
   total = 0, Let ( total := Mul(20, M_PI) )
   Cls
   Loop for ( t=0, var 't' Is less equal to 'total', Let (t := Add (t, 0.005)) )
       #( r = a + b * t )
       Set 'origen x, origen y', # ( 200 + (2*r*sin(t)) ) » 'origen x', #( 105 + (r*cos(t)) ) » 'origen y', 
       Gosub 'Dibuja un segmento'
   Next
   Pause
End

Subrutines

Define (Dibuja un segmento, x1, y1, x2, y2)
  dx=0, dy=0, paso=0, i=0, DX=0, DY=0

  Sub(x2, x1), Sub (y2, y1), Move to ' dx, dy '

  Let( paso := Get if( Greater equal ( Abs(dx) » (DX), Abs(dy)»(DY) ), DX, DY ) )

  
  Div(dx, paso), Div(dy, paso), Move to ( dx, dy )

  Color back (13)
  
  i = 0
  Loop if ( Less equal (i, paso) )
     Locate( y1, x1 ), Printnl( " " )
     Add ( x1, dx), Add( y1, dy ), Move to ( x1, y1 )
     ++i
  Back
  Printnl("\OFF")
Return
Task: Archimedean spiral



C#: using System;
using System.Linq;
using System.Drawing;
using System.Diagnostics;
using System.Drawing.Drawing2D;

class Program
{
    const int width = 380;
    const int height = 380;
    static PointF archimedeanPoint(int degrees)
    {
        const double a = 1;
        const double b = 9;
        double t = degrees * Math.PI / 180;
        double r = a + b * t;
        return new PointF { X = (float)(width / 2 + r * Math.Cos(t)), Y = (float)(height / 2 + r * Math.Sin(t)) };
    }

    static void Main(string[] args)
    {
        var bm = new Bitmap(width, height);
        var g = Graphics.FromImage(bm);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.FillRectangle(new SolidBrush(Color.White), new Rectangle { X = 0, Y = 0, Width = width, Height = height });
        var pen = new Pen(Color.OrangeRed, 1.5f);

        var spiral = Enumerable.Range(0, 360 * 3).AsParallel().AsOrdered().Select(archimedeanPoint);
        var p0 = new PointF(width / 2, height / 2);
        foreach (var p1 in spiral)
        {
            g.DrawLine(pen, p0, p1);
            p0 = p1;
        }
        g.Save(); 
        bm.Save("archimedes-csharp.png");
        Process.Start("archimedes-csharp.png"); 
    }
}
Task: Archimedean spiral





Java: import java.awt.*;
import static java.lang.Math.*;
import javax.swing.*;

public class ArchimedeanSpiral extends JPanel {

    public ArchimedeanSpiral() {
        setPreferredSize(new Dimension(640, 640));
        setBackground(Color.white);
    }

    void drawGrid(Graphics2D g) {
        g.setColor(new Color(0xEEEEEE));
        g.setStroke(new BasicStroke(2));

        double angle = toRadians(45);

        int w = getWidth();
        int center = w / 2;
        int margin = 10;
        int numRings = 8;

        int spacing = (w - 2 * margin) / (numRings * 2);

        for (int i = 0; i < numRings; i++) {
            int pos = margin + i * spacing;
            int size = w - (2 * margin + i * 2 * spacing);
            g.drawOval(pos, pos, size, size);

            double ia = i * angle;
            int x2 = center + (int) (cos(ia) * (w - 2 * margin) / 2);
            int y2 = center - (int) (sin(ia) * (w - 2 * margin) / 2);

            g.drawLine(center, center, x2, y2);
        }
    }

    void drawSpiral(Graphics2D g) {
        g.setStroke(new BasicStroke(2));
        g.setColor(Color.orange);

        double degrees = toRadians(0.1);
        double center = getWidth() / 2;
        double end = 360 * 2 * 10 * degrees;
        double a = 0;
        double b = 20;
        double c = 1;

        for (double theta = 0; theta < end; theta += degrees) {
            double r = a + b * pow(theta, 1 / c);
            double x = r * cos(theta);
            double y = r * sin(theta);
            plot(g, (int) (center + x), (int) (center - y));
        }
    }

    void plot(Graphics2D g, int x, int y) {
        g.drawOval(x, y, 1, 1);
    }

    @Override
    public void paintComponent(Graphics gg) {
        super.paintComponent(gg);
        Graphics2D g = (Graphics2D) gg;
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);

        drawGrid(g);
        drawSpiral(g);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setTitle("Archimedean Spiral");
            f.setResizable(false);
            f.add(new ArchimedeanSpiral(), BorderLayout.CENTER);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        });
    }
}
Task: Archimedean spiral







Python: theta = 0
rotation = 0.1

def setup():
    size(300, 300)
    background(255)

def draw():
    global theta
    translate(width / 2.0, height / 2.0)
    x = theta * cos(theta / PI)
    y = theta * sin(theta / PI)
    point(x, y)
    theta = theta + rotation
    
    if x > width / 2.0:
        background(255)
        theta = 0
Task: Archimedean spiral








VB: Private Sub plot_coordinate_pairs(x As Variant, y As Variant)
    Dim chrt As Chart
    Set chrt = ActiveSheet.Shapes.AddChart.Chart
    With chrt
        .ChartType = xlXYScatter
        .HasLegend = False
        .SeriesCollection.NewSeries
        .SeriesCollection.Item(1).XValues = x
        .SeriesCollection.Item(1).Values = y
    End With
End Sub
Public Sub main()
    Dim x(1000) As Single, y(1000) As Single
    a = 1
    b = 9
    For i = 0 To 1000
        theta = i * WorksheetFunction.Pi() / 60
        r = a + b * theta
        x(i) = r * Cos(theta)
        y(i) = r * Sin(theta)
    Next i
    plot_coordinate_pairs x, y
End Sub
Task: Archimedean spiral




Go: package main

import (
	"image"
	"image/color"
	"image/draw"
	"image/png"
	"log"
	"math"
	"os"
)

func main() {
	const (
		width, height = 600, 600
		centre        = width / 2.0
		degreesIncr   = 0.1 * math.Pi / 180
		turns         = 2
		stop          = 360 * turns * 10 * degreesIncr
		fileName      = "spiral.png"
	)

	img := image.NewNRGBA(image.Rect(0, 0, width, height)) 
	bg := image.NewUniform(color.RGBA{255, 255, 255, 255}) 
	draw.Draw(img, img.Bounds(), bg, image.ZP, draw.Src)   
	fgCol := color.RGBA{255, 0, 0, 255}                    

	a := 1.0
	b := 20.0

	for theta := 0.0; theta < stop; theta += degreesIncr {
		r := a + b*theta
		x := r * math.Cos(theta)
		y := r * math.Sin(theta)
		img.Set(int(centre+x), int(centre-y), fgCol)
	}

	imgFile, err := os.Create(fileName)
	if err != nil {
		log.Fatal(err)
	}
	defer imgFile.Close()

	if err := png.Encode(imgFile, img); err != nil {
		imgFile.Close()
		log.Fatal(err)
	}
}
Task: Named parameters



C#: using System;

namespace NamedParams
{
    class Program
    {
        static void AddWidget(string parent, float x = 0, float y = 0, string text = "Default")
        {
            Console.WriteLine("parent = {0}, x = {1}, y = {2}, text = {3}", parent, x, y, text);
        }

        static void Main(string[] args)
        {
            AddWidget("root", 320, 240, "First");
            AddWidget("root", text: "Origin");
            AddWidget("root", 500);
            AddWidget("root", text: "Footer", y: 400);
        }
    }
}









Ada: procedure Foo (Arg_1 : Integer; Arg_2 : Float := 0.0);
Task: Named parameters

C: #include <stdio.h>



typedef struct { int x, y, z; } FTest_args;

void FTest (FTest_args args) {
	printf("x: %d, y: %d, z: %d\n", args.x, args.y, args.z);
}

#define FT(...) FTest((FTest_args){ __VA_ARGS__ })




#define DFT(...) FTest((FTest_args){ .x = 142, .y = 143, .z = 144, __VA_ARGS__ })




void FTest2 (int x, int y, int z) {
	printf("x: %d, y: %d, z: %d\n", x, y, z);
}

static inline void FTest2_default_wrapper (FTest_args args) {
	return FTest2(args.x, args.y, args.z);
}

#define DF2(...) FTest2_default_wrapper((FTest_args){ .x = 142, .y = 143, .z = 144, __VA_ARGS__ })


int main(int argc, char **argv)
{
	
	FTest((FTest_args){ .y = 10 });
	FTest((FTest_args){ .y = 10, .z = 42 });
	FT( .z = 47, .y = 10, .x = 42 );

	
	DFT();
	DFT( .z = 99 );

	
	DF2();
	DF2( .z = 99 );

	return 0;
}











Ada: procedure Foo (Arg_1 : Integer; Arg_2 : Float := 0.0);
Task: Named parameters


C++: class foo_params{
	friend void foo(foo_params p);
public:
    foo_params(int r):
        required_param_(r),
	optional_x_(0),
	optional_y_(1),
	optional_z_(3.1415)
	{}
     foo_params& x(int i){
	optional_x_=i;
	return *this;
     }
     foo_params& y(int i){
	optional_y_=i;
	return *this;
     }
     foo_params& z(float f){
	optional_z_=f;
	return *this;
     }
private:
        int 	required_param_;
	int 	optional_x_;
	int 	optional_y_;
	float 	optional_z_;
};










Ada: procedure Foo (Arg_1 : Integer; Arg_2 : Float := 0.0);
Task: Named parameters




Go: package main

import (
   "fmt"
)

type params struct {x, y, z int}

func myFunc(p params) int {
    return p.x + p.y + p.z
}

func main() {
    r := myFunc(params{x: 1, y: 2, z: 3}) 
    fmt.Println("r =", r)
    s := myFunc(params{z: 3, y: 2, x: 1}) 
    fmt.Println("s =", s)
    t := myFunc(params{y: 2})             
    fmt.Println("t =", t)
}








Ada: procedure Foo (Arg_1 : Integer; Arg_2 : Float := 0.0);
Task: Named parameters





Java: module NamedParams
    {
    const Point(Int x, Int y)
        {
        Point with(Int? x=Null, Int? y=Null)
            {
            return new Point(x ?: this.x, y ?: this.y);
            }
        }

    @Inject Console console;

    void run()
        {
        Point origin = new Point(0, 0);
        console.print($"origin={origin}");
        Point moveRight = origin.with(x=5);
        console.print($"moveRight(x=5)={moveRight}");
        Point moveUp    = moveRight.with(y=3);
        console.print($"moveUp(y=3)={moveUp}");
        }
    }







Ada: procedure Foo (Arg_1 : Integer; Arg_2 : Float := 0.0);
Task: Named parameters







Python: def subtract(x, y):
    return x - y

subtract(5, 3)         
subtract(y = 3, x = 5) 





Ada: procedure Foo (Arg_1 : Integer; Arg_2 : Float := 0.0);
Task: Named parameters








VB: Public Function timedelta(Optional weeks As Integer = 0, Optional days As Integer = 0, _
    Optional hours As Integer = 0, Optional minutes As Integer = 0, Optional seconds As Integer = 0, _
    Optional milliseconds As Integer = 0, Optional microseconds As Integer = 0) As Variant
End Function
Public Sub main()
    
    fourdays = timedelta(days:=4)
    
    
    oneday = timedelta(days = 1) 
                                        
                                        
    Dim hours As Integer
    shift = timedelta(hours:=hours) 
    
                                 
End Sub




Ada: procedure Foo (Arg_1 : Integer; Arg_2 : Float := 0.0);
Task: Named parameters

C: #include <stdio.h>



typedef struct { int x, y, z; } FTest_args;

void FTest (FTest_args args) {
	printf("x: %d, y: %d, z: %d\n", args.x, args.y, args.z);
}

#define FT(...) FTest((FTest_args){ __VA_ARGS__ })




#define DFT(...) FTest((FTest_args){ .x = 142, .y = 143, .z = 144, __VA_ARGS__ })




void FTest2 (int x, int y, int z) {
	printf("x: %d, y: %d, z: %d\n", x, y, z);
}

static inline void FTest2_default_wrapper (FTest_args args) {
	return FTest2(args.x, args.y, args.z);
}

#define DF2(...) FTest2_default_wrapper((FTest_args){ .x = 142, .y = 143, .z = 144, __VA_ARGS__ })


int main(int argc, char **argv)
{
	
	FTest((FTest_args){ .y = 10 });
	FTest((FTest_args){ .y = 10, .z = 42 });
	FT( .z = 47, .y = 10, .x = 42 );

	
	DFT();
	DFT( .z = 99 );

	
	DF2();
	DF2( .z = 99 );

	return 0;
}
Task: Named parameters



C#: using System;

namespace NamedParams
{
    class Program
    {
        static void AddWidget(string parent, float x = 0, float y = 0, string text = "Default")
        {
            Console.WriteLine("parent = {0}, x = {1}, y = {2}, text = {3}", parent, x, y, text);
        }

        static void Main(string[] args)
        {
            AddWidget("root", 320, 240, "First");
            AddWidget("root", text: "Origin");
            AddWidget("root", 500);
            AddWidget("root", text: "Footer", y: 400);
        }
    }
}
Task: Named parameters


C++: class foo_params{
	friend void foo(foo_params p);
public:
    foo_params(int r):
        required_param_(r),
	optional_x_(0),
	optional_y_(1),
	optional_z_(3.1415)
	{}
     foo_params& x(int i){
	optional_x_=i;
	return *this;
     }
     foo_params& y(int i){
	optional_y_=i;
	return *this;
     }
     foo_params& z(float f){
	optional_z_=f;
	return *this;
     }
private:
        int 	required_param_;
	int 	optional_x_;
	int 	optional_y_;
	float 	optional_z_;
};
Task: Named parameters





Java: module NamedParams
    {
    const Point(Int x, Int y)
        {
        Point with(Int? x=Null, Int? y=Null)
            {
            return new Point(x ?: this.x, y ?: this.y);
            }
        }

    @Inject Console console;

    void run()
        {
        Point origin = new Point(0, 0);
        console.print($"origin={origin}");
        Point moveRight = origin.with(x=5);
        console.print($"moveRight(x=5)={moveRight}");
        Point moveUp    = moveRight.with(y=3);
        console.print($"moveUp(y=3)={moveUp}");
        }
    }
Task: Named parameters







Python: def subtract(x, y):
    return x - y

subtract(5, 3)         
subtract(y = 3, x = 5)
Task: Named parameters








VB: Public Function timedelta(Optional weeks As Integer = 0, Optional days As Integer = 0, _
    Optional hours As Integer = 0, Optional minutes As Integer = 0, Optional seconds As Integer = 0, _
    Optional milliseconds As Integer = 0, Optional microseconds As Integer = 0) As Variant
End Function
Public Sub main()
    
    fourdays = timedelta(days:=4)
    
    
    oneday = timedelta(days = 1) 
                                        
                                        
    Dim hours As Integer
    shift = timedelta(hours:=hours) 
    
                                 
End Sub
Task: Named parameters




Go: package main

import (
   "fmt"
)

type params struct {x, y, z int}

func myFunc(p params) int {
    return p.x + p.y + p.z
}

func main() {
    r := myFunc(params{x: 1, y: 2, z: 3}) 
    fmt.Println("r =", r)
    s := myFunc(params{z: 3, y: 2, x: 1}) 
    fmt.Println("s =", s)
    t := myFunc(params{y: 2})             
    fmt.Println("t =", t)
}
Task: Named parameters



C#: using System;

namespace NamedParams
{
    class Program
    {
        static void AddWidget(string parent, float x = 0, float y = 0, string text = "Default")
        {
            Console.WriteLine("parent = {0}, x = {1}, y = {2}, text = {3}", parent, x, y, text);
        }

        static void Main(string[] args)
        {
            AddWidget("root", 320, 240, "First");
            AddWidget("root", text: "Origin");
            AddWidget("root", 500);
            AddWidget("root", text: "Footer", y: 400);
        }
    }
}








Fortran: subroutine a_sub(arg1, arg2, arg3)
  integer, intent(in) :: arg1, arg2
  integer, intent(out), optional :: arg3
  
end subroutine a_sub
Task: Named parameters


C++: class foo_params{
	friend void foo(foo_params p);
public:
    foo_params(int r):
        required_param_(r),
	optional_x_(0),
	optional_y_(1),
	optional_z_(3.1415)
	{}
     foo_params& x(int i){
	optional_x_=i;
	return *this;
     }
     foo_params& y(int i){
	optional_y_=i;
	return *this;
     }
     foo_params& z(float f){
	optional_z_=f;
	return *this;
     }
private:
        int 	required_param_;
	int 	optional_x_;
	int 	optional_y_;
	float 	optional_z_;
};









Fortran: subroutine a_sub(arg1, arg2, arg3)
  integer, intent(in) :: arg1, arg2
  integer, intent(out), optional :: arg3
  
end subroutine a_sub
Task: Named parameters

C: #include <stdio.h>



typedef struct { int x, y, z; } FTest_args;

void FTest (FTest_args args) {
	printf("x: %d, y: %d, z: %d\n", args.x, args.y, args.z);
}

#define FT(...) FTest((FTest_args){ __VA_ARGS__ })




#define DFT(...) FTest((FTest_args){ .x = 142, .y = 143, .z = 144, __VA_ARGS__ })




void FTest2 (int x, int y, int z) {
	printf("x: %d, y: %d, z: %d\n", x, y, z);
}

static inline void FTest2_default_wrapper (FTest_args args) {
	return FTest2(args.x, args.y, args.z);
}

#define DF2(...) FTest2_default_wrapper((FTest_args){ .x = 142, .y = 143, .z = 144, __VA_ARGS__ })


int main(int argc, char **argv)
{
	
	FTest((FTest_args){ .y = 10 });
	FTest((FTest_args){ .y = 10, .z = 42 });
	FT( .z = 47, .y = 10, .x = 42 );

	
	DFT();
	DFT( .z = 99 );

	
	DF2();
	DF2( .z = 99 );

	return 0;
}










Fortran: subroutine a_sub(arg1, arg2, arg3)
  integer, intent(in) :: arg1, arg2
  integer, intent(out), optional :: arg3
  
end subroutine a_sub
Task: Named parameters




Go: package main

import (
   "fmt"
)

type params struct {x, y, z int}

func myFunc(p params) int {
    return p.x + p.y + p.z
}

func main() {
    r := myFunc(params{x: 1, y: 2, z: 3}) 
    fmt.Println("r =", r)
    s := myFunc(params{z: 3, y: 2, x: 1}) 
    fmt.Println("s =", s)
    t := myFunc(params{y: 2})             
    fmt.Println("t =", t)
}







Fortran: subroutine a_sub(arg1, arg2, arg3)
  integer, intent(in) :: arg1, arg2
  integer, intent(out), optional :: arg3
  
end subroutine a_sub
Task: Named parameters





Java: module NamedParams
    {
    const Point(Int x, Int y)
        {
        Point with(Int? x=Null, Int? y=Null)
            {
            return new Point(x ?: this.x, y ?: this.y);
            }
        }

    @Inject Console console;

    void run()
        {
        Point origin = new Point(0, 0);
        console.print($"origin={origin}");
        Point moveRight = origin.with(x=5);
        console.print($"moveRight(x=5)={moveRight}");
        Point moveUp    = moveRight.with(y=3);
        console.print($"moveUp(y=3)={moveUp}");
        }
    }






Fortran: subroutine a_sub(arg1, arg2, arg3)
  integer, intent(in) :: arg1, arg2
  integer, intent(out), optional :: arg3
  
end subroutine a_sub
Task: Named parameters







Python: def subtract(x, y):
    return x - y

subtract(5, 3)         
subtract(y = 3, x = 5) 




Fortran: subroutine a_sub(arg1, arg2, arg3)
  integer, intent(in) :: arg1, arg2
  integer, intent(out), optional :: arg3
  
end subroutine a_sub
Task: Named parameters








VB: Public Function timedelta(Optional weeks As Integer = 0, Optional days As Integer = 0, _
    Optional hours As Integer = 0, Optional minutes As Integer = 0, Optional seconds As Integer = 0, _
    Optional milliseconds As Integer = 0, Optional microseconds As Integer = 0) As Variant
End Function
Public Sub main()
    
    fourdays = timedelta(days:=4)
    
    
    oneday = timedelta(days = 1) 
                                        
                                        
    Dim hours As Integer
    shift = timedelta(hours:=hours) 
    
                                 
End Sub



Fortran: subroutine a_sub(arg1, arg2, arg3)
  integer, intent(in) :: arg1, arg2
  integer, intent(out), optional :: arg3
  
end subroutine a_sub
Task: Named parameters






PHP: function named($args) {
  $args += ["gbv" => 2,
            "motor" => "away",
            "teenage" => "fbi"];
  echo $args["gbv"] . " men running " . $args['motor'] . " from the " . $args['teenage'];
}

named(["teenage" => "cia", "gbv" => 10]);





Fortran: subroutine a_sub(arg1, arg2, arg3)
  integer, intent(in) :: arg1, arg2
  integer, intent(out), optional :: arg3
  
end subroutine a_sub
Task: Named parameters






PHP: function named($args) {
  $args += ["gbv" => 2,
            "motor" => "away",
            "teenage" => "fbi"];
  echo $args["gbv"] . " men running " . $args['motor'] . " from the " . $args['teenage'];
}

named(["teenage" => "cia", "gbv" => 10]);






Ada: procedure Foo (Arg_1 : Integer; Arg_2 : Float := 0.0);
Task: Named parameters






PHP: function named($args) {
  $args += ["gbv" => 2,
            "motor" => "away",
            "teenage" => "fbi"];
  echo $args["gbv"] . " men running " . $args['motor'] . " from the " . $args['teenage'];
}

named(["teenage" => "cia", "gbv" => 10]);
Task: Catalan numbers

C: #include <stdio.h>

typedef unsigned long long ull;

ull binomial(ull m, ull n)
{
	ull r = 1, d = m - n;
	if (d > n) { n = d; d = m - n; }

	while (m > n) {
		r *= m--;
		while (d > 1 && ! (r%d) ) r /= d--;
	}

	return r;
}

ull catalan1(int n) {
	return binomial(2 * n, n) / (1 + n);
}

ull catalan2(int n) {
	int i;
	ull r = !n;

	for (i = 0; i < n; i++)
		r += catalan2(i) * catalan2(n - 1 - i);
	return r;
}

ull catalan3(int n)
{
	return n ? 2 * (2 * n - 1) * catalan3(n - 1) / (1 + n) : 1;
}

int main(void)
{
	int i;
	puts("\tdirect\tsumming\tfrac");
	for (i = 0; i < 16; i++) {
		printf("%d\t%llu\t%llu\t%llu\n", i,
			catalan1(i), catalan2(i), catalan3(i));
	}

	return 0;
}











Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Test_Catalan is
   function Catalan (N : Natural) return Natural is
      Result : Positive := 1;
   begin
      for I in 1..N loop
         Result := Result * 2 * (2 * I - 1) / (I + 1);
      end loop;
      return Result;
   end Catalan;
begin
   for N in 0..15 loop
      Put_Line (Integer'Image (N) & " =" & Integer'Image (Catalan (N)));
   end loop;
end Test_Catalan;