We are still actively working on the spam issue.

Pascal

From InstallGentoo Wiki
Jump to: navigation, search
Pascal.png

Pascal is a highly-structured, strongly-typed programming language.

Pascal was originally designed by Dr. Niklaus Wirth, and was first published in 1970. It began as an extension to ALGOL, a programming language which Dr. Wirth had also helped to design. The language is named after the famous 17th-century French mathematician and philosopher Blaise Pascal.

In the 1970's and 80's, Pascal became very popular, particularly in the academic field. However, its popularity started to wane when many universities and businesses began using the newly created UNIX operating system, which was programmed in the C language. Many university classes and other users switched from Pascal to C to take advantage of the new system. Another major user of Pascal, Apple, would also eventually switch to C and Objective-C.

The Pascal language has been extended many times by different groups. Borland Turbo Pascal is among the better known extensions, featuring one of the fastest compilers for PCs at the time. Turbo Pascal also popularized the usage of object oriented programming in the Pascal language.

Modern implementations

Delphi

Embarcadero Delphi is a proprietary IDE which uses a dialect of Object Pascal, a much more developed object oriented dialect than that used in Borland Turbo Pascal.

Free Pascal

Free Pascal is a free and open source implementation which supports a wide variety of platforms. It features its own Object Pascal dialect similar to that of Delphi, as well as Delphi, Turbo, and Mac Pascal compatibility. The project also develops two IDEs: the text-based FreeVision IDE, and the Delphi-like Lazarus IDE.

GNU Pascal

GNU Pascal is another free and open source Pascal implementation, maintained as part of the GNU project and built upon GCC. It focuses more on supporting the ISO Pascal standards, with several features from ISO Standard and Extended Pascal which other modern Pascal dialects like Free Pascal and Delphi do not support.

The Dev-Pascal IDE supports the GNU Pascal dialect.

Installation

Compiler

Free Pascal is probably the easiest to install and use, with or without the Lazarus IDE. You can find an easy installer for most platforms at the Free Pascal SourceForge page. You can also install it through your GNU/Linux or BSD package manager.

After the compiler is installed, you can type fpc myprogram.pas in your terminal to compile the source file myprogram.pas. By default, the resulting binary would be called myprogram (or myprogram.exe on Windows). Then you can run the program by typing ./myprogram (or simply myprogram on Windows).

Package Manager

The Free Pascal installation also includes the fppkg package manager. You can use it to install extra libraries not included as part of the standard installation (such as the fpGUI framework)

Tutorial

The following tutorial covers concepts mostly universal among Pascal dialects:

Pascal Tutorial

An edited version of this tutorial for Free Pascal, which adds lessons on concepts specific to Object Pascal and object-oriented programming, is hosted at the project's wiki:

Object Pascal Tutorial

If you prefer printed materials or more traditionally formatted learning resources, a list of Pascal Books is available on this wiki.

Examples

Hello World

program Hello;
begin
  Writeln('Hello World!')
end.

Bottles of Beer

program BottlesOfBeer;

function Count(Bottles: Integer): string;
begin
  case Bottles of
    0: Count := 'No more bottles';
    1: Count := '1 bottle';
  else
    WriteStr(Count, Bottles, ' bottles')
  end
end;

var
  Bottles: Integer;
begin
  for Bottles := 99 downto 1 do
  begin
    Writeln(Count(Bottles), ' of beer on the wall');
    Writeln(Count(Bottles), ' of beer');
    Writeln('Take one down, pass it around');
    Writeln(Count(Bottles - 1), ' of beer on the wall');
    Writeln
  end
end.

Further reading