| FazBrowse Wikipedia Viewer | Main Page | | |
| Viewing: https://en.wikipedia.org/wiki/PascalABC.NET |
| Contents |
|---|
| Code examples |
| Usual PascalABC.NET style |
| Object-oriented style |
| Close to regular C# style |
| PascalABC.NET | ||
|---|---|---|
| Paradigm | Multi-paradigm: procedural, functional, object-oriented, generic | |
| Designed by | PascalABC.NET Compiler Team | |
| First appeared | 2007;19 years ago (2007) | |
| loop10do
Write('*');
• for loop with a step (1..10).Printlines
• short function definition syntax varseq:sequenceofinteger:=Arr(1..10);
seq.Println;
seq:=Lst(11..100);seq.Println;
seq:=HSet(1..20);seq.Println;
i*i);\n"}}'>vara:=ArrGen(10,i->i*i);
• auto classes - classes with an automatically generated constructor ##// denotes that the main program will be written without enclosing begin-end
varf:real->real:=x->x*x;
Here is an example of superposition of two functions: (f: T1 -> T2; g: T -> T1): T -> T2 := x -> f(g(x));\n\nvar f: real -> real := x -> x*x;\nvar fg := Super(f,Sin);\nvar gf := Super(Sin,f);\n\nPrint(fg(2));\nPrint(gf(2));\n"}}'>##
functionSuper<T,T1,T2>(f:T1->T2;g:T->T1):T->T2:=x->f(g(x));
varf:real->real:=x->x*x;
varfg:=Super(f,Sin);
vargf:=Super(Sin,f);
Print(fg(2));
Print(gf(2));
Superposition operation is defined in the standard library: real := x -> x*x;\n\nPrint((f*Cos)(2));\nPrint((Cos*f)(2));\n"}}'>##
varf:real->real:=x->x*x;
Print((f*Cos)(2));
Print((Cos*f)(2));
In the book "How To Program Effectively In Delphi" and in the corresponding video tutorials, Dr. Kevin Bond, a programmer and a Computer Science teaching specialist, notes that PascalABC.NET has powerful functional programming capabilities which are missing in Delphi. As an example, partial function application is demonstrated: integer -> integer := x -> y -> x + y;\n Writeln(f(2)(6));\nend.\n"}}'>begin
varf:integer->integer->integer:=x->y->x+y;
Writeln(f(2)(6));
end.
Code exampleseditPascalABC.NET is a multi-paradigm programming language. It allows one to use different coding styles from oldschool Pascal to functional and object-oriented programming. The same task can be solved in different styles as follows: Usual PascalABC.NET styleeditbegin
var(a,b):=ReadInteger2;
(a..b).Sum(x->x*x).Print// method chaining with lambda expressions
end.
Object-oriented styleeditThis solution demonstrates PascalABC.NET-specific short function definition style. x*x); \n static function SumCubes(a,b: integer) := (a..b).Sum(x -> x*x*x);\nend;\n\nbegin\n var (a,b) := ReadInteger2;\n Println($'Squares sum = {Algorithms.SumSquares(a,b)}');\n Println($'Cubes sum = {Algorithms.SumCubes(a,b)}') \nend.\n"}}'>typeAlgorithms=class
staticfunctionSumSquares(a,b:integer):=(a..b).Sum(x->x*x);
staticfunctionSumCubes(a,b:integer):=(a..b).Sum(x->x*x*x);
end;
begin
var(a,b):=ReadInteger2;
Println($'Squares sum = {Algorithms.SumSquares(a,b)}');
Println($'Cubes sum = {Algorithms.SumCubes(a,b)}')
end.
Close to regular C# styleeditIt is possible to write programs without usage of PascalABC.NET standard library. All standard .NET Framework classes and methods can be used directly. "Twisted Pair Podcast, #389". Twisted Pair Podcast (in Russian). 30 March 2021.
| ||