Hello world/Text

From Rosetta Code
Task
Hello world/Text
You are encouraged to solve this task according to the task description, using any language you may know.
Hello world/Text is part of Short Circuit's Console Program Basics selection.

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

See also: Hello world/Graphical or Hello world/Standard error

8086 Assembly

<lang asm> DOSSEG .MODEL TINY .DATA TXT DB "Goodbye, World!$" .CODE START: MOV ax, @DATA MOV ds, ax

MOV ah, 09h ;prepare output function MOV dx, OFFSET TXT ; set offset INT 21h ; output string TXT

MOV AX, 4C00h ; go back to DOS INT 21h END START </lang>

ABAP

<lang ABAP> REPORT zgoodbyeworld.

 WRITE 'Goodbye, World!'.

</lang>

ActionScript

<lang ActionScript>trace("Goodbye, World!");</lang>

Ada

Works with: GCC version 4.1.2

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

 Put_Line ("Goodbye, World!");

end Main;</lang>

Aikido

<lang aikido> println ("Goodbye, World!") </lang>

ALGOL 68

<lang algol68>main: (

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

)</lang>

AmigaE

<lang amigae>PROC main()

 WriteF('Goodbye, World!\n')

ENDPROC</lang>

AppleScript

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

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

Argile

<lang Argile>use std print "Goodbye, World!"</lang> compile with: arc hello_world.arg -o hello_world.c && gcc -o hello_world hello_world.c

AutoHotkey

script launched from windows explorer <lang AutoHotkey>DllCall("AllocConsole") FileAppend, Goodbye`, World!, CONOUT$ FileReadLine, _, CONIN$, 1</lang> scripts run from shell [requires Windows XP or higher; older Versions of Windows don´t have the "AttachConsole" function] <lang AutoHotkey>DllCall("AttachConsole", "int", -1) FileAppend, Goodbye`, World!, CONOUT$</lang> <lang AutoHotkey>SendInput Goodbye, World{!}</lang>

AWK

<lang awk>BEGIN{print "Goodbye, World!"}</lang>

BASIC

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

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

Batch File

<lang dos>echo Goodbye, World!</lang>

BCPL

<lang BCPL>GET "libhdr"

LET start() = VALOF { writef("Goodbye, World!")

 RESULTIS 0

}</lang>

Befunge

<lang befunge>0"!dlrow ,eybdooG">:v

                 ^,_@</lang>

Brainf***

We wanna make a series of round numbers going like:

10 close to newline and carriage return

30 close to ! and SPACE

40 close to COMMA

70 close to G

80 close to W

90 close to b

100 is d and close to e and l

110 close to o

120 close to y

forming all the letters we need if we just add up a bit

Commented version: <lang bf> +++++ +++++ First cell 10 (its a counter and we will be "multiplying")

[ >+ 10 times 1 is 10 >+++ 10 times 3 is 30 >++++ etc etc >+++++ ++ >+++++ +++ >+++++ ++++ >+++++ +++++ >+++++ ++++++ >+++++ +++++++ <<<<<<<<< - go back to counter and subtract 1 ]

printing G >>>> + .

o twice >>>> + ..

d < .

b < +++++ +++ .

y >>> + .

e << + .

COMMA <<<< ++++ .

SPACE < ++ .

W >>> +++++ ++ .

o >>> .

r +++ .

l < +++++ ++ .

d


--- .

! <<<<< + .

CRLF < +++ . --- .</lang>

Uncommented: <lang bf> ++++++++++[>+>+++>++++>+++++++>++++++++>+++++++++>++ ++++++++>+++++++++++>++++++++++++<<<<<<<<<-]>>>>+.>>> >+..<.<++++++++.>>>+.<<+.<<<<++++.<++.>>>+++++++.>>>.+++. <+++++++.--------.<<<<<+.<.+++.</lang> It can most likely be optimized, but this is a nice way to show how character printing works in Brainf*** :)

C

Works with: gcc version 4.0.1

<lang c>#include <stdio.h>

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

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

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

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

}</lang>

C#

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

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

C++

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

<lang cpp>#include <iostream>

int main () {

 std::cout << "Goodbye, World!" << std::endl;
 return std::cout.bad();

}</lang>

Chef

<lang Chef>Hello World Souffle.

This recipe prints the immortal words "Hello world!", in a basically brute force way. It also makes a lot of food for one person.

Ingredients. 72 g haricot beans 101 eggs 108 g lard 111 cups oil 32 zucchinis 119 ml water 114 g red salmon 100 g dijon mustard 33 potatoes

Method. Put potatoes into the mixing bowl. Put dijon mustard into the mixing bowl. Put lard into the mixing bowl. Put red salmon into the mixing bowl. Put oil into the mixing bowl. Put water into the mixing bowl. Put zucchinis into the mixing bowl. Put oil into the mixing bowl. Put lard into the mixing bowl. Put lard into the mixing bowl. Put eggs into the mixing bowl. Put haricot beans into the mixing bowl. Liquefy contents of the mixing bowl. Pour contents of the mixing bowl into the baking dish.

Serves 1.</lang>

Clean

<lang clean>Start = "Goodbye, World!"</lang>

Clojure

<lang lisp>(println "Goodbye, world!")</lang>

Common Lisp

<lang lisp>(format t "Goodbye, world!~%")</lang>

D

<lang D>import tango.io.Console

void main() {

 Cout("Goodbye, World!").newline;

}</lang>

Dao

<lang dao>io.writeln( 'Goodbye, World!' )</lang>

dc

<lang dc>[Goodbye, World!]p</lang>

E

<lang e>println("Goodbye, World!")

stdout.println("Goodbye, World!")</lang>

eC

<lang ec>class GoodByeApp : Application {

  void Main()
  {
     PrintLn("Goodbye, World!");
  }

}</lang>

Efene

short version (without a function)

<lang efene>io.format("Goodbye, world~n")</lang>

complete version (put this in a file and compile it)

<lang efene>@public run = fn () {

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

}</lang>

Erlang

<lang erlang>io:format("Goodbye, world~n").</lang>

Factor

<lang factor>"Goodbye, world." print</lang>

Falcon

<lang false> > "Goodbye, World!" </lang>

FALSE

<lang false>"Goodbye, World! "</lang>

Forth

<lang forth>." Goodbye, World!"</lang>

Or as a whole program:

<lang forth>: goodbye ( -- ) ." Goodbye, World!" CR ;</lang>

Fortran

Works with: F77

Simplest case - display using default formatting:

<lang fortran>print *,"Goodbye, world"</lang>

Use explicit output format:

<lang fortran>100 format (5X,A,"!")

     print 100,"Goodbye, world"</lang>

Output to channels other than stdout goes like this:

<lang fortran>write (89,100) "Goodbye, world"</lang>

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".

F#

<lang fsharp>printfn "%s" "Goodbye, world"</lang> or using .Net classes directly <lang fsharp>System.Console.WriteLine("Goodbye, World!")</lang>

Glee

<lang glee>"Goodbye, World!"</lang>

Go

<lang go>package main

import "fmt"

func main() { fmt.Printf("Goodbye, World!\n") }</lang>

Haskell

<lang haskell>main = putStrLn "Goodbye, world"</lang>

HicEst

<lang hicest>WRITE() 'Goodbye, World!'</lang>

HLA

<lang HLA>program goodbyeWorld;

  1. include("stdlib.hhf")

begin goodbyeWorld;

 stdout.put( "Goodbye, World!" nl );

end goodbyeWorld;</lang>

Icon and Unicon

Icon

<lang icon>procedure main()

 write( "Goodbye World" )

end</lang>

Unicon

This Icon solution works in Unicon.

IDL

<lang idl>print,'Goodbye World'</lang>

Ioke

<lang ioke>"Goodbye, World!" println</lang>

J

<lang j> 'Goodbye, World!' Goodbye, World!</lang>

Here are some redundant alternatives: <lang J>

  [data=. 'Goodbye, World!'

Goodbye, World!

  data

Goodbye, World!

  smoutput data

Goodbye, World!</lang>

Java

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

JavaScript

Works with: Firefox version 2.0

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

Works with: NJS version 0.2.5
Works with: Rhino
Works with: SpiderMonkey

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

Works with: JScript

<lang javascript>WScript.Echo("Hello, World!");</lang>

Joy

<lang joy>"Goodbye, World!" putchars.</lang>

Lisaac

Works with: Lisaac version 0.13.1

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

<lang lisaac>Section Header // The Header section is required.

 + name := GOODBYE;    // Define the name of this object.

Section Public

 - main <- ("Goodbye, World!\n".print;);</lang>

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

<lang lisaac>Section Header // The Header section is required.

 + name := GOODBYE2;   // Define the name of this object.

Section Public

 - main <- (IO.put_string "Goodbye, World!\n";);</lang>

Print includes a line feed: <lang logo>print [Goodbye, world!]</lang> Type does not: <lang logo>type [Goodbye, world!]</lang>

LSE64

<lang lse64>" Goodbye, World!" ,t nl</lang>

Lua

Works with: Lua version 5.1.1

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

or:

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

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.

M4

For the particular nature of m4, this is simply: <lang m4>`Goodbye, World'</lang>

Mathematica

<lang mathematica>Print["Goodbye, World!"]</lang>

MAXScript

<lang maxscript>print "Goodbye, World!"</lang> or: <lang maxscript>format "%" "Goodbye, World!"</lang>

Mercury

<lang mecury>

- module hello.
- interface.
- import_module io.
- pred main(io::di, io::uo) is det.
- implementation.

main(!IO) :-

   io.write_string("Goodbye, World!\n", !IO).

</lang>

Metafont

<lang metafont>message "Goodbye, World"; end</lang>

mIRC Scripting Language

Works with: mIRC

<lang mirc>alias saygoodbye { echo -a Goodbye! }</lang>

Modula-3

<lang modula3>MODULE Goodbye EXPORTS Main;

IMPORT IO;

BEGIN

 IO.Put("Goodbye, World!\n");

END Goodbye.</lang>

MUMPS

<lang MUMPS>Write "Goodbye, World.",!</lang>


newLISP

Works with: newLisp version 6.1 and after

<lang lisp>(println "Goodbye, World!")</lang>

Nimrod

<lang python>echo("Goodbye, World!")</lang>

Objective-C

Works with: GCC

To print to stdout: <lang objc>printf("Goodbye, World!");</lang>

To log a time-stamped message to the Console: <lang objc>NSLog(@"Goodbye, World!");</lang>

OCaml

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

Octave

<lang octave>disp("Goodbye, world");</lang>

Or, using C-style function printf:

<lang octave>printf("Goodbye, world\n");</lang>

Oz

In the REPL: <lang oz>{System.showInfo "Goodbye, World!"}</lang>

As a complete program: <lang oz>functor import Application System define

  {System.showInfo "Goodbye, World!"}
  {Application.exit 0}

end</lang>

Pascal

Works with: Free Pascal

<lang pascal>program byeworld; begin

writeln('Goodbye, World!');

end.</lang>

Perl

Works with: Perl version 5.8.8

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

Works with: Perl version 5.10.x

Backported from Perl 6: <lang perl>use feature 'say'; say 'Goodbye, World!';</lang>

or: <lang perl>use 5.010; say 'Goodbye, World!';</lang>

Perl 6

<lang perl6>say 'Goodbye, World!';</lang>

PDP-11 Assembly

Works with: UNIX version 7

This is tested on Unix v7 Prints "Goodbye, World!" to stdout:

<lang assembly>.globl start .text start:

       mov	$1,r0

sys 4; outtext; outlen sys 1 rts pc

.data outtext: <Goodbye, World!\n> outlen = . - outtext</lang>

PHP

<lang php><?php echo "Goodbye, World!\n"; ?></lang> Alternatively, any text outside of the <?php ?> tags will be automatically echoed: <lang php>Goodbye, World!</lang>

PicoLisp

<lang PicoLisp>(prinl "Goodbye, World!")</lang>

PL/I

<lang PL/I> display ('Goodbye world'); </lang>

Prolog

<lang prolog>:- write('Goodbye, World', nl).</lang>

Pop11

<lang pop11>printf('Goodbye, World!\n');</lang>

Pike

<lang pike>int main(){

  write("Goodbye, world!\n");

}</lang>

PostScript

The "==" and "=" operators display the topmost element of the stack with or without processing, followed by a newline. Thus:

<lang postscript>(Goodbye, World!) ==</lang>

will display the string "(Goodbye, World!)" while

<lang postscript>(Goodbye, World!) =</lang>

will display the content of the string "(Goodbye, World!)"; that is, "Goodbye, World!".

To print a string without the following newline, use

<lang postscript>(Goodbye, World!) print</lang>

PowerShell

<lang powershell>Write-Host "Goodbye, World!"

  1. For extra flair, you can specify colored output

Write-Host "Goodbye, World!" -foregroundcolor red</lang>

PureBasic

<lang PureBasic> OpenConsole() PrintN("Goodbye, World!") Input() ; Wait for enter </lang>

Python

Works with: Python version 2.4

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

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

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

Works with: Python version 3.0

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

R

<lang R> cat("Goodbye, World!\n")</lang>

Raven

<lang raven>'Goodbye, World!' print</lang>

REBOL

<lang REBOL>print "Goodbye, World!"</lang>

REXX

<lang rexx>/* goodbye program */ say 'Goodbye, World!'</lang>

Ruby

Works with: Ruby version 1.8.4

<lang ruby>puts "Goodbye, World!"</lang> or <lang ruby>$stdout.puts "Goodbye, World!"</lang>


Sather

<lang sather> class GOODBYE_WORLD is

main is 
 #OUT+"Goodbye, World!\n"; 
end; 

end; </lang>

sed

<lang sed>cGoodbye, World!</lang>

Seed7

<lang seed7>$ include "seed7_05.s7i";

const proc: main is func

 begin
   writeln("Goodbye, World!");
 end func;</lang>

Scheme

Works with: Gauche

<lang scheme>(display "Goodbye, world!") (newline)</lang> or <lang scheme>(print "Goodbye, world!")</lang>

SIMPOL

<lang simpol>function main() end function "Goodbye, world!{d}{a}"</lang>

Slate

<lang slate>inform: 'Goodbye, world!'.</lang>

Smalltalk

<lang smalltalk>Transcript show: 'Goodbye, world!'; cr.</lang>

Works with: GNU Smalltalk

<lang smalltalk>'Goodbye, world!' printNl.</lang>

SNOBOL4

Using CSnobol4 dialect <lang snobol4>

   OUTPUT = "Hello World"

END </lang>

SNUSP

<lang snusp>@\G.@\o.o.@\d.--b.@\y.@\e.>@\comma.@\.<-@\W.+@\o.+++r.------l.@\d.>+.! #

|   |     \@------|#  |    \@@+@@++|+++#-    \\               -
|   \@@@@=+++++#  |   \===--------!\===!\-----|-------#-------/
\@@+@@@+++++#     \!#+++++++++++++++++++++++#!/</lang>

Standard ML

<lang sml>print "Goodbye, World!\n"</lang>

Suneido

<lang Suneido>Print("Hello World!")</lang>

Transact-SQL

<lang sql>PRINT "Goodbye, world!"</lang>

Tcl

Output to terminal: <lang tcl>puts "Goodbye, World"</lang>

Output to arbitrary open, writable file: <lang tcl>puts $fileID "Goodbye, World"</lang>

TI-83 BASIC

See TI-89 BASIC.

TI-89 BASIC

<lang ti89b>Disp "Goodbye, World!"</lang>


UNIX Shell

Works with: Bourne Again SHell

<lang bash>#!/bin/bash echo "Goodbye World!"</lang>

Unlambda

<lang unlambda>`r``````````````.G.o.o.d.b.y.e.,. .W.o.r.l.di</lang>

Ursala

output as a side effect of compilation <lang Ursala>#show+

main = -[Goodbye, World!]-</lang> output by a compiled executable <lang Ursala>#import std

  1. executable ('parameterized',)

main = <file[contents: -[Goodbye, World!]-]>!</lang>


V

<lang v>"Goodbye! world" puts</lang>

VBScript

Works with: Windows Script Host version 5.7

<lang VBScript>WScript.Echo("Goodbye, World!")</lang>

Vedit macro language

<lang vedit>Message("Goodbye, World!")</lang>

X86 Assembly

Works with: nasm version 2.05.01

This is known to work on Linux, it may or may not work on other Unix-like systems

Prints "Goodbye, World!" to stdout (and there is probably an even simpler version): <lang assembly>section .data msg db 'Goodbye, World!', 0AH len equ $-msg

section .text global _start _start: mov edx, len

       mov     ecx, msg
       mov     ebx, 1
       mov     eax, 4
       int     80h
       mov     ebx, 0
       mov     eax, 1
       int     80h</lang>

XSLT

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

Quill

<lang quill>"Goodbye, World!" print</lang>

Yoric

<lang yoric>write, stdout, "Goodbye,World"</lang>