Translations from Turing

From Compsci.ca Wiki

Revision as of 06:51, 12 October 2008 by Wtd (Talk | contribs)
Jump to: navigation, search

Contents

Hello, world!

Turing

% This is a comment
put "Hello, world!"

C

/* This a comment */

#include <stdio.h>

int main()
{
   puts("Hello, world!");
   return 0;
}

C++

// This is a comment

#include <iostream>

int main()
{
   std::cout << "Hello, world!" << std::endl;
   return 0;
}

Java

// This is a comment

import java.lang.*;
import java.io.*;

public static void HelloWorld {
   public static void main(String[] args) {
      System.out.println("Hello, world!");
   }
}

C#

// This is a comment

using System;

public class HelloWorld 
{
   public static void Main(string[] args)
   {
      Console.WriteLine("Hello, world!");
   }
}

D

// This is a comment

import std.stream;

void main()
{
   stdout.writeLine("Hello, world!");
}

Perl

# This a comment
print "Hello, world!\n";

Python

# This a comment
print "Hello, world!"

Ruby

# This a comment
puts "Hello, world!"

O'Caml

(* This a comment *)
print_endline "Hello, world!"

Eiffel

-- This is a comment
class HELLO_WORLD
creation {ANY} make
feature {ANY}
   make is
      do
         std_output.put_string("Hello, world!")
         std_output.put_new_line
      end
end

Pascal

(* This a comment *)
program HelloWorld;
begin
   WriteLn('Hello, world!')
end.

Ada95

-- This is a comment
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello_World is
begin
   Put_Line("Hello, world!");
end Hello_World;

Javascript

// This is a comment
document.write("Hello, world!<br/>");

A procedure

Now, abstracting the "Hello, world!" into a procedure called "say_hello_world".

Note: That name may appear slightly different depending on the naming conventions of a language. Where possible, forward declarations are used.

Turing

procedure sayHelloWorld
   put "Hello, world!"
end sayHelloWorld

sayHelloWorld

C

#include <stdio.h>

void say_hello_world();

int main()
{
   say_hello_world();
   return 0;
}

void say_hello_world()
{
   puts("Hello, world!");
}

C++

#include <iostream>

void say_hello_world();

int main()
{
   say_hello_world();
   return 0;
}

void say_hello_world()
{
   std::cout << "Hello, world!" << std::endl;
}

Java

import java.lang.*;
import java.io.*;

public class HelloWorld {
   public static void main(String[] args) {
      sayHelloWorld();
   }

   private static void sayHelloWorld() {
      System.out.println("Hello, world!");
   }
}

C#

using System;

public class HelloWorld 
{ 
   public static void Main(string[] args) 
   {
      SayHelloWorld();
   }

   private static void SayHelloWorld() 
   {
      Console.WriteLine("Hello, world!");
   }
}

D

import std.stream;

void main()
{
   sayHelloWorld();
}

void sayHelloWorld()
{
   stdout.writeLine("Hello, world!");
}

Perl

say_hello_world;

sub say_hello_world {
   print "Hello, world!";
}

Python

def say_hello_world():
   print "Hello, world!"

say_hello_world()

Ruby

def say_hello_world
   puts "Hello, world!"
end

say_hello_world

O'Caml

let say_hello_world () = 
   print_endline "Hello, world!"

say_hello_world ()

Eiffel

class HELLO_WORLD
creation {ANY} make
feature {ANY}
   make is
      do
         say_hello_world
      end
feature {NONE}
   say_hello_world is

      do
         std_output.put_string("Hello, world!")
         std_output.put_new_line
      end
end

Pascal

program HelloWorld;
var
   procedure SayHelloWorld;
   begin
      WriteLn('Hello, world!')
   end;
begin
   SayHelloWorld
end.

Ada

with Ada.Text_IO; use Ada.Text_IO;
procedure Hello_World is
   procedure Say_Hello_World is
   begin
      Put_Line("Hello, world!");
   end Say_Hello_World;
begin
   Say_Hello_World;
end Hello_World;

Javascript

function sayHelloWorld() {
   document.write("Hello, world!");
}

sayHelloWorld();

Credits

Author: Wtd

Personal tools