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.
|
||||
|
||||
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
|
||||
- [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
|
||||
```pascal
|
||||
{
|
||||
Calculate a factorial on multiple languages: Pascal version
|
||||
Compile with: fpc -O3 -S2 fact.pas
|
||||
}
|
||||
program Factorials;
|
||||
program Factorial;
|
||||
|
||||
{ qword = 64 bit unsigned type }
|
||||
function Factorial(n: qword): qword;
|
||||
function factorial(n: qword): qword;
|
||||
begin
|
||||
Result := 1;
|
||||
while n > 0 do
|
||||
|
@ -76,7 +72,7 @@ begin
|
|||
{ The usage of C-like arithmetic assignment operators is possible with -Sc: }
|
||||
{ Result *= n; }
|
||||
Result := Result * n;
|
||||
Dec(n); { equivalent to C's `--` operator }
|
||||
dec(n); { equivalent to C's `--` operator }
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -86,11 +82,16 @@ var
|
|||
begin
|
||||
for n in values do
|
||||
begin
|
||||
WriteLn('Factorial of ', n, ' = ', Factorial(n));
|
||||
writeLn('Factorial of ', n, ' = ', factorial(n));
|
||||
end;
|
||||
end.
|
||||
```
|
||||
|
||||
Compiling:
|
||||
```
|
||||
fpc -O3 -S2 fact.pas
|
||||
```
|
||||
|
||||
## Resources
|
||||
- [Free Pascal Wiki](https://wiki.freepascal.org/Main_Page)
|
||||
- [Basic Pascal Tutorial](https://wiki.freepascal.org/Basic_Pascal_Tutorial)
|
||||
|
|
Loading…
Add table
Reference in a new issue