articles/pascal.md: update
This commit is contained in:
parent
a3b2f7eb71
commit
e6782ebbcd
1 changed files with 10 additions and 9 deletions
|
@ -9,7 +9,7 @@ In its "vanilla" form, Pascal is not any more complex than C, aside from having
|
||||||
such as range types, nested procedures, sets, builtin tagged unions, etc.
|
such as range types, nested procedures, sets, builtin tagged unions, etc.
|
||||||
|
|
||||||
Pascal has an ISO standard: ISO 7185. Since the Pascal described in said standard is quite useless for practical programming,
|
Pascal has an ISO standard: ISO 7185. Since the Pascal described in said standard is quite useless for practical programming,
|
||||||
most compilers are for an extended superset of Pascal.
|
most compilers are for an extended superset of the Pascal described in that standard.
|
||||||
|
|
||||||
## Compilers
|
## Compilers
|
||||||
- [FPC](https://www.freepascal.org/) (Free Pascal Compiler): currently the most popular Pascal compiler with wide support
|
- [FPC](https://www.freepascal.org/) (Free Pascal Compiler): currently the most popular Pascal compiler with wide support
|
||||||
|
@ -61,14 +61,10 @@ fpc hellopascal.pas
|
||||||
|
|
||||||
### Factorial
|
### Factorial
|
||||||
```pascal
|
```pascal
|
||||||
{
|
program Factorial;
|
||||||
Calculate a factorial on multiple languages: Pascal version
|
|
||||||
Compile with: fpc -O3 -S2 fact.pas
|
|
||||||
}
|
|
||||||
program Factorials;
|
|
||||||
|
|
||||||
{ qword = 64 bit unsigned type }
|
{ qword = 64 bit unsigned type }
|
||||||
function Factorial(n: qword): qword;
|
function factorial(n: qword): qword;
|
||||||
begin
|
begin
|
||||||
Result := 1;
|
Result := 1;
|
||||||
while n > 0 do
|
while n > 0 do
|
||||||
|
@ -76,7 +72,7 @@ begin
|
||||||
{ The usage of C-like arithmetic assignment operators is possible with -Sc: }
|
{ The usage of C-like arithmetic assignment operators is possible with -Sc: }
|
||||||
{ Result *= n; }
|
{ Result *= n; }
|
||||||
Result := Result * n;
|
Result := Result * n;
|
||||||
Dec(n); { equivalent to C's `--` operator }
|
dec(n); { equivalent to C's `--` operator }
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -86,11 +82,16 @@ var
|
||||||
begin
|
begin
|
||||||
for n in values do
|
for n in values do
|
||||||
begin
|
begin
|
||||||
WriteLn('Factorial of ', n, ' = ', Factorial(n));
|
writeLn('Factorial of ', n, ' = ', factorial(n));
|
||||||
end;
|
end;
|
||||||
end.
|
end.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Compiling:
|
||||||
|
```
|
||||||
|
fpc -O3 -S2 fact.pas
|
||||||
|
```
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
- [Free Pascal Wiki](https://wiki.freepascal.org/Main_Page)
|
- [Free Pascal Wiki](https://wiki.freepascal.org/Main_Page)
|
||||||
- [Basic Pascal Tutorial](https://wiki.freepascal.org/Basic_Pascal_Tutorial)
|
- [Basic Pascal Tutorial](https://wiki.freepascal.org/Basic_Pascal_Tutorial)
|
||||||
|
|
Loading…
Add table
Reference in a new issue