Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 1/Identifiers: what changed

Revision 1 to 2. 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-``  ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \ (or the space character) ``
12+```
13+ ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \ (or the space character)
14+```
1315
1416# Reserved words
1517
1618Several 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:
1719
1820- Turbo Pascal reserved words
1921- Delphi reserved words
2022- FPC reserved words
2123
2224### Turbo Pascal reserved words
2325
2426| | | | | | | | |
2527|----|----|----|----|----|----|----|----|
2628| absolute | and | array | asm | begin | break | case | const |
2729| constructor | continue | destructor | div | do | downto | else | end |
2830| file | for | function | goto | if | implementation | in | inherited |
2931| inline | interface | label | mod | nil | not | object | of |
3032| on | operator | or | packed | procedure | program | record | reintroduce |
3133| repeat | self | set | shl | shr | string | then | to |
3234| type | unit | until | uses | var | while | with | xor |
3335
3436### Delphi reserved words
3537
3638The Delphi (II) reserved words are the same as the pascal ones, plus the following ones:
3739
3840| | | | | | | |
3941|-----|---------|--------|----------|--------------|-----------|----------------|
4042| as | class | except | exports | finalization | finally | initialization |
4143| is | library | on | property | raise | threadvar | try |
4244
4345### Free Pascal reserved words
4446
4547On top of the Turbo Pascal and Delphi reserved words, Free Pascal also considers the following as reserved words:
4648
4749| | | | | | | |
4850|---------|------|-------|-----|------|-------|----------|
4951| dispose | exit | false | new | true | break | continue |
5052
5153Also, 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.
5254
5355| | | | | | | | |
5456|-------|-------------|---------|---------|------|---------|--------|------|
5557| abs | arctan | boolean | char | cos | dispose | eof | eoln |
5658| exp | false | input | integer | ln | maxint | new | odd |
5759| ord | output | pack | page | pred | read | readln | real |
5860| reset | rewrite | round | sin | sqr | sqrt | succ | text |
5961| true | trunc write | writeln | | | | | |
6062
6163Pascal is not case sensitive! , , and are equivalent. But for readability purposes, it is a good idea to use meaningful capitalization!
6264
6365There 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 .
6466
6567Identifiers can be any length, but many Pascal compilers will only look at the first 32 characters or so. That is,
6668
67-`    ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFAlphaBeta`\
68-`    ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGammaDelta`
69+```
70+ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFAlphaBeta
71+ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGammaDelta
72+```
6973
7074may 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.
7175
7276This 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.
7377
7478To 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.
7579
7680While 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.
7781
7882---
7983*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