Samples

Hits: 48919

Operators +=, *=

var a: integer := 1;
begin
 a += 2; 
 a *= 2;
end.
 

Local block variables

begin
  var n := 10000;
  var s := 0.0;
  for var i:=1 to n do
  for var j:=1 to n do
    s += 1.0/(i*j);
  Println(Milliseconds);  
end.
 

Using foreach

begin
  var arr := Arr(1,2,3,4);
  foreach var x in arr do
    Print(x);
end.
 

BigInteger

begin
  var p: BigInteger := 1;
  for var i := 2 to 100 do
    p *= i;
  Println('100!=',p); 
end.
 

Short functions

function CircleLen(r: real) := 2 * Pi * r;
 
begin
  Println(CircleLen(2.3));  
end.
 

Creating dynamic arrays with Arr function

begin
  var a := Arr(2,5,3,1,9,7);
  Sort(a);
  a.Println;
  Reverse(a);
  a.Println; 
end.

Dynamic matrices

function Transpose(a: array [,] of integer): array[,] of integer;
begin
  var m := Length(a,0);
  var n := Length(a,1);
  Result := new integer[n,m];
  for var i:=0 to n-1 do
  for var j:=0 to m-1 do
    Result[i,j] := a[j,i]  
end;
 
begin
  var a := MatrixRandom(3,4);
  a.Println;
  var b := Transpose(a);
  a.Println;
end.

Dictionaries

begin
  var Capital := Dict(('Russia','Moscow'),('Germany','Berlin'),('France','Paris'),('Italy','Rom'));
  Println(Capital['France'],Capital['Germany']);
end.
 

Simple file operations

var 
  f: Text;
  s: string;
begin
  Assign(f,'13_Files1.pas');
  Reset(f);
  while not eof(f) do
  begin
    readln(f,s);
    writeln(s);
  end;
  Close(f);
end.
 

or

begin
  var f := OpenRead('13_Files2.pas');
  while not f.Eof do
  begin
    var s := f.ReadlnString;
    writeln(s);
  end;
  f.Close;
end.
 

or

begin
  foreach var s in ReadLines('13_Files4.pas') do
    writeln(s);
end.

or

begin
  ReadLines('13_Files4.pas').Println(NewLine)
end.

Drawing sine with lambda

uses GraphABC;
 
begin
  Draw(x->x*sin(x));
end.
 

Monte-Carlo-Simulation

begin
  var n := 10000000;
  var pp := Range(1,n)
    .Select(x->Rec(Random(),Random()))
    .Where(p->sqr(p.Item1)+sqr(p.Item2)<1)
    .Count/n*4;
  Print(pp);
end.
 

Quicksort with LINQ

function QuickSort(a: sequence of integer): sequence of integer := a.Count = 0 ? a : QuickSort(a.Skip(1).Where(x->x<=a.First())) + a.First() + QuickSort(a.Skip(1).Where(x->x>a.First()));
 
begin
  var a := ArrRandom(20);
  a.Println;
  QuickSort(a).Println;
end.
 

News

09.03.22. Release  PascalABC.NET 3.8.3. Main features: for loop with step, foreach loop with index. All changes are here.

07.02.22. Release PascalABC.NET 3.8.2. What's new in 3.8.2.

24.08.21. Release PascalABC.NET 3.8.1. Main features - [Cache] attribute and PlotWPF unit. What's new in version 3.8.1.

07.03.21. PascalABC.NET 3.8 release. Slices of multidimensional arrays and unpacking of lambda expressions parameters into variables. What's new in version 3.8..

12.01.21. Version PascalABC.NET 3.7.2. What's new in version 3.7.2..