Hello, World: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Hello, World
| Old | New | Line | |
|---|---|---|---|
| 1 | + | **Hello, World** refers to a trivial [[Program|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]]. | |
| 2 | + | ||
| 3 | + | ## standard source code | |
| 4 | + | ||
| 5 | + | The following [[Source code|source code]] is a minimal, yet complete *Hello, World* fully-compliant to [[Standard Pascal]] (ISO standard 7185): | |
| 6 | + | ||
| 7 | + | ``` pascal | |
| 8 | + | program helloWorld(output); | |
| 9 | + | begin | |
| 10 | + | writeLn('Hello, World!') | |
| 11 | + | end. | |
| 12 | + | ``` | |
| 13 | + | ||
| 14 | + | Compilation with the [[FPC]] is as simple as that: | |
| 15 | + | ||
| 16 | + | ```text | |
| 17 | + | $ fpc helloWorld.pas | |
| 18 | + | Target OS: Linux for x86-64 | |
| 19 | + | Compiling helloWorld.pas | |
| 20 | + | Linking helloWorld | |
| 21 | + | 4 lines compiled, 0.1 sec | |
| 22 | + | ``` | |
| 23 | + | ||
| 24 | + | ## line-by-line description | |
| 25 | + | ||
| 26 | + | ### header | |
| 27 | + | ||
| 28 | + | 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|unit]] and `library`. | |
| 29 | + | ||
| 30 | + | The next word provides an [[Identifier|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. | |
| 31 | + | ||
| 32 | + | After that comes a parameter list. Here this parameter list enumerates one item, [[Output|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|console]]. | |
| 33 | + | ||
| 34 | + | The header is *separated* from the following [[Block|block]] by a [[Semicolon|semicolon]]. | |
| 35 | + | ||
| 36 | + | ### definition | |
| 37 | + | ||
| 38 | + | Following the header comes the `program` definition. A `program` is defined with a block. Every block has to have exactly one `begin … end` [[Frame|frame]]. The FPC also accepts `asm … end` ([[Assembly language|assembly language]]) frames for [[Routine|routines]]. | |
| 39 | + | ||
| 40 | + | In our program this frame contains one [[statement]]: A call of the built-in [[Procedure|procedure]] [[Write|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]]. | |
| 41 | + | ||
| 42 | + | The `program` definition concludes with a [[period]]. | |
| 43 | + | ||
| 44 | + | ## degenerate examples | |
| 45 | + | ||
| 46 | + | These examples are meant to demonstrate a point. They do not appear in production programs. | |
| 47 | + | ||
| 48 | + | ### whitespace | |
| 49 | + | ||
| 50 | + | 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): | |
| 51 | + | ||
| 52 | + | ``` pascal | |
| 53 | + | program helloWorld (output) ; | |
| 54 | + | begin | |
| 55 | + | writeLn ( 'Hello, world!' ) | |
| 56 | + | ||
| 57 | + | end . | |
| 58 | + | ``` | |
| 59 | + | ||
| 60 | + | ### case-insensitive | |
| 61 | + | ||
| 62 | + | Pascal is case-insensitive. This program has *exactly* the same meaning and effect as the standard source code: | |
| 63 | + | ||
| 64 | + | ``` pascal | |
| 65 | + | PrOgRaM HeLLoWorLd(oUtpUt); | |
| 66 | + | begIn | |
| 67 | + | wRiTelN('Hello, world!') | |
| 68 | + | EnD. | |
| 69 | + | ``` | |
| 70 | + | ||
| 71 | + | ## see also | |
| 72 | + | ||
| 73 | + | - [[Using resourcestrings]] for an internationalized (= translated/translatable) *Hello, World* | |
| 74 | + | - [[Basic Pascal Tutorial/Hello, World|Hello, World]] in the [[Basic Pascal Tutorial]] | |
| 75 | + | - [Hello, world](https://RosettaCode.org/wiki/Hello_world/Text#Pascal) in the *Rosetta code* project | |
| 76 | + | - [[Programming in Symbian OS]] for *Hello, World* using the Symbian OS API | |
| 77 | + | - [[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]]) | |
| 78 | + | - [[Free Pascal videos|Video]]: [Hello, World](https://www.youtube.com/watch?v=dVkoeoIpGlE) in Pascal on *YouTube* | |
| 79 | + | ||
| 80 | + | --- | |
| 81 | + | *From the Free Pascal wiki, page "Hello, World", as it stood on 2022-08-29 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 82 | + | Category: Code | |
| 83 | + | Category: Pascal |
