Hello world/Text

From Rosetta Code

Jump to: navigation, search
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

Contents

[edit] 4DOS Batch

echo Goodbye, World!

[edit] 6502 Assembly

; helloworld.s for C= 8-bit machines, ca65 assembler format.
; String printing limited to strings of 256 characters or less.
 
a_cr = $0d ; Carriage return.
bsout = $ffd2 ; KERNAL ROM, output a character to current device.
 
.code
 
ldx #0 ; Starting index 0 in X register.
printnext:
lda text,x ; Get character from string.
beq done ; If we read a 0 we're done.
jsr bsout ; Output character.
inx ; Increment index to next character.
bne printnext ; Repeat if index doesn't overflow to 0.
done:
rts ; Return from subroutine.
 
.rodata
 
text:
.byte "Hello, world!", a_cr, 0

[edit] 8086 Assembly

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

[edit] ABAP

REPORT zgoodbyeworld.
WRITE 'Goodbye, World!'.

[edit] ActionScript

trace("Goodbye, World!");

[edit] Ada

Works with: GCC version 4.1.2

with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
begin
Put_Line ("Goodbye, World!");
end Main;

[edit] Aikido

println ("Goodbye, World!")

[edit] Algae

printf("Goodbye, World\n");

[edit] ALGOL 68

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

[edit] AmigaE

PROC main()
WriteF('Goodbye, World!\n')
ENDPROC

[edit] AppleScript

To show in Script Editor Result pane:

"Goodbye, World!"

To show in Script Editor Event Log pane:

log "Goodbye, World!"

[edit] Argile

use std
print "Goodbye, World!"

compile with: arc hello_world.arg -o hello_world.c && gcc -o hello_world hello_world.c

[edit] AutoHotkey

script launched from windows explorer

DllCall("AllocConsole")
FileAppend, Goodbye`, World!, CONOUT$
FileReadLine, _, CONIN$, 1

scripts run from shell [requires Windows XP or higher; older Versions of Windows don“t have the "AttachConsole" function]

DllCall("AttachConsole", "int", -1)
FileAppend, Goodbye`, World!, CONOUT$
SendInput Goodbye, World{!}

[edit] AWK

BEGIN{print "Goodbye, World!"}

Here there is no significant difference between BEGIN and END, as the input is empty. So this version is shorter:

END{print"Hello, world!"}

[edit] BASIC

Works with: BASICA

10 print "Goodbye World!"

Works with: QuickBasic version 4.5

PRINT "Goodbye, World!"

[edit] Batch File

echo Goodbye, World!

[edit] BCPL

GET "libhdr"
 
LET start() = VALOF
{ writef("Goodbye, World!")
RESULTIS 0
}

[edit] Befunge

0"!dlrow ,eybdooG">:#,_@

[edit] Brace

#!/usr/bin/env bx
use b
Main:
say("Goodbye, World!")

[edit] 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:

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

Uncommented:

++++++++++[>+>+++>++++>+++++++>++++++++>+++++++++>++
++++++++>+++++++++++>++++++++++++<<<<<<<<<-]>>>>+.>>>
>+..<.<++++++++.>>>+.<<+.<<<<++++.<++.>>>+++++++.>>>.+++.
<+++++++.--------.<<<<<+.<+++.---.

It can most likely be optimized, but this is a nice way to show how character printing works in Brainf*** :)

[edit] C

Works with: gcc version 4.0.1

#include <stdio.h>
 
int main(int argc, char **argv)
{
printf("Goodbye, World!\n");
 
return 0;
}

Or:

int main(int argc, char **argv){
puts("Goodbye, World!");
return 0;
}

[edit] C#

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

System.Console.WriteLine("Goodbye, World!");

[edit] C++

#include <iostream>
 
int main () {
std::cout << "Goodbye, World!" << std::endl;
return std::cout.bad();
}

[edit] 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.

[edit] Clay

main() {
println("Goodbye, world!");
}

[edit] Clean

Start = "Goodbye, World!"

[edit] Clojure

(println "Goodbye, world!")

[edit] Cobra

class Hello
def main
print 'Goodbye, World'

[edit] COBOL

Using fixed format. Works with: cobc (OpenCOBOL) 1.1.20090206

	program-id. hello.
procedure division.
display "Goodbye, world!".
stop run.

[edit] Common Lisp

(format t "Goodbye, world!~%")

[edit] D

Library: tango

import tango.io.Console
 
void main()
{
Cout("Goodbye, World!").newline;
}

[edit] Dao

io.writeln( 'Goodbye, World!' )

[edit] dc

[Goodbye, World!]p

[edit] E

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

[edit] eC

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

[edit] Efene

short version (without a function)

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

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

@public 
run = fn () {
io.format("Goodbye, world~n")
}

[edit] elastiC

From the elastiC Manual.

package hello;
 
// Import the `basic' package
import basic;
 
// Define a simple function
function hello()
{
// Print hello world
basic.print( "Goodbye, world!\n" );
}
 
/*
* Here we start to execute package code
*/
 
// Invoke the `hello' function
hello();

[edit] Erlang

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

[edit] Factor

"Goodbye, world." print

[edit] Falcon

> "Goodbye, World!"

[edit] FALSE

"Goodbye, World!
"

[edit] ferite

uses "console";
Console.println( "Goodby, World" );

[edit] Forth

." Goodbye, World!"

Or as a whole program:

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

[edit] 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".

[edit] Fortress

export Executable                                                                                                                       
 
run() = println("Goodbye, world!")

[edit] F#

printfn "%s" "Goodbye, world"

or using .Net classes directly

System.Console.WriteLine("Goodbye, World!")

[edit] Gema

Gema ia a preprocessor that reads an input file and writes an output file. This code will write "Goodby, World!' no natter what input is given.

*= ! ignore off content of input
\B=Goodby, World\! ! Start output with this text.

[edit] Glee

"Goodbye, World!"

[edit] Go

package main
 
import "fmt"
 
func main() { fmt.Println("Goodbye, World!") }

[edit] Haskell

main = putStrLn "Goodbye, world"

[edit] HicEst

WRITE() 'Goodbye, World!'

[edit] HLA

program goodbyeWorld;
#include("stdlib.hhf")
begin goodbyeWorld;
 
stdout.put( "Goodbye, World!" nl );
 
end goodbyeWorld;

[edit] Icon and Unicon

[edit] Icon

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

[edit] Unicon

This Icon solution works in Unicon.

[edit] IDL

print,'Goodbye World'

[edit] Io

"Goodbye, world!" println

[edit] Ioke

"Goodbye, World!" println

[edit] J

   'Goodbye, World!'
Goodbye, World!

Here are some redundant alternatives:

   [data=. 'Goodbye, World!'
Goodbye, World!
data
Goodbye, World!
smoutput data
Goodbye, World!

[edit] Java

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

[edit] JavaScript

Works with: Firefox version 2.0

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

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

print('Hello, World!');

Works with: JScript

WScript.Echo("Hello, World!");

[edit] Joy

"Goodbye, World!" putchars.

[edit] Liberty BASIC

print "Goodbye, World!"

[edit] Limbo

implement Command;
 
include "sys.m";
sys: Sys;
 
include "draw.m";
 
include "sh.m";
 
init(nil: ref Draw->Context, nil: list of string)
{
sys = load Sys Sys->PATH;
sys->print("Goodby, World!\n");
}

[edit] 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";);

[edit] Logo

Print includes a line feed:

print [Goodbye, world!]

Type does not:

type [Goodbye, world!]

[edit] LSE64

" Goodbye, World!" ,t nl

[edit] Lua

Works with: Lua version 5.1.1

print("Goodbye, World!")

or:

print "Goodbye, World!"

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.

[edit] M4

For the particular nature of m4, this is simply:

`Goodbye, World'

[edit] Mathematica

Print["Goodbye, World!"]

[edit] MATLAB

>> 'Goodbye, World!'
 
ans =
 
Goodbye, World!

[edit] MAXScript

print "Goodbye, World!"

or:

format "%" "Goodbye, World!"

[edit] Mercury

:- module hello.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
 
:- implementation.
main(!IO) :-
io.write_string("Goodbye, World!\n", !IO).

[edit] Metafont

message "Goodbye, World"; end

[edit] MIPS Assembly

Works with: MARS and Works with: SPIM

   .data
hello: .asciiz "Goodbye, world!"
 
.text
main:
la $a0, hello
li $v0, 4
syscall
li $v0, 10
syscall

[edit] mIRC Scripting Language

Works with: mIRC

alias saygoodbye { echo -a Goodbye! }

[edit] Modula-3

MODULE Goodbye EXPORTS Main;
 
IMPORT IO;
 
BEGIN
IO.Put("Goodbye, World!\n");
END Goodbye.

[edit] MUMPS

Write "Goodbye, World.",!

[edit] newLISP

Works with: newLisp version 6.1 and after

(println "Goodbye, World!")

[edit] Nimrod

echo("Goodbye, World!")

[edit] Objeck

bundle Default {
class SayHello {
function : Main(args : String[]) ~ Nil {
"Hello World!"->PrintLine();
}
}
}

[edit] Objective-C

Works with: GCC To print to stdout:

printf("Goodbye, World!");

To log a time-stamped message to the Console:

NSLog(@"Goodbye, World!");

[edit] OCaml

print_endline "Goodbye, World!"

[edit] Octave

disp("Goodbye, world");

Or, using C-style function printf:

printf("Goodbye, world\n");

[edit] Onyx

`Hello world!\n' print

[edit] Oz

In the REPL:

{System.showInfo "Goodbye, World!"}

As a complete program:

functor
import Application System
define
{System.showInfo "Goodbye, World!"}
{Application.exit 0}
end

[edit] Pascal

Works with: Free Pascal

program byeworld;
begin
writeln('Goodbye, World!');
end.

[edit] Perl

Works with: Perl version 5.8.8

print "Goodbye, World!\n";

Works with: Perl version 5.10.x Backported from Perl 6:

use feature 'say';
say 'Goodbye, World!';

or:

use 5.010;
say 'Goodbye, World!';

[edit] Perl 6

say 'Goodbye, World!';

[edit] PDP-11 Assembly

Works with: UNIX version 7

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

.globl  start
.text
start:
mov $1,r0
sys 4; outtext; outlen
sys 1
rts pc
 
.data
outtext: <Goodbye, World!\n>
outlen = . - outtext

[edit] PHP

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

Alternatively, any text outside of the <?php ?> tags will be automatically echoed:

Goodbye, World!

[edit] PicoLisp

(prinl "Goodbye, World!")

[edit] PL/I

put ('Goodbye, World');

[edit] Prolog

:- write('Goodbye, World', nl).

[edit] Pop11

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

[edit] Pike

int main(){
write("Goodbye, world!\n");
}

[edit] PostScript

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

(Goodbye, World!) ==

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

(Goodbye, World!) =

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

To print a string without the following newline, use

(Goodbye, World!) print

[edit] PowerShell

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

[edit] PureBasic

OpenConsole()
PrintN("Goodbye, World!")
Input() ; Wait for enter

[edit] Python

Works with: Python version 2.4

print "Goodbye, World!"

The same using sys.stdout

import sys
sys.stdout.write("Goodbye, World!\n")

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

Works with: Python version 3.0

print("Goodbye, World!")

[edit] R

 cat("Goodbye, World!\n")

[edit] Raven

'Goodbye, World!' print

[edit] REBOL

print "Goodbye, World!"

[edit] REXX

/* goodbye program */
say 'Goodbye, World!'

[edit] RTL/2

TITLE Goodbye World;
 
LET NL=10;
 
EXT PROC(REF ARRAY BYTE) TWRT;
 
ENT PROC INT RRJOB();
 
TWRT("Goodbye, World!#NL#");
RETURN(1);
 
ENDPROC;

[edit] Ruby

Works with: Ruby version 1.8.4

puts "Goodbye, World!"

or

$stdout.puts "Goodbye, World!"

[edit] Sather

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

[edit] sed

cGoodbye, World!

[edit] Seed7

$ include "seed7_05.s7i";
 
const proc: main is func
begin
writeln("Goodbye, World!");
end func;

[edit] Scala

println("Goodbye, World!")

[edit] Scheme

Works with: Gauche

(display "Goodbye, world!")
(newline)

or

(print "Goodbye, world!")

[edit] SIMPOL

function main()
end function "Goodbye, world!{d}{a}"

[edit] Sisal

define main
 
% Sisal doesn't yet have a string built-in.
% Let's define one as an array of characters.
 
type string = array[character];
 
function main(returns string)
"Hello world!"
end function

[edit] Slate

inform: 'Goodbye, world!'.

[edit] Smalltalk

Transcript show: 'Goodbye, world!'; cr.

Works with: GNU Smalltalk

'Goodbye, world!' printNl.

[edit] SNOBOL4

Using CSnobol4 dialect

    OUTPUT = "Hello World"
END

[edit] SNUSP

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

[edit] Standard ML

print "Goodbye, World!\n"

[edit] Suneido

Print("Hello World!")

[edit] Transact-SQL

PRINT "Goodbye, world!"

[edit] Tcl

Output to terminal:

puts "Goodbye, World"

Output to arbitrary open, writable file:

puts $fileID "Goodbye, World"

[edit] TI-83 BASIC

See TI-89 BASIC.

[edit] TI-89 BASIC

Disp "Goodbye, World!"

[edit] Trith

"Goodbye, World!" print

[edit] UNIX Shell

Works with: Bourne Again SHell

#!/bin/bash
echo "Goodbye World!"

[edit] Unlambda

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

[edit] Ursala

output as a side effect of compilation

#show+
 
main = -[Goodbye, World!]-

output by a compiled executable

#import std
 
#executable ('parameterized','')
 
main = <file[contents: -[Goodbye, World!]-]>!

[edit] V

"Goodbye! world" puts

[edit] VBScript

Works with: Windows Script Host version 5.7

WScript.Echo("Goodbye, World!")

[edit] Vedit macro language

Message("Goodbye, World!")

[edit] Whenever

1 print("Goodbye, world!");

[edit] 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):

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

[edit] XSLT

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

[edit] Quill

"Goodbye, World!" print

[edit] Yoric

write, stdout, "Goodbye,World"
Personal tools
Support