WeixiangYan/CodeTransOcean huggingface dataset:
Task: Look-and-say sequence







Python: def lookandsay(number):
    result = ""

    repeat = number[0]
    number = number[1:]+" "
    times = 1

    for actual in number:
        if actual != repeat:
            result += str(times)+repeat
            times = 1
            repeat = actual
        else:
            times += 1

    return result

num = "1"

for i in range(10):
    print num
    num = lookandsay(num)



COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. LOOK-AND-SAY-SEQ.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 SEQUENCES.
           02 CUR-SEQ       PIC X(80) VALUE "1".
           02 CUR-CHARS     REDEFINES CUR-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY CI.
           02 CUR-LENGTH    PIC 99 COMP VALUE 1.
           02 NEXT-SEQ      PIC X(80).
           02 NEXT-CHARS    REDEFINES NEXT-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY NI.
        01 ALG-STATE.
           02 STEP-AMOUNT   PIC 99 VALUE 14.
           02 ITEM-COUNT    PIC 9.
           
        PROCEDURE DIVISION.
        LOOK-AND-SAY.
            DISPLAY CUR-SEQ.
            SET CI TO 1.
            SET NI TO 1.
        MAKE-NEXT-ENTRY.
            MOVE 0 TO ITEM-COUNT.
            IF CI IS GREATER THAN CUR-LENGTH GO TO STEP-DONE.
        TALLY-ITEM.
            ADD 1 TO ITEM-COUNT.
            SET CI UP BY 1.
            IF CI IS NOT GREATER THAN CUR-LENGTH
               AND CUR-CHARS(CI) IS EQUAL TO CUR-CHARS(CI - 1) 
                GO TO TALLY-ITEM.
        INSERT-ENTRY.
            MOVE ITEM-COUNT TO NEXT-CHARS(NI).
            MOVE CUR-CHARS(CI - 1) TO NEXT-CHARS(NI + 1).
            SET NI UP BY 2.
            GO TO MAKE-NEXT-ENTRY.
        STEP-DONE.
            MOVE NEXT-SEQ TO CUR-SEQ.
            SET NI DOWN BY 1.
            SET CUR-LENGTH TO NI.
            SUBTRACT 1 FROM STEP-AMOUNT.
            IF STEP-AMOUNT IS NOT EQUAL TO ZERO GO TO LOOK-AND-SAY.
            STOP RUN.
Task: Look-and-say sequence








VB: function looksay( n )
	dim i
	dim accum
	dim res
	dim c
	res = vbnullstring
	do
		if n = vbnullstring then exit do
		accum = 0
		c = left( n,1 )
		do while left( n, 1 ) = c
			accum = accum + 1
			n = mid(n,2)
		loop
		if accum > 0 then 
			res = res & accum & c
		end if
	loop
	looksay = res
end function


COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. LOOK-AND-SAY-SEQ.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 SEQUENCES.
           02 CUR-SEQ       PIC X(80) VALUE "1".
           02 CUR-CHARS     REDEFINES CUR-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY CI.
           02 CUR-LENGTH    PIC 99 COMP VALUE 1.
           02 NEXT-SEQ      PIC X(80).
           02 NEXT-CHARS    REDEFINES NEXT-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY NI.
        01 ALG-STATE.
           02 STEP-AMOUNT   PIC 99 VALUE 14.
           02 ITEM-COUNT    PIC 9.
           
        PROCEDURE DIVISION.
        LOOK-AND-SAY.
            DISPLAY CUR-SEQ.
            SET CI TO 1.
            SET NI TO 1.
        MAKE-NEXT-ENTRY.
            MOVE 0 TO ITEM-COUNT.
            IF CI IS GREATER THAN CUR-LENGTH GO TO STEP-DONE.
        TALLY-ITEM.
            ADD 1 TO ITEM-COUNT.
            SET CI UP BY 1.
            IF CI IS NOT GREATER THAN CUR-LENGTH
               AND CUR-CHARS(CI) IS EQUAL TO CUR-CHARS(CI - 1) 
                GO TO TALLY-ITEM.
        INSERT-ENTRY.
            MOVE ITEM-COUNT TO NEXT-CHARS(NI).
            MOVE CUR-CHARS(CI - 1) TO NEXT-CHARS(NI + 1).
            SET NI UP BY 2.
            GO TO MAKE-NEXT-ENTRY.
        STEP-DONE.
            MOVE NEXT-SEQ TO CUR-SEQ.
            SET NI DOWN BY 1.
            SET CUR-LENGTH TO NI.
            SUBTRACT 1 FROM STEP-AMOUNT.
            IF STEP-AMOUNT IS NOT EQUAL TO ZERO GO TO LOOK-AND-SAY.
            STOP RUN.
Task: Look-and-say sequence




Go: package main

import (
    "fmt"
    "strconv"
)

func lss(s string) (r string) {
    c := s[0]
    nc := 1
    for i := 1; i < len(s); i++ {
        d := s[i]
        if d == c {
            nc++
            continue
        }
        r += strconv.Itoa(nc) + string(c)
        c = d
        nc = 1
    }
    return r + strconv.Itoa(nc) + string(c)
}

func main() {
    s := "1"
    fmt.Println(s)
    for i := 0; i < 8; i++ {
        s = lss(s)
        fmt.Println(s)
    }
}






COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. LOOK-AND-SAY-SEQ.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 SEQUENCES.
           02 CUR-SEQ       PIC X(80) VALUE "1".
           02 CUR-CHARS     REDEFINES CUR-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY CI.
           02 CUR-LENGTH    PIC 99 COMP VALUE 1.
           02 NEXT-SEQ      PIC X(80).
           02 NEXT-CHARS    REDEFINES NEXT-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY NI.
        01 ALG-STATE.
           02 STEP-AMOUNT   PIC 99 VALUE 14.
           02 ITEM-COUNT    PIC 9.
           
        PROCEDURE DIVISION.
        LOOK-AND-SAY.
            DISPLAY CUR-SEQ.
            SET CI TO 1.
            SET NI TO 1.
        MAKE-NEXT-ENTRY.
            MOVE 0 TO ITEM-COUNT.
            IF CI IS GREATER THAN CUR-LENGTH GO TO STEP-DONE.
        TALLY-ITEM.
            ADD 1 TO ITEM-COUNT.
            SET CI UP BY 1.
            IF CI IS NOT GREATER THAN CUR-LENGTH
               AND CUR-CHARS(CI) IS EQUAL TO CUR-CHARS(CI - 1) 
                GO TO TALLY-ITEM.
        INSERT-ENTRY.
            MOVE ITEM-COUNT TO NEXT-CHARS(NI).
            MOVE CUR-CHARS(CI - 1) TO NEXT-CHARS(NI + 1).
            SET NI UP BY 2.
            GO TO MAKE-NEXT-ENTRY.
        STEP-DONE.
            MOVE NEXT-SEQ TO CUR-SEQ.
            SET NI DOWN BY 1.
            SET CUR-LENGTH TO NI.
            SUBTRACT 1 FROM STEP-AMOUNT.
            IF STEP-AMOUNT IS NOT EQUAL TO ZERO GO TO LOOK-AND-SAY.
            STOP RUN.
Task: Look-and-say sequence






PHP: <?php

function lookAndSay($str) {

	return preg_replace_callback('#(.)\1*#', function($matches) {
	
		return strlen($matches[0]).$matches[1];
	}, $str);
}

$num = "1";

foreach(range(1,10) as $i) {

	echo $num."<br/>";
	$num = lookAndSay($num);
}

?>
Task: Look-and-say sequence






PHP: <?php

function lookAndSay($str) {

	return preg_replace_callback('#(.)\1*#', function($matches) {
	
		return strlen($matches[0]).$matches[1];
	}, $str);
}

$num = "1";

foreach(range(1,10) as $i) {

	echo $num."<br/>";
	$num = lookAndSay($num);
}

?>






Ada: with Ada.Text_IO, Ada.Strings.Fixed;
use  Ada.Text_IO, Ada.Strings, Ada.Strings.Fixed;

function "+" (S : String) return String is
   Item : constant Character := S (S'First);
begin
   for Index in S'First + 1..S'Last loop
      if Item /= S (Index) then
         return Trim (Integer'Image (Index - S'First), Both) & Item & (+(S (Index..S'Last)));
      end if;
   end loop;
   return Trim (Integer'Image (S'Length), Both) & Item;
end "+";
Task: Look-and-say sequence






PHP: <?php

function lookAndSay($str) {

	return preg_replace_callback('#(.)\1*#', function($matches) {
	
		return strlen($matches[0]).$matches[1];
	}, $str);
}

$num = "1";

foreach(range(1,10) as $i) {

	echo $num."<br/>";
	$num = lookAndSay($num);
}

?>




COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. LOOK-AND-SAY-SEQ.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 SEQUENCES.
           02 CUR-SEQ       PIC X(80) VALUE "1".
           02 CUR-CHARS     REDEFINES CUR-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY CI.
           02 CUR-LENGTH    PIC 99 COMP VALUE 1.
           02 NEXT-SEQ      PIC X(80).
           02 NEXT-CHARS    REDEFINES NEXT-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY NI.
        01 ALG-STATE.
           02 STEP-AMOUNT   PIC 99 VALUE 14.
           02 ITEM-COUNT    PIC 9.
           
        PROCEDURE DIVISION.
        LOOK-AND-SAY.
            DISPLAY CUR-SEQ.
            SET CI TO 1.
            SET NI TO 1.
        MAKE-NEXT-ENTRY.
            MOVE 0 TO ITEM-COUNT.
            IF CI IS GREATER THAN CUR-LENGTH GO TO STEP-DONE.
        TALLY-ITEM.
            ADD 1 TO ITEM-COUNT.
            SET CI UP BY 1.
            IF CI IS NOT GREATER THAN CUR-LENGTH
               AND CUR-CHARS(CI) IS EQUAL TO CUR-CHARS(CI - 1) 
                GO TO TALLY-ITEM.
        INSERT-ENTRY.
            MOVE ITEM-COUNT TO NEXT-CHARS(NI).
            MOVE CUR-CHARS(CI - 1) TO NEXT-CHARS(NI + 1).
            SET NI UP BY 2.
            GO TO MAKE-NEXT-ENTRY.
        STEP-DONE.
            MOVE NEXT-SEQ TO CUR-SEQ.
            SET NI DOWN BY 1.
            SET CUR-LENGTH TO NI.
            SUBTRACT 1 FROM STEP-AMOUNT.
            IF STEP-AMOUNT IS NOT EQUAL TO ZERO GO TO LOOK-AND-SAY.
            STOP RUN.
Task: Closures_Value capture



C#: using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var captor = (Func<int, Func<int>>)(number => () => number * number);
        var functions = Enumerable.Range(0, 10).Select(captor);
        foreach (var function in functions.Take(9))
        {
            Console.WriteLine(function());
        }
    }
}









Ada: with Ada.Text_IO;

procedure Value_Capture is
   
   protected type Fun is 
      entry Init(Index: Natural);
      function Result return Natural;
   private
      N: Natural := 0;
   end Fun;
   
   protected body Fun is 
      entry Init(Index: Natural) when N=0 is
      begin 
         N := Index;
      end Init;
      function Result return Natural is (N*N);
   end Fun;
   
   A: array (1 .. 10) of Fun; 
   
begin
   for I in A'Range loop 
      A(I).Init(I);
   end loop;
   
   for I in A'First .. A'Last-1 loop 
      Ada.Text_IO.Put(Integer'Image(A(I).Result));
   end loop;
end Value_Capture;
Task: Closures_Value capture

C: #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>

typedef int (*f_int)();
 
#define TAG 0xdeadbeef
int _tmpl() { 
	volatile int x = TAG;
	return x * x;
}

#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS) 
f_int dupf(int v)
{
	size_t len = (void*)dupf - (void*)_tmpl;
	f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
	char *p;
	if(ret == MAP_FAILED) {
		perror("mmap");
		exit(-1);
	}
	memcpy(ret, _tmpl, len);
	for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
		if (*(int *)p == TAG) *(int *)p = v;
	return ret;
}
 
int main()
{
	f_int funcs[10];
	int i;
	for (i = 0; i < 10; i++) funcs[i] = dupf(i);
 
	for (i = 0; i < 9; i++)
		printf("func[%d]: %d\n", i, funcs[i]());
 
	return 0;
}











Ada: with Ada.Text_IO;

procedure Value_Capture is
   
   protected type Fun is 
      entry Init(Index: Natural);
      function Result return Natural;
   private
      N: Natural := 0;
   end Fun;
   
   protected body Fun is 
      entry Init(Index: Natural) when N=0 is
      begin 
         N := Index;
      end Init;
      function Result return Natural is (N*N);
   end Fun;
   
   A: array (1 .. 10) of Fun; 
   
begin
   for I in A'Range loop 
      A(I).Init(I);
   end loop;
   
   for I in A'First .. A'Last-1 loop 
      Ada.Text_IO.Put(Integer'Image(A(I).Result));
   end loop;
end Value_Capture;
Task: Closures_Value capture


C++: #include <iostream>
#include <functional>
#include <vector>

int main() {
  std::vector<std::function<int()> > funcs;
  for (int i = 0; i < 10; i++)
    funcs.push_back([=]() { return i * i; });
  for ( std::function<int( )> f : funcs ) 
    std::cout << f( ) << std::endl ; 
  return 0;
}










Ada: with Ada.Text_IO;

procedure Value_Capture is
   
   protected type Fun is 
      entry Init(Index: Natural);
      function Result return Natural;
   private
      N: Natural := 0;
   end Fun;
   
   protected body Fun is 
      entry Init(Index: Natural) when N=0 is
      begin 
         N := Index;
      end Init;
      function Result return Natural is (N*N);
   end Fun;
   
   A: array (1 .. 10) of Fun; 
   
begin
   for I in A'Range loop 
      A(I).Init(I);
   end loop;
   
   for I in A'First .. A'Last-1 loop 
      Ada.Text_IO.Put(Integer'Image(A(I).Result));
   end loop;
end Value_Capture;
Task: Closures_Value capture




Go: package main

import "fmt"

func main() {
    fs := make([]func() int, 10)
    for i := range fs {
        i := i
        fs[i] = func() int {
            return i * i
        }
    }
    fmt.Println("func #0:", fs[0]())
    fmt.Println("func #3:", fs[3]())
}








Ada: with Ada.Text_IO;

procedure Value_Capture is
   
   protected type Fun is 
      entry Init(Index: Natural);
      function Result return Natural;
   private
      N: Natural := 0;
   end Fun;
   
   protected body Fun is 
      entry Init(Index: Natural) when N=0 is
      begin 
         N := Index;
      end Init;
      function Result return Natural is (N*N);
   end Fun;
   
   A: array (1 .. 10) of Fun; 
   
begin
   for I in A'Range loop 
      A(I).Init(I);
   end loop;
   
   for I in A'First .. A'Last-1 loop 
      Ada.Text_IO.Put(Integer'Image(A(I).Result));
   end loop;
end Value_Capture;
Task: Closures_Value capture





Java: import java.util.function.Supplier;
import java.util.ArrayList;

public class ValueCapture {
    public static void main(String[] args) {
	ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
	for (int i = 0; i < 10; i++) {
	    int j = i;
	    funcs.add(() -> j * j);
	}

	Supplier<Integer> foo = funcs.get(3);
	System.out.println(foo.get()); 
    }
}







Ada: with Ada.Text_IO;

procedure Value_Capture is
   
   protected type Fun is 
      entry Init(Index: Natural);
      function Result return Natural;
   private
      N: Natural := 0;
   end Fun;
   
   protected body Fun is 
      entry Init(Index: Natural) when N=0 is
      begin 
         N := Index;
      end Init;
      function Result return Natural is (N*N);
   end Fun;
   
   A: array (1 .. 10) of Fun; 
   
begin
   for I in A'Range loop 
      A(I).Init(I);
   end loop;
   
   for I in A'First .. A'Last-1 loop 
      Ada.Text_IO.Put(Integer'Image(A(I).Result));
   end loop;
end Value_Capture;
Task: Closures_Value capture







Python: funcs = []
for i in range(10):
    funcs.append(lambda: i * i)
print funcs[3]() 





Ada: with Ada.Text_IO;

procedure Value_Capture is
   
   protected type Fun is 
      entry Init(Index: Natural);
      function Result return Natural;
   private
      N: Natural := 0;
   end Fun;
   
   protected body Fun is 
      entry Init(Index: Natural) when N=0 is
      begin 
         N := Index;
      end Init;
      function Result return Natural is (N*N);
   end Fun;
   
   A: array (1 .. 10) of Fun; 
   
begin
   for I in A'Range loop 
      A(I).Init(I);
   end loop;
   
   for I in A'First .. A'Last-1 loop 
      Ada.Text_IO.Put(Integer'Image(A(I).Result));
   end loop;
end Value_Capture;
Task: Closures_Value capture

C: #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>

typedef int (*f_int)();
 
#define TAG 0xdeadbeef
int _tmpl() { 
	volatile int x = TAG;
	return x * x;
}

#define PROT (PROT_EXEC | PROT_WRITE)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS) 
f_int dupf(int v)
{
	size_t len = (void*)dupf - (void*)_tmpl;
	f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0);
	char *p;
	if(ret == MAP_FAILED) {
		perror("mmap");
		exit(-1);
	}
	memcpy(ret, _tmpl, len);
	for (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++)
		if (*(int *)p == TAG) *(int *)p = v;
	return ret;
}
 
int main()
{
	f_int funcs[10];
	int i;
	for (i = 0; i < 10; i++) funcs[i] = dupf(i);
 
	for (i = 0; i < 9; i++)
		printf("func[%d]: %d\n", i, funcs[i]());
 
	return 0;
}
Task: Closures_Value capture



C#: using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var captor = (Func<int, Func<int>>)(number => () => number * number);
        var functions = Enumerable.Range(0, 10).Select(captor);
        foreach (var function in functions.Take(9))
        {
            Console.WriteLine(function());
        }
    }
}
Task: Closures_Value capture


C++: #include <iostream>
#include <functional>
#include <vector>

int main() {
  std::vector<std::function<int()> > funcs;
  for (int i = 0; i < 10; i++)
    funcs.push_back([=]() { return i * i; });
  for ( std::function<int( )> f : funcs ) 
    std::cout << f( ) << std::endl ; 
  return 0;
}
Task: Closures_Value capture





Java: import java.util.function.Supplier;
import java.util.ArrayList;

public class ValueCapture {
    public static void main(String[] args) {
	ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
	for (int i = 0; i < 10; i++) {
	    int j = i;
	    funcs.add(() -> j * j);
	}

	Supplier<Integer> foo = funcs.get(3);
	System.out.println(foo.get()); 
    }
}
Task: Closures_Value capture







Python: funcs = []
for i in range(10):
    funcs.append(lambda: i * i)
print funcs[3]()
Task: Closures_Value capture




Go: package main

import "fmt"

func main() {
    fs := make([]func() int, 10)
    for i := range fs {
        i := i
        fs[i] = func() int {
            return i * i
        }
    }
    fmt.Println("func #0:", fs[0]())
    fmt.Println("func #3:", fs[3]())
}
Task: Closures_Value capture






PHP: <?php
$funcs = array();
for ($i = 0; $i < 10; $i++) {
    $funcs[] = function () use ($i) { return $i * $i; };
}
echo $funcs[3](), "\n"; // prints 9
?>
Task: Closures_Value capture






PHP: <?php
$funcs = array();
for ($i = 0; $i < 10; $i++) {
    $funcs[] = function () use ($i) { return $i * $i; };
}
echo $funcs[3](), "\n"; // prints 9
?>






Ada: with Ada.Text_IO;

procedure Value_Capture is
   
   protected type Fun is 
      entry Init(Index: Natural);
      function Result return Natural;
   private
      N: Natural := 0;
   end Fun;
   
   protected body Fun is 
      entry Init(Index: Natural) when N=0 is
      begin 
         N := Index;
      end Init;
      function Result return Natural is (N*N);
   end Fun;
   
   A: array (1 .. 10) of Fun; 
   
begin
   for I in A'Range loop 
      A(I).Init(I);
   end loop;
   
   for I in A'First .. A'Last-1 loop 
      Ada.Text_IO.Put(Integer'Image(A(I).Result));
   end loop;
end Value_Capture;
Task: Send email



C#: static void Main(string[] args)
{
    

    SmtpClient SMTP = new SmtpClient("smtp.gmail.com", 587); 
    SMTP.EnableSsl = true; 
    SMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
    SMTP.Credentials = new NetworkCredential("YourUserName", "YourPassword");
    MailMessage Mail = new MailMessage("yourEmail@address.com", "theirEmail@address.com");


    

    Mail.Subject = "Important Message";
    Mail.Body = "Hello over there"; 
    

    

    SMTP.Send(Mail);

    Console.WriteLine("Message Sent");
}









Ada: with AWS.SMTP, AWS.SMTP.Client, AWS.SMTP.Authentication.Plain;
with Ada.Text_IO;
use  Ada, AWS;

procedure Sendmail is
   Status : SMTP.Status;
   Auth : aliased constant SMTP.Authentication.Plain.Credential :=
      SMTP.Authentication.Plain.Initialize ("id", "password");
   Isp : SMTP.Receiver;
begin
   Isp :=
      SMTP.Client.Initialize
        ("smtp.mail.com",
         Port       => 5025,
         Credential => Auth'Unchecked_Access);
   SMTP.Client.Send
     (Isp,
      From    => SMTP.E_Mail ("Me", "me@some.org"),
      To      => SMTP.E_Mail ("You", "you@any.org"),
      Subject => "subject",
      Message => "Here is the text",
      Status  => Status);
   if not SMTP.Is_Ok (Status) then
      Text_IO.Put_Line
        ("Can't send message :" & SMTP.Status_Message (Status));
   end if;
end Sendmail;
Task: Send email


C++: 



#include <cstdlib>
#include <iostream>
#include <Poco/Net/SMTPClientSession.h>
#include <Poco/Net/MailMessage.h>

using namespace Poco::Net;

int main (int argc, char **argv)
{
  try
    {
      MailMessage msg;

      msg.addRecipient (MailRecipient (MailRecipient::PRIMARY_RECIPIENT,
                                       "alice@example.com",
                                       "Alice Moralis"));
      msg.addRecipient (MailRecipient (MailRecipient::CC_RECIPIENT,
                                       "pat@example.com",
                                       "Patrick Kilpatrick"));
      msg.addRecipient (MailRecipient (MailRecipient::BCC_RECIPIENT,
                                       "mike@example.com",
                                       "Michael Carmichael"));

      msg.setSender ("Roy Kilroy <roy@example.com>");

      msg.setSubject ("Rosetta Code");
      msg.setContent ("Sending mail from C++ using POCO C++ Libraries");

      SMTPClientSession smtp ("mail.example.com"); 
      smtp.login ();
      smtp.sendMessage (msg);
      smtp.close ();
      std::cerr << "Sent mail successfully!" << std::endl;
    }
  catch (std::exception &e)
    {
      std::cerr << "failed to send mail: " << e.what() << std::endl;
      return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}










Ada: with AWS.SMTP, AWS.SMTP.Client, AWS.SMTP.Authentication.Plain;
with Ada.Text_IO;
use  Ada, AWS;

procedure Sendmail is
   Status : SMTP.Status;
   Auth : aliased constant SMTP.Authentication.Plain.Credential :=
      SMTP.Authentication.Plain.Initialize ("id", "password");
   Isp : SMTP.Receiver;
begin
   Isp :=
      SMTP.Client.Initialize
        ("smtp.mail.com",
         Port       => 5025,
         Credential => Auth'Unchecked_Access);
   SMTP.Client.Send
     (Isp,
      From    => SMTP.E_Mail ("Me", "me@some.org"),
      To      => SMTP.E_Mail ("You", "you@any.org"),
      Subject => "subject",
      Message => "Here is the text",
      Status  => Status);
   if not SMTP.Is_Ok (Status) then
      Text_IO.Put_Line
        ("Can't send message :" & SMTP.Status_Message (Status));
   end if;
end Sendmail;
Task: Send email





Java: import java.util.Properties;

import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class Mail
{
 
 protected Session session;

 
 public Mail(String host)
 {
  Properties properties = new Properties();
  properties.put("mail.smtp.host", host);
  session = Session.getDefaultInstance(properties);
 }

 
 public void send(String from, String tos[], String ccs[], String subject,
        String text)
        throws MessagingException
 {
  MimeMessage message = new MimeMessage(session);
  message.setFrom(new InternetAddress(from));
  for (String to : tos)
   message.addRecipient(RecipientType.TO, new InternetAddress(to));
  for (String cc : ccs)
   message.addRecipient(RecipientType.TO, new InternetAddress(cc));
  message.setSubject(subject);
  message.setText(text);
  Transport.send(message);
 }
}







Ada: with AWS.SMTP, AWS.SMTP.Client, AWS.SMTP.Authentication.Plain;
with Ada.Text_IO;
use  Ada, AWS;

procedure Sendmail is
   Status : SMTP.Status;
   Auth : aliased constant SMTP.Authentication.Plain.Credential :=
      SMTP.Authentication.Plain.Initialize ("id", "password");
   Isp : SMTP.Receiver;
begin
   Isp :=
      SMTP.Client.Initialize
        ("smtp.mail.com",
         Port       => 5025,
         Credential => Auth'Unchecked_Access);
   SMTP.Client.Send
     (Isp,
      From    => SMTP.E_Mail ("Me", "me@some.org"),
      To      => SMTP.E_Mail ("You", "you@any.org"),
      Subject => "subject",
      Message => "Here is the text",
      Status  => Status);
   if not SMTP.Is_Ok (Status) then
      Text_IO.Put_Line
        ("Can't send message :" & SMTP.Status_Message (Status));
   end if;
end Sendmail;