Hello world/Text: Difference between revisions

From Rosetta Code
Content added Content deleted
(dc)
Line 118: Line 118:
=={{header|Haskell}}==
=={{header|Haskell}}==
main = putStrLn "Goodbye, world"
main = putStrLn "Goodbye, world"

=={{header|Icon}}==
procedure main ()
write ( "Goodbye World" )
end


=={{header|IDL}}==
=={{header|IDL}}==

Revision as of 21:08, 8 December 2008

Task
Hello world/Text
You are encouraged to solve this task according to the task description, using any language you may know.

In this User Output task, the goal is to display the string "Goodbye, World!" on a text console.

See also: User Output - graphical

Ada

Works with: GCC version 4.1.2

<ada>with Ada.Text_IO; use Ada.Text_IO; procedure Main is begin

 Put_Line ("Goodbye, World!");

end Main;</ada>

ALGOL 68

main: (
  printf($"Goodbye, World!"l$)
)

AppleScript

To show in Script Editor Result pane: <applescript>"Goodbye, World!"</applescript>

To show in Script Editor Event Log pane: log "Goodbye, World!"

BASIC

Works with: BASICA
10 print "Goodbye World!"
Works with: QuickBasic version 4.5

<qbasic>PRINT "Goodbye, World!"</qbasic>

Befunge

0"!dlrow ,eybdooG">:v
                  ^,_@

C

Works with: gcc version 4.0.1

<c>#include <stdio.h>

int main(int argc, char **argv) {

 printf("Goodbye, World!\n");
 return 0;

}</c> Or: <c>int main(int argc, char **argv){

 puts("Goodbye, World!");
 return 0;

}</c>

C#

Works with: Mono version 1.2
Works with: Visual C# version 2003

<csharp>System.Console.WriteLine("Goodbye, World!");</csharp>

C++

Works with: GCC version 4.1.2
Works with: Visual C++ version 2005

<cpp>#include <iostream>

using std::cout; using std::endl;

int main () {

 cout << "Goodbye, World!" << endl;
 return 0;

}</cpp>

Clean

Start = "Goodbye, World!"

Common Lisp

(print "Goodbye, World!")

dc

[Goodbye, World!]p

E

println("Goodbye, World!")
stdout.println("Goodbye, World!")

eC

class GoodByeApp : Application
{
   void Main()
   {
      PrintLn("Goodbye, World!");
   }
}

Erlang

io:format("Goodbye, world~n").

Forth

 ." Goodbye, World!"

Or as a whole program:

: goodbye ( -- )   ." Goodbye, World!" CR ;

Fortran

Works with: F77

Simplest case - display using default formatting:

      print *,"Goodbye, world"

Use explicit output format:

100   format (5X,A,"!")
      print 100,"Goodbye, world"

Output to channels other than stdout goes like this:

      write (89,100) "Goodbye, world"

uses the format given at label 100 to output to unit 89. If output unit with this number exists yet (no "OPEN" statement or processor-specific external unit setting), a new file will be created and the output sent there. On most UNIX/Linux systems that file will be named "fort.89".

Haskell

 main = putStrLn "Goodbye, world"

Icon

procedure main ()
  write ( "Goodbye World" )
end

IDL

 print,'Goodbye World'

Java

<java>System.out.println("Goodbye, World!");</java>

JavaScript

Works with: Firefox version 2.0

<javascript><script language="JavaScript"> document.write("Goodbye, World!"); </script></javascript>

Works with: NJS version 0.2.5

<javascript>print('Hello, World!');</javascript>

Lisaac

Works with: Lisaac version 0.13.1

You can print to standard output in Lisaac by calling STRING.print or INTEGER.print:

 Section Header          // The Header section is required.
   + name := GOODBYE;    // Define the name of this object.
 
 Section Public
   - main <- ("Goodbye, World!\n".print;);

However, it may be more straightforward to use IO.print_string instead:

 Section Header          // The Header section is required.
   + name := GOODBYE2;   // Define the name of this object.
 
 Section Public
   - main <- (IO.put_string "Goodbye, World!\n";);

Print includes a line feed:

print [Goodbye, world!]

Type does not:

type [Goodbye, world!]

LSE64

" Goodbye, World!" ,t nl

Lua

Works with: Lua version 5.1.1

<lua>print("Goodbye, World!")</lua>

or:

<lua>print "Goodbye, World!"</lua>

In Lua, parentheses are optional for function calls when there is only one argument and this argument is either a string or a table constructor.

Mathematica

Print["Goodbye, World!"]

MAXScript

print "Goodbye, World!"

or:

format "%" "Goodbye, World!"

mIRC Scripting Language

Works with: mIRC
alias saygoodbye { echo -a Goodbye! }

newLISP

Works with: newLisp version 9.0
(println "Goodbye, World!")

Objective-C

Works with: GCC

To print to stdout:

printf("Goodbye, World!");

To log a time-stamped message to the Console:

NSLog(@"Goodbye, World!");

OCaml

<ocaml>print_endline "Goodbye, World!"</ocaml>

Pascal

Works with: Free Pascal

<pascal>program byeworld; begin

writeln('Goodbye, World!');

end.</pascal>

Perl

Works with: Perl version 5.8.8

<perl>print "Goodbye, World!\n";</perl>

Works with: Perl version 5.10.x

<perl>say 'Goodbye, World!';</perl>

PHP

<php>echo "Goodbye, World!\n";</php>

Pop11

 printf('Goodbye, World!\n');

PostScript

The "==" and "=" operators display the topmost element of the stack with or without processing. Thus:

(Goodbye world) ==

will display the string "(Goodbye world)" while

(Goodbye world) =

will display the content of the the string "(Goodbye wolrd)".

PowerShell

Write-Host "Goodbye, World!"
# For extra flair, you can specify colored output
Write-Host "Goodbye, World!" -foregroundcolor red

Python

Works with: Python version 2.4

<python>print "Goodbye, World!"</python>

The same using sys.stdout <python>import sys sys.stdout.write("Goodbye, World!\n")</python>

In Python 3.0, print is being changed from a statement to a function.

Works with: Python version 3.0

<python>print("Goodbye, World!")</python>

Raven

'Goodbye, World!' print

Ruby

Works with: Ruby version 1.8.4

puts "Goodbye, World!" or $stdout.puts "Goodbye, World!"

Seed7

$ include "seed7_05.s7i";

const proc: main is func
  begin
    writeln("Goodbye, World!");
  end func;

Scheme

Works with: Gauche
(display "Goodbye, world!")
(newline)

or

(print "Goodbye, world!")

Smalltalk

Transcript show: 'Goodbye, world!'; cr.
Works with: GNU Smalltalk
'Goodbye, world!' printNl.

SNUSP

@\G.@\o.o.@\d.--b.@\y.@\e.>@\comma.@\.<-@\W.+@\o.+++r.------l.@\d.>+.! #
 |   |     \@------|#  |    \@@+@@++|+++#-    \\               -
 |   \@@@@=+++++#  |   \===--------!\===!\-----|-------#-------/
 \@@+@@@+++++#     \!#+++++++++++++++++++++++#!/

Tcl

Output to terminal:

 puts "Goodbye, World"

Output to file:

 puts $fileID "Goodbye, World"

UNIX Shell

Works with: Bourne Again SHell
#!/bin/bash
echo "Goodbye World!"

Unlambda

`r``````````````.G.o.o.d.b.y.e.,. .W.o.r.l.di

V

"Goodbye! world" puts

Vedit macro language

Message("Goodbye, World!")

XSLT

<xsl:text>Goodbye, World!
</xsl:text>