NETSquirrel - guidelines/Printable version
This is the print version of NETSquirrel - guidelines You won't see this message or any elements not part of the book's content when you print or preview this page. |
The current, editable version of this book is available in Wikibooks, the open-content textbooks collection, at
https://en.wikibooks.org/wiki/NETSquirrel_-_guidelines
Introduction
NETSquirrel - what's that?
[edit | edit source]NETSquirrel - it is the library for NET and NETCore which simplifies code writing on NET languages. The idea of creating this library has been come from PABCSystem unit that provides some subroutings for causing some usual operations such as arrays and matrices generation.
Why NETSquirrel?
[edit | edit source]NETSquirrel generalizes PABCSystem functionality and adds some itself all over NET. This means that you can safely transfer from PascalABC.NET language to another (ex. C#) and backward.
Namespaces structure
Namespaces structure
[edit | edit source]There are the following namespaces to provide different functionality:
- DataStructures - provides non-generic data structures interfaces. Example: IStack interface.
- Immutable - provides non-generic immutable data structures interfaces. Example: IImmutableStack interface.
- Generic - provides generic data structures interfaces. Example: IStack<T> interface.
- Immutable - provides generic immutable data structures interfaces. Example: IImmutableStack<T> interface.
- Debug - provides non-generic proxy types for IDE's (such as Visual Studio and Rider) debuggers. Example: CollectionProxyType proxy type.
- Generic - provides generic proxy types for IDE's (such as Visual Studio and Rider) debuggers. Example: CollectionProxyType<T> proxy type.
- Extensions - provides several extensions for different types. Example: Print extension.
- ConsoleSpecific - provides console specific extensions for different types. Example: DebugPrint extension.
- Utils - provides several utils for different types. Example: GenerateArray util.
Low complexity
Working with base types
[edit | edit source]You are capable to read values of all over base types and accomplish some extra useful operations with them via NETSquirrel.Utils.BaseTypesUtils and NETSquirrel.Extensions.BaseTypesExtensions classes. Let's consider the provided functionality.
Reading base types values from the keyboard
[edit | edit source]Method's signature | Brief description |
---|---|
bool ReadBool(string) | Reads the bool value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
byte ReadByte(string) | Reads the byte value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
sbyte ReadSByte(string) | Reads the sbyte value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
char ReadChar(string) | Reads the char value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
decimal ReadDecimal(string) | Reads the decimal value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
double ReadDouble(string) | Reads the double value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
float ReadFloat(string) | Reads the float value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
int ReadInt(string) | Reads the int value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
uint ReadUInt(string) | Reads the uint value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
long ReadLong(string) | Reads the long value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
ulong ReadULong(string) | Reads the ulong value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
short ReadShort(string) | Reads the short value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
ushort ReadUShort(string) | Reads the ushort value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
string ReadString(string) | Reads the string value from the keyboard with the specified prompt and returns it.
Parameters:
Notes:
|
The general idea used in methods names is: ReadTypeName, where TypeName - is the base type's name.
ReadBool usage example:
using NETSquirrel.Extensions;
using NETSquirrel.Utils;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
BaseTypesUtils.ReadBool("Bool:").PrintLine();
}
}
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
begin
BaseTypesUtils.ReadBool('Bool:').PrintLine();
end.
Values swapping
[edit | edit source]Method's signature | Brief description |
---|---|
void Swap<T>(ref T, ref T) | Swapped two variables values.
Parameters:
|
Swap usage example:
using NETSquirrel.Utils;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
var x = 1;
var y = 2;
BaseTypesUtils.Swap(ref x, ref y); // x == 2, y == 1
}
}
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
begin
var x := 1;
var y := 2;
BaseTypesUtils.Swap(x, y); // x = 2, y = 1
end.
Sequences generation from particular ranges
[edit | edit source]Method's signature | Brief description |
---|---|
bool IsBetween(this int, int, int) | Evaluates whether the value passed as this parameter is between two other ones and returns the according bool value.
Parameters:
Notes:
|
IEnumerable<int> To(this int, int) | Generates the sequence from the value passed as this parameter to higher one and returns it.
Parameters:
Notes:
|
IEnumerable<int> DownTo(this int, int) | Generates the sequence from the value passed as this parameter to lower one and returns it.
Parameters:
Notes:
|
IEnumerable<int> ToThis(this int) | Generates the sequences from 0 up to/down to (dependent on the second value) to the value passed as this parameter and returns it.
Parameters:
Notes:
|
IEnumerable<int> Stepped(this int, int) | Generates the endless sequence from the value passed as this parameter with the specified step and returns it.
Parameters:
Notes:
|
bool Print() | Outputs bool typed value.
Parameters:
|
bool PrintLine() | Outputs bool typed value and jumps onto the new line.
Parameters:
|
byte Print() | Outputs byte typed value.
Parameters:
|
byte PrintLine() | Outputs byte typed value and jumps onto the new line.
Parameters:
|
sbyte Print() | Outputs sbyte typed value.
Parameters:
|
sbyte PrintLine() | Outputs sbyte typed value and jumps onto the new line.
Parameters:
|
char Print() | Outputs char typed value.
Parameters:
|
char PrintLine() | Outputs char typed value and jumps onto the new line.
Parameters:
|
decimal Print() | Outputs decimal typed value.
Parameters:
|
decimal PrintLine() | Outputs decimal typed value and jumps onto the new line.
Parameters:
|
double Print() | Outputs double typed value.
Parameters:
|
double PrintLine() | Outputs double typed value and jumps onto the new line.
Parameters:
|
float Print() | Outputs float typed value.
Parameters:
|
float PrintLine() | Outputs float typed value and jumps onto the new line.
Parameters:
|
int Print() | Outputs int typed value.
Parameters:
|
int PrintLine() | Outputs int typed value and jumps onto the new line.
Parameters:
|
uint Print() | Outputs uint typed value.
Parameters:
|
uint PrintLine() | Outputs uint typed value and jumps onto the new line.
Parameters:
|
long Print() | Outputs long typed value.
Parameters:
|
long PrintLine() | Outputs long typed value and jumps onto the new line.
Parameters:
|
ulong Print() | Outputs ulong typed value.
Parameters:
|
ulong PrintLine() | Outputs ulong typed value and jumps onto the new line.
Parameters:
|
short Print() | Outputs short typed value.
Parameters:
|
short PrintLine() | Outputs short typed value and jumps onto the new line.
Parameters:
|
ushort Print() | Outputs ushort typed value.
Parameters:
|
ushort PrintLine() | Outputs ushort typed value and jumps onto the new line.
Parameters:
|
To, DownTo and ToThis usage example:
using NETSquirrel.Extensions;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
1.To(10).PrintLine(); // 1, 2, ..., 10
10.DownTo(1).PrintLine(); // 10, 9, ..., 1
10.ToThis().PrintLine(); // 0, 1, ..., 10
}
}
}
{$reference NETSquirrel.dll}
begin
1.To(10).PrintLine(); // 1, 2, ..., 10
10.DownTo(1).PrintLine(); // 1, 2, ..., 10
10.ToThis().PrintLine(); // 1, 2, ..., 10
end.
Working with arrays
[edit | edit source]You are capable to read arrays of all over base types and accomplish some extra useful operations with them via NETSquirrel.Utils.ArrayUtils class. Let's consider the provided functionality.
Arrays generators
[edit | edit source]Method's signature | Brief description |
---|---|
T[] GenerateArray<T>(int, Func<int, T>, int) | Generates the array with specified length via particular selector and returns it.
Parameters:
Exceptions:
Notes:
|
T[] GenerateArray<T>(int, T, Func<T, T>) | Generates the array with specified length via particular selector and returns it.
Parameters:
Exceptions:
|
T[] GenerateArray<T>(int, Func<T[], int, T>) | Generates the array with specified length via particular selector and returns it.
Parameters:
Exceptions:
Notes:
|
int[] CreateRandomIntArray(int, int, int) | Creates the randomly filled array with values taken from the particular range.
Parameters:
Exceptions:
|
float[] CreateRandomFloatArray(int, float, float) | Creates the randomly filled array with values taken from the particular range.
Parameters:
Exceptions:
|
GenerateArray usage example:
using NETSquirrel.Extensions;
using NETSquirrel.Utils;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
ArraysUtils.GenerateArray(10, i => i).PrintLine(); // 0, 1, ..., 10
ArraysUtils.GenerateArray(10, 0, x => x + 1).PrintLine(); // 0, 1, ..., 10
}
}
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
begin
ArraysUtils.GenerateArray(10, i -> i).PrintLine(); // 0, 1, ..., 10
ArraysUtils.GenerateArray(10, 0, x -> x + 1).PrintLine(); // 0, 1, ..., 10
end.
GenerateArray usage example 2:
using NETSquirrel.Extensions;
using NETSquirrel.Utils;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
ArraysUtils.GenerateArray<int>(10, (array, i) => {
switch (i)
{
case 0:
case 1:
return 1;
default:
return array[i - 1] + array[i - 2];
}
}).PrintLine(); // 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
}
}
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
begin
ArraysUtils.GenerateArray&<integer>(10, (a, i) -> begin
case i of
0, 1: Result := 1;
else Result := a[i - 1] + a[i - 2];
end;
end).PrintLine(); // 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
end.
Arrays reading from the keyboard
[edit | edit source]Method's name | Brief description |
---|---|
bool[] ReadBoolArray(int, string) | Reads the array of bool[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
bool[] ReadBoolArray(int, Func<int, string>) | Reads the array of bool[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
bool[] ReadBoolArray(int, ExceptionHandler, string) | Reads the array of bool[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
bool[] ReadBoolArray(int, ExceptionHandler, Func<int, string>) | Reads the array of bool[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
byte[] ReadByteArray(int, string) | Reads the array of byte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
byte[] ReadByteArray(int, Func<int, string>) | Reads the array of byte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
byte[] ReadByteArray(int, ExceptionHandler, string) | Reads the array of byte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
byte[] ReadByteArray(int, ExceptionHandler, Func<int, string>) | Reads the array of byte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
sbyte[] ReadSByteArray(int, string) | Reads the array of sbyte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
sbyte[] ReadSByteArray(int, Func<int, string>) | Reads the array of sbyte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
sbyte[] ReadSByteArray(int, ExceptionHandler, string) | Reads the array of sbyte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
sbyte[] ReadSByteArray(int, ExceptionHandler, Func<int, string>) | Reads the array of sbyte[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
char[] ReadCharArray(int, string) | Reads the array of char[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
char[] ReadCharArray(int, Func<int, string>) | Reads the array of char[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
decimal[] ReadDecimalArray(int, string) | Reads the array of decimal[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
decimal[] ReadDecimalArray(int, Func<int, string>) | Reads the array of decimal[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
decimal[] ReadDecimalArray(int, ExceptionHandler, string) | Reads the array of decimal[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
decimal[] ReadDecimalArray(int, ExceptionHandler, Func<int, string>) | Reads the array of decimal[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
double[] ReadDooubleArray(int, string) | Reads the array of double[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
double[] ReadDooubleArray(int, Func<int, string>) | Reads the array of double[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
double[] ReadDooubleArray(int, ExceptionHandler, string) | Reads the array of double[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
double[] ReadDooubleArray(int, ExceptionHandler, Func<int, string>) | Reads the array of double[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
float[] ReadFloatArray(int, string) | Reads the array of float[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
float[] ReadFloatArray(int, Func<int, string>) | Reads the array of float[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
float[] ReadFloatArray(int, ExceptionHandler, string) | Reads the array of float[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
float[] ReadFloatArray(int, ExceptionHandler, Func<int, string>) | Reads the array of float[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
int[] ReadIntArray(int, string) | Reads the array of int[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
int[] ReadIntArray(int, Func<int, string>) | Reads the array of int[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
int[] ReadIntArray(int, ExceptionHandler, string) | Reads the array of int[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
int[] ReadIntArray(int, ExceptionHandler, Func<int, string>) | Reads the array of int[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
uint[] ReadUIntArray(int, string) | Reads the array of uint[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
uint[] ReadUIntArray(int, Func<int, string>) | Reads the array of uint[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
uint[] ReadUIntArray(int, ExceptionHandler, string) | Reads the array of uint[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
uint[] ReadUIntArray(int, ExceptionHandler, Func<int, string>) | Reads the array of uint[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
long[] ReadLongArray(int, string) | Reads the array of long[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
long[] ReadLongArray(int, Func<int, string>) | Reads the array of long[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
long[] ReadLongArray(int, ExceptionHandler, string) | Reads the array of long[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
long[] ReadLongArray(int, ExceptionHandler, Func<int, string>) | Reads the array of long[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ulong[] ReadULongArray(int, string) | Reads the array of ulong[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ulong[] ReadULongArray(int, Func<int, string>) | Reads the array of ulong[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ulong[] ReadULongArray(int, ExceptionHandler, string) | Reads the array of ulong[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ulong[] ReadULongArray(int, ExceptionHandler, Func<int, string>) | Reads the array of ulong[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
short[] ReadShortArray(int, string) | Reads the array of short[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
short[] ReadShortArray(int, Func<int, string>) | Reads the array of short[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
short[] ReadShortArray(int, ExceptionHandler, string) | Reads the array of short[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
short[] ReadShortArray(int, ExceptionHandler, Func<int, string>) | Reads the array of short[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ushort[] ReadUShortArray(int, string) | Reads the array of ushort[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ushort[] ReadUShortArray(int, Func<int, string>) | Reads the array of ushort[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ushort[] ReadUShortArray(int, ExceptionHandler, string) | Reads the array of ushort[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ushort[] ReadUShortArray(int, ExceptionHandler, Func<int, string>) | Reads the array of ushort[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
string[] ReadStringArray(int, string) | Reads the array of string[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
string[] ReadStringArray(int, Func<int, string>) | Reads the array of string[] type with the specified length.
Parameters:
Exceptions:
Notes:
|
ReadBoolArray usage example:
using NETSquirrel.Extensions;
using NETSquirrel.Utils;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
ArraysUtils.ReadBoolArray(10, "item {0} = ").PrintLine();
ArraysUtils.ReadBoolArray(10, i => $"{new[] { "even", "odd" }[i % 2]} item = ").PrintLine();
}
}
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
begin
ArraysUtils.ReadBoolArray(10, 'item {0} = ').PrintLine();
var lambda: integer -> string := i -> string.Format('{0} item = ', (new string[] ('even', 'odd'))[i mod 2]);
ArraysUtils.ReadBoolArray(10, lambda).PrintLine();
end.
ReadBoolArray usage example 2:
using NETSquirrel.Extensions;
using NETSquirrel.Utils;
namespace Test
{
internal static class Program
{
private static void Main(string[] args)
{
ArraysUtils.ReadBoolArray(10, e => e.Message.PrintLine(), "item {0} = ").PrintLine();
ArraysUtils.ReadBoolArray(10, e => e.Message.PrintLine(),
i => $"{new[] { "even", "odd" }[i % 2]} item = ").PrintLine();
}
}
}
{$reference NETSquirrel.dll}
uses NETSquirrel.Utils;
uses NETSquirrel;
begin
ArraysUtils.ReadBoolArray(10, procedure(e) -> e.Message.PrintLine(), 'item {0} = ').PrintLine();
ArraysUtils.ReadBoolArray(10, procedure(e) -> e.Message.PrintLine(),
i -> string.Format('{0} item = ', (new string[] ('even', 'odd'))[i mod 2])).PrintLine();
end.
Working with matrices
[edit | edit source]Matrices generators
[edit | edit source]Matrices reading from the keyboard
[edit | edit source]
Medium complexity
Applying data structures interfaces
[edit | edit source]
High complexity
Debug view customization via proxy types
[edit | edit source]
Remarks
Compatibility
[edit | edit source]There is no full compatibility between NETSquirrel and PascalABC.NET due to named tuples usage. It means that the following code will not compile:
{$reference NETSquirrel.dll}
uses NETSquirrel;
begin
(new integer[] (1, 2, 3)).Numerate().Select(x -> x.index).PrintLine(); // You must use Item2 instead index.
end.
Links
These links are relevant for NETSquirrel.
- GitHub
- Official site
- Support on the Russian VK social media site
- Google Docs - Documentation
- Cyberforum - theme
- Forum of mechanics and mathematics SFU - theme
- C# - GeekforGeeks