Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 1/Identifiers: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
111B - Identifiers (author: Tao Yue, state: changed)
22
33Identifiers are names that allow you to reference stored values, such as variables and constants. Also, every program must be identified (get it?) by an identifier.
44
55Rules for identifiers:
66
77- Must begin with a letter (a..z or A..Z, Pascal is case insensitive) from the English alphabet or an underscore (_).
88- Can be followed by zero or more letters (a..Z), digits (0..9), or underscores (_), in any combination.
99- Cannot be the same as a [[Keyword|keyword]] such as `begin`, `for`, `case`, `absolute` etc.
1010- May not contain special characters, such as:
1111
12-```
12+```text
1313 ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \ (or the space character)
1414```
1515
1616# Reserved words
1717
1818Several identifiers are reserved in Pascal -- you cannot use them as your own identifiers. According to the [FPC Reference](http://lazarus-ccr.sourceforge.net/fpcdoc/ref/ref.html) they are grouped in:
1919
2020- Turbo Pascal reserved words
2121- Delphi reserved words
2222- FPC reserved words
2323
2424### Turbo Pascal reserved words
2525
2626| | | | | | | | |
2727|----|----|----|----|----|----|----|----|
2828| absolute | and | array | asm | begin | break | case | const |
2929| constructor | continue | destructor | div | do | downto | else | end |
3030| file | for | function | goto | if | implementation | in | inherited |
3131| inline | interface | label | mod | nil | not | object | of |
3232| on | operator | or | packed | procedure | program | record | reintroduce |
3333| repeat | self | set | shl | shr | string | then | to |
3434| type | unit | until | uses | var | while | with | xor |
3535
3636### Delphi reserved words
3737
3838The Delphi (II) reserved words are the same as the pascal ones, plus the following ones:
3939
4040| | | | | | | |
4141|-----|---------|--------|----------|--------------|-----------|----------------|
4242| as | class | except | exports | finalization | finally | initialization |
4343| is | library | on | property | raise | threadvar | try |
4444
4545### Free Pascal reserved words
4646
4747On top of the Turbo Pascal and Delphi reserved words, Free Pascal also considers the following as reserved words:
4848
4949| | | | | | | |
5050|---------|------|-------|-----|------|-------|----------|
5151| dispose | exit | false | new | true | break | continue |
5252
5353Also, Pascal has several pre-defined identifiers. You can replace them with your own definitions, but then you'd be deleting part of the functionality of Pascal.
5454
5555| | | | | | | | |
5656|-------|-------------|---------|---------|------|---------|--------|------|
5757| abs | arctan | boolean | char | cos | dispose | eof | eoln |
5858| exp | false | input | integer | ln | maxint | new | odd |
5959| ord | output | pack | page | pred | read | readln | real |
6060| reset | rewrite | round | sin | sqr | sqrt | succ | text |
6161| true | trunc write | writeln | | | | | |
6262
6363Pascal is not case sensitive! , , and are equivalent. But for readability purposes, it is a good idea to use meaningful capitalization!
6464
6565There are two possible methods you could choose to apply to your identifiers: CamelCase and underscore as space. CamelCase, as it appears, means that separate words in an identifier are capitalized, so that you have or instead of . Using underscore as space means you separate words in an identifier with underscores, so that you have instead of . Or you could combine the two, so that you have or instead of .
6666
6767Identifiers can be any length, but many Pascal compilers will only look at the first 32 characters or so. That is,
6868
69-```
69+```text
7070 ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFAlphaBeta
7171 ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGammaDelta
7272```
7373
7474may be equivalent to some Pascal compilers because the differences begin in the 33rd character. Free Pascal limits [identifiers](http://www.freepascal.org/docs-html/3.0.0/ref/refse4.html#x16-150001.4) to 127 characters.
7575
7676This is extremely generous. The original Pascal compiler for the CDC 6000 mainframe only noticed the first 10 characters of an identifier. This was because the CDC had a 60 bit word, and by using 6 bit characters (all upper case letters plus digits and some punctuation) an identifier could fit in one word. You could have more than 10 characters in an identifier, but only the first 10 counted, so and would be considered the same.
7777
7878To make your code compilable by all compilers, use a reasonable length for identifiers -- up to 15 characters. That way, you'll also save on typing.
7979
8080While it is a good idea to make identifiers to be mnemonic with the use of longer names, there is nothing wrong with using very short identifiers in specific uses. it is extremely common to use `I, J,`and `K` as the control variable in a [[For|for]] loop.
8181
8282---
8383*From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 1/Identifiers", as it stood on 2022-08-20 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).*

Back to history