Difference between revisions of "&"

From Free Pascal wiki
Jump to navigationJump to search
(octal base, reserved word identifier escape)
Line 1: Line 1:
 
{{&}}
 
{{&}}
 
<div style="float:left; margin: 0 25px 20px 0; padding:40px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">&</div>
 
<div style="float:left; margin: 0 25px 20px 0; padding:40px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">&</div>
 +
 +
<br /> <br />
  
 
In [[ASCII]] the character code decimal <syntaxhighlight lang="pascal" enclose="none">38</syntaxhighlight> (or [[Hexadecimal|<syntaxhighlight lang="pascal" enclose="none">$</syntaxhighlight>]]<syntaxhighlight lang="pascal" enclose="none">26</syntaxhighlight>) is defined to be <syntaxhighlight lang="pascal" enclose="none">&</syntaxhighlight> (pronounced “ampersand”).
 
In [[ASCII]] the character code decimal <syntaxhighlight lang="pascal" enclose="none">38</syntaxhighlight> (or [[Hexadecimal|<syntaxhighlight lang="pascal" enclose="none">$</syntaxhighlight>]]<syntaxhighlight lang="pascal" enclose="none">26</syntaxhighlight>) is defined to be <syntaxhighlight lang="pascal" enclose="none">&</syntaxhighlight> (pronounced “ampersand”).
 +
 +
 +
<br /> <br />
  
 
== Pascal ==
 
== Pascal ==
 
=== octal base ===
 
=== octal base ===
In Pascal the <syntaxhighlight lang="pascal" enclose="none">&</syntaxhighlight> denotes an octal base number.
+
In [[Pascal]] the <syntaxhighlight lang="pascal" enclose="none">&</syntaxhighlight> denotes an octal base number.
 
<syntaxhighlight lang="pascal" line highlight="9">
 
<syntaxhighlight lang="pascal" line highlight="9">
 
program messageNo(input, output, stderr);
 
program messageNo(input, output, stderr);
Line 32: Line 37:
  
 
=== identifier escape ===
 
=== identifier escape ===
[[FPC|FreePascal]] retroactively declared some new reserved words.
+
[[FPC|FreePascal]] retroactively declared some new [[Reserved word|reserved words]].
In order of being capable of compiling old code with an up-to-date compiler version, which might fail due to those new reserved words, FPC declared the <syntaxhighlight lang="pascal" enclose="none">&</syntaxhighlight> as an escape character.
+
In order of being capable of compiling old code with an up-to-date [[Compiler|compiler]] version, which might fail due to those new reserved words, FPC declared the <syntaxhighlight lang="pascal" enclose="none">&</syntaxhighlight> as an escape character.
Thus, without refactoring the code but escaping, i.e. prepending an <syntaxhighlight lang="pascal" enclose="none">&</syntaxhighlight> to the identifier, the compiler accepts the actual reserved word as a valid identifier.
+
Thus, without refactoring the code but escaping, i.e. prepending an <syntaxhighlight lang="pascal" enclose="none">&</syntaxhighlight> to the [[Identifier|identifier]], the compiler accepts the actual reserved word as a valid identifier. New code though shall come up with different identifier names, without utilizing this feature.
New code though shall come up with different identifier names, without utilizing this feature.
 
  
 
== Lazarus ==
 
== Lazarus ==
In Lazarus the <syntaxhighlight lang="pascal" enclose="none">&</syntaxhighlight> is used to
+
In [[Lazarus]] the <syntaxhighlight lang="pascal" enclose="none">&</syntaxhighlight> is used to
 
* indicate shortcut keys in [[TMenuItem|<syntaxhighlight lang="pascal" enclose="none">TMenuItem</syntaxhighlight>]]
 
* indicate shortcut keys in [[TMenuItem|<syntaxhighlight lang="pascal" enclose="none">TMenuItem</syntaxhighlight>]]
  
 
{{Symbols}}
 
{{Symbols}}

Revision as of 18:48, 20 March 2019

English (en) suomi (fi) français (fr) português (pt) русский (ru)

&



In ASCII the character code decimal 38 (or $26) is defined to be & (pronounced “ampersand”).




Pascal

octal base

In Pascal the & denotes an octal base number.

 1program messageNo(input, output, stderr);
 2
 3uses
 4	baseUnix;
 5
 6begin
 7	// withdraw group write access to current terminal
 8	// equivalent to invoking: mesg n
 9	fpChmod('/dev/stdin', &0600);
10end.

In an octal base only the characters 0 through and including 7 are allowed. An optional sign is specified in front of the &.

As a passing remark, in a production program the number in the above example is better written as

fpChmod('/dev/stdin', S_IRUSR or S_IWUSR);

since it is more meaningful than having a raw number. Pascal is a high-level language. Use this advantage. Write what you mean, not what in fact the computer does.

identifier escape

FreePascal retroactively declared some new reserved words. In order of being capable of compiling old code with an up-to-date compiler version, which might fail due to those new reserved words, FPC declared the & as an escape character. Thus, without refactoring the code but escaping, i.e. prepending an & to the identifier, the compiler accepts the actual reserved word as a valid identifier. New code though shall come up with different identifier names, without utilizing this feature.

Lazarus

In Lazarus the & is used to


navigation bar: topic: Pascal symbols
single characters

+ (plus)  •  - (minus)  •  * (asterisk)  •  / (slash)
= (equal)  •  > (greater than)  •  < (less than)
. (period)  •  : (colon)  •  ; (semi colon)
^ (hat)  •  @ (at)
$ (dollar sign)  •  & (ampersand)  •  # (hash)
' (single quote)

character pairs

<> (not equal)  •  <= (less than or equal)  •  := (becomes)  •  >= (greater than or equal)

 •  >< (symmetric difference)  •  // (double slash)