Pascal.NET

The new generation Pascal programming language that combines simplicity of classic Pascal, a great number of modern extensions and broad capabilities of Microsoft .NET Framework.

Download

Sample>
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);
writeln(Milliseconds);
end.

Using foreach
begin
var arr := new integer[](1,2,3,4);
foreach var x in arr do
write(x,’ ‘);
writeln;
end.

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

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

Creating dynamic arrays with Arr function
begin
var a := Arr(2,5,3,1,9,7);
Sort(a);
writeln(a);
Reverse(a);
writeln(a);
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);
writeln(a);
var b := Transpose(a);
writeln(b);
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.

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

begin
foreach var s in ReadLines(’13_Files4.pas’) do
writeln(s);
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)xx>a.First()));
end;

begin
var a := ArrRandom(20);
a.Println;
QuickSort(a).Println;
end.

Advertisements
This entry was posted in Pascal.Net. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s