100 Helloslanguages
Home / Languages / Pascal

Pascal

1970fraglet
historicalimperativestructured.pas.p
docker run --rm --platform="linux/amd64" 100hellos/pascal:latest

MCP + fragletc

MCPstdinargs
This language supports code execution via MCP and the fragletc CLI. Stdin piping and argument passing are both supported.
Install fragletc →

Pascal is an Algol-inspired structured programming language that had a great deal of success in the 1970s and 80s before eventually being displaced by C and C++. From Wikipedia:

Pascal is an imperative and procedural programming language, designed by Niklaus Wirth as a small, efficient language intended to encourage good programming practices using structured programming and data structuring. It is named after French mathematician, philosopher and physicist Blaise Pascal.

Pascal was developed on the pattern of the ALGOL 60 language. Wirth was involved in the process to improve the language as part of the ALGOL X efforts and proposed a version named ALGOL W. This was not accepted, and the ALGOL X process bogged down. In 1968, Wirth decided to abandon the ALGOL X process and further improve ALGOL W, releasing this as Pascal in 1970.

Borland's Turbo Pascal, in particular, saw extensive use throughout the 80s and early 90s in both professional and educational settings by extending the language to incorporate features such as inline assembly, units for shipping code modules, and object-oriented programming features, among others.

Here we use a limited installation of Free Pascal, a compiler supporting a variety of Pascal dialects, to build a simple example program. Note, the resulting container only includes the core RTL.

Hello World

program HelloWorld;

uses crt;

{ BEGIN_FRAGLET }
begin
  writeln('Hello World!');
end.
{ END_FRAGLET }

Coding Guide

Language Version

Free Pascal (FPC) 3.2.2

Execution Model

  • Compiled language using Free Pascal Compiler (FPC)
  • Code is compiled to a binary, then executed
  • Standard Pascal execution model with a program block

Key Characteristics

  • Statically typed
  • Case-insensitive
  • Requires explicit compilation step
  • Uses Free Pascal Compiler (FPC)
  • Supports both procedural and object-oriented programming

Fragment Authoring

Write valid Pascal code blocks. Your fragment becomes the main program body. Your fragment will be compiled and executed.

Fragments must include the begin and end. statements, along with all the code you want to execute.

Available Units

The template includes:

  • crt - C runtime library (basic I/O operations)

Standard Pascal units are available:

  • crt - Console I/O (writeln, readln, etc.)
  • sysutils - System utilities (string functions, date/time)
  • math - Mathematical functions (sin, cos, sqrt, pow)
  • strutils - String utilities (string manipulation functions)

Common Patterns

  • Output: writeln('message');
  • Variables: var x: integer; or x: integer = 10;
  • Procedures: procedure Name; begin ... end;
  • Functions: function Add(a, b: integer): integer; begin Add := a + b; end;
  • Arrays: arr: array[1..10] of integer;
  • Loops: for i := 1 to 10 do begin ... end;
  • Conditionals: if x > 0 then begin ... end;

Examples

// Simple output
begin
  writeln('Hello from fragment!');
end.

// Variables and calculations
var
  a, b: integer;
begin
  a := 5;
  b := 10;
  writeln('Sum: ', a + b);
end.

// Loops
var
  i: integer;
begin
  for i := 1 to 5 do
    writeln('Count: ', i);
end.

// Arrays
var
  numbers: array[1..5] of integer = (1, 2, 3, 4, 5);
  sum, i: integer;
begin
  sum := 0;
  for i := 1 to 5 do
    sum := sum + numbers[i];
  writeln('Array sum: ', sum);
end.

Caveats

  • Fragments must be valid Pascal code that compiles
  • Pascal uses single quotes for strings: 'string'
  • Variables must be declared in a var block before the begin block
  • The code is compiled fresh each time, so compilation errors will fail execution
  • Pascal is case-insensitive
  • Statement terminators (;) are required
  • Fragments must include the complete begin...end. block structure
  • If you need variables, declare them in a var block before begin

Fraglet Scripts

Echo Args

#!/usr/bin/env -S fragletc --vein=pascal
var
  i: integer;
begin
  write('Args:');
  for i := 1 to paramcount do
    write(' ', paramstr(i));
  writeln;
end.

Stdin Upper

#!/usr/bin/env -S fragletc --vein=pascal
var
  line: string;
begin
  while not eof do
  begin
    readln(line);
    writeln(upcase(line));
  end;
end.

Test

#!/usr/bin/env -S fragletc --vein=pascal
begin
  writeln('Hello World!');
end.

Connections

influenced by

Container Info

image100hellos/pascal:latest
build scheduleFriday
fragletenabled