Samples

Hits: 7979

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

30.08.17. PascalABC.NET 3.3 is out. GraphWPF and Graph3D units are added.

29.08.16. PascalABC.NET 3.2 is out. New features: yield, yield sequence

12.02.16. PascalABC.NET 3.1 is out. New features: tuples syntax (a,b), tuples assignment (a,b) := (b,a), extension operators, new syntax of extension methods

28.08.15. PascalABC.NET 3.0 is out.

28.08.15. PascalABC.NET is free now and distributed under LGPLv3 license. Repository is located here.

Our Twitter