Pascal is available for the Raspberry Pi via the Free Pascal Compiler (FPC). The FPC is a Pascal compiler that not only supports Raspbian on ARM, but it also supports a wide range of 32-bit and 64-bit systems including Intel/AMD system running Linux, FreeBSD, OS X and Windows. To install it on your Pi, type the following command: To test the compiler, we can use a “Hello World” type program. Create a file called “hello.pp” using nano: Insert the following lines: In Pascal, like most programming languages, it is important to include all correct symbols, specifically the semi-colons at the end of the lines and the dot after the word end. Exit and save nano with the shortcut key “Ctrl + x”. To compile the program, call the compiler “fpc” with the name of the Pascal file as the first parameter, i.e.: To run the program type: And you should see the message “Hello Make Tech Easier.” Here is a more complex program which calculates prime numbers by using trial by division. This is a very inefficient way to calculate primes, however it is sufficient to demonstrate a more complex Pascal program. Create a file called “primes.pp” using nano: And insert the following lines: Exit and save nano. Compile the program: And run: The out will look something like this:
Free Pascal also includes a text-based IDE. It is reminiscent of the other text-based Pascal IDEs like Turbo Pascal from the days of MS-DOS. To start it, just type fp; if you want to load a program into the IDE at start up, include it as the first parameter. For example, to run the IDE and load “hello.pp”, type:
To access the menus, press ALT followed by the first letter (marked in red) of the menu name. So “Alt + F” opens the File menu, “Alt + R” opens the Run menu and so on. There are also some “F” key shortcuts. F3 to open a file, F2 to save a file, F9 to build the project and “Ctrl + F9” to run it. The IDE is great in that you get an editor with syntax highlighting and a quick way to compile your source code. Two disadvantages that I have discovered are: Using Free Pascal on the Raspberry is a great way to learn the Pascal programming language. It is also a good stepping stone to Lazarus, a Delphi-like IDE and visual programming environment developed by the same project team. If you have any questions about the examples above, please use the comments section below, and we will see if we can help. Free Pascal also has a vibrant user community and a set of forums where you can get help from other Free Pascal users.