Difference between revisions of "Hello, World"

From Lazarus wiki
Jump to navigationJump to search
(Kai Burghardt moved page Hello, World to Basic Pascal Tutorial/Hello, World: tidy up main name space: create subpage hierarchy for basic Pascal tutorial [cf. [[Special: PermaLink/149778#Cluttering of mai...)
Tag: New redirect
 
(remove redirect to Basic Pascal Tutorial/Hello, World and write an article that serves as a single entry point for newcomers)
Tag: Removed redirect
Line 1: Line 1:
#REDIRECT [[Basic Pascal Tutorial/Hello, World]]
+
'''Hello, World''' refers to a trivial [[Program|program]] printing <syntaxhighlight lang="text" inline>Hello, World!</syntaxhighlight> to some standard means of output.
 +
It is used to illustrate some basic characteristics of a programming language.
 +
This page elaborates a ''Hello, World'' in [[Pascal]].
 +
 
 +
== standard source code ==
 +
The following [[Source code|source code]] is a minimal, yet complete ''Hello, World'' fully-compliant to [[Standard Pascal]] (ISO standard 7185):
 +
<syntaxhighlight lang="pascal" line>program helloWorld(output);
 +
begin
 +
writeLn('Hello, World!')
 +
end.</syntaxhighlight>
 +
Compilation with the [[FPC]] is as simple as that:
 +
<syntaxhighlight lang="text">$ fpc helloWorld.pas
 +
Target OS: Linux for x86-64
 +
Compiling helloWorld.pas
 +
Linking helloWorld
 +
4 lines compiled, 0.1 sec</syntaxhighlight>
 +
 
 +
== line-by-line description ==
 +
=== header ===
 +
Every Pascal source code file starts off with a word identifying the kind of source code.
 +
Here, this kind is <syntaxhighlight lang="pascal" inline>program</syntaxhighlight>.
 +
In [[Extended Pascal]] (ISO standard 10206) <syntaxhighlight lang="pascal" inline>module</syntaxhighlight> is possible, too.
 +
As of 2022, the [[FPC]] supports, beside <syntaxhighlight lang="pascal" inline>program</syntaxhighlight>, only two other kinds: [[Unit|<syntaxhighlight lang="delphi" inline>unit</syntaxhighlight>]] and <syntaxhighlight lang="delphi" inline>library</syntaxhighlight>.
 +
 
 +
The next word provides an [[Identifier|identifier]] for this <syntaxhighlight lang="pascal" inline>program</syntaxhighlight> (or <syntaxhighlight lang="pascal" inline>module</syntaxhighlight>).
 +
As per ISO standards, this identifier has no significance.
 +
You ''could'' reuse the identifier <syntaxhighlight lang="pascal" inline>helloWorld</syntaxhighlight> in the following lines.
 +
The FPC, however, reserves this identifier for use in fully-qualified identifiers.
 +
 
 +
After that comes a parameter list.
 +
Here this parameter list enumerates one item, [[Output|<syntaxhighlight lang="pascal" inline>output</syntaxhighlight>]].
 +
Parameters of the spelling <syntaxhighlight lang="pascal" inline>input</syntaxhighlight> and <syntaxhighlight lang="pascal" inline>output</syntaxhighlight> have special meaning.
 +
They refer to an implementation-defined standard means of accessing the user interface, that means usually the [[Console|console]].
 +
 
 +
The header is ''separated'' from the following [[Block|block]] by a [[Semicolon|semicolon]].
 +
 
 +
=== definition ===
 +
Following the header comes the <syntaxhighlight lang="pascal" inline>program</syntaxhighlight> definition.
 +
A <syntaxhighlight lang="pascal" inline>program</syntaxhighlight> is defined with a block.
 +
Every block has to have exactly one <syntaxhighlight lang="pascal" inline>begin … end</syntaxhighlight> [[Frame|frame]].
 +
The FPC also accepts <syntaxhighlight lang="pascal" inline>asm … end</syntaxhighlight> ([[Assembly language|assembly language]]) frames for [[Routine|routines]].
 +
 
 +
In our program this frame contains one [[statement]]:
 +
A call of the built-in [[Procedure|procedure]] [[Write|<syntaxhighlight lang="pascal" inline>writeLn</syntaxhighlight>]], short for ''write line''.
 +
Thereafter follows a non-empty comma-separated list of actual parameters.
 +
Here we have one string literal <syntaxhighlight lang="pascal" inline>'Hello, world!'</syntaxhighlight>.
 +
String literals are delimited by [['|typewriter straight quotes]].
 +
 
 +
The <syntaxhighlight lang="pascal" inline>program</syntaxhighlight> definition concludes with a [[period#module end|period]].
 +
 
 +
== degenerate examples ==
 +
These examples are meant to demonstrate a point.
 +
They do not appear in production programs.
 +
 
 +
=== whitespace ===
 +
White space (blanks or newlines) has no significance to the meaning to the program, as long as it does not interfere with words or literal values (i.&#8239;e. number or string constants):
 +
<syntaxhighlight lang="pascal"> program  helloWorld (output) ;
 +
        begin
 +
  writeLn  ( 'Hello, world!' )
 +
 
 +
                          end .</syntaxhighlight>
 +
 
 +
=== case-insensitive ===
 +
Pascal is case-insensitive.
 +
This program has ''exactly'' the same meaning and effect as the [[#standard source code|standard source code]]:
 +
<syntaxhighlight lang="pascal">PrOgRaM HeLLoWorLd(oUtpUt);
 +
begIn
 +
wRiTelN('Hello, world!')
 +
EnD.</syntaxhighlight>
 +
 
 +
== see also ==
 +
* [[Using resourcestrings]] for an internationalized ''Hello, World''
 +
* [[Basic Pascal Tutorial/Hello, World|Hello, World]] in the [[Basic Pascal Tutorial]]
 +
* [https://RosettaCode.org/wiki/Hello_world/Text#Pascal Hello, world] in the ''Rosetta code'' project
 +
* [[Programming in Symbian OS#Hello World|Programming in Symbian OS]] for ''Hello, World'' using the Symbian OS API
 +
* [[Howdy World (Hello World on steroids)|Howdy World]]: ''Hello, World''-inspired tutorial for using a graphical user interface and the [[Lazarus]] integrated development environment ([[IDE]])
 +
* [[Free Pascal videos|Video]: [https://www.youtube.com/watch?v=dVkoeoIpGlE Hello, World] in Pascal on ''YouTube''
 +
 
 +
[[Category: Pascal]]
 +
[[Category: Code]]

Revision as of 15:15, 29 August 2022

Hello, World refers to a trivial program printing Hello, World! to some standard means of output. It is used to illustrate some basic characteristics of a programming language. This page elaborates a Hello, World in Pascal.

standard source code

The following source code is a minimal, yet complete Hello, World fully-compliant to Standard Pascal (ISO standard 7185):

1program helloWorld(output);
2begin
3	writeLn('Hello, World!')
4end.

Compilation with the FPC is as simple as that:

$ fpc helloWorld.pas
Target OS: Linux for x86-64
Compiling helloWorld.pas
Linking helloWorld
4 lines compiled, 0.1 sec

line-by-line description

header

Every Pascal source code file starts off with a word identifying the kind of source code. Here, this kind is program. In Extended Pascal (ISO standard 10206) module is possible, too. As of 2022, the FPC supports, beside program, only two other kinds: unit and library.

The next word provides an identifier for this program (or module). As per ISO standards, this identifier has no significance. You could reuse the identifier helloWorld in the following lines. The FPC, however, reserves this identifier for use in fully-qualified identifiers.

After that comes a parameter list. Here this parameter list enumerates one item, output. Parameters of the spelling input and output have special meaning. They refer to an implementation-defined standard means of accessing the user interface, that means usually the console.

The header is separated from the following block by a semicolon.

definition

Following the header comes the program definition. A program is defined with a block. Every block has to have exactly one begin  end frame. The FPC also accepts asm  end (assembly language) frames for routines.

In our program this frame contains one statement: A call of the built-in procedure writeLn, short for write line. Thereafter follows a non-empty comma-separated list of actual parameters. Here we have one string literal 'Hello, world!'. String literals are delimited by typewriter straight quotes.

The program definition concludes with a period.

degenerate examples

These examples are meant to demonstrate a point. They do not appear in production programs.

whitespace

White space (blanks or newlines) has no significance to the meaning to the program, as long as it does not interfere with words or literal values (i. e. number or string constants):

 program  helloWorld (output) ;
        begin
  writeLn   ( 'Hello, world!' )
  
                          end .

case-insensitive

Pascal is case-insensitive. This program has exactly the same meaning and effect as the standard source code:

PrOgRaM HeLLoWorLd(oUtpUt);
begIn
	wRiTelN('Hello, world!')
EnD.

see also