pascal.md: update

This commit is contained in:
tocariimaa 2025-02-10 17:33:54 -03:00
parent 1fe8f53497
commit f9c2fa55b0

View file

@ -4,11 +4,37 @@ Pascal is a procedural programming language created by [Niklaus Wirth](niklaus_w
Pascal was a popular choice for microcomputers in the 70's and 80's, even more popular than C initially (C was still quite an UNIX-only language)
due to its simple design, which allowed fast simple single-pass compilers.
In its "vanilla" form, Pascal is not any more complex than C, aside from having features that C doesn't have, such as range types
and nested procedures.
## Compilers
- [FPC](https://www.freepascal.org/) (Free Pascal Compiler): currently the most popular Pascal compiler with wide support
for different OSes and architectures, libre software.
- Turbo Pascal: old compiler for DOS systems, proprietary
- Delphi: proprietary, adds [OOP](oop.md) bloat
- Turbo Pascal: old compiler for DOS systems, proprietary.
- Delphi: proprietary, adds [OOP](oop.md) bloat and exception handling.
## Notes
### Returning values from functions
```pascal
{ The "classical" way, assigning the return value to the function name }
function Square(n: integer): integer;
begin
Square := n * n;
end;
{ Object Pascal and Delphi, assigning to special `Result` variable }
{ Enable with `-S2` in FPC }
function Square(n: integer): integer;
begin
Result := n * n;
end;
{ Return statement like }
function Square(n: integer): integer;
begin
Exit(n * n);
end;
```
## Examples
### Hello world
@ -68,6 +94,7 @@ end.
## Resources
- [Free Pascal Wiki](https://wiki.freepascal.org/Main_Page)
- [Basic Pascal Tutorial](https://wiki.freepascal.org/Basic_Pascal_Tutorial)
- *Why Pascal is Not My Favorite Programming Language* by Brian Kernighan, mostly of historic interest as almost all of the
flaws described in the article has been fixed by modern Pascal compilers. <https://www.lysator.liu.se/c/bwk-on-pascal.html>