Simple tuple and const matching code examples
This commit is contained in:
parent
aa4a847bad
commit
314ee3b8be
|
|
@ -31,12 +31,12 @@ begin
|
|||
var a := Arr(1,9,8,7,2,3,4,5);
|
||||
|
||||
// Расширенный is
|
||||
if a is [1,..,x,_,5] then
|
||||
Println(x);
|
||||
if a is [1,..,x,_,5] then // a is [1,..,1,1,1,1,1,1,1,1,1,1] - ран тайм эррор -
|
||||
Println(x); //в расширенном is короткое вычисление логических выражений не работает (#1508)
|
||||
|
||||
// match .. with
|
||||
match a with
|
||||
[1,9,8,7,2]: print(1);
|
||||
[1,9,8,'str',2]: print(1); //Нет проверки соответствия типов в для коллекций - добавить.
|
||||
[..,4,x]: print(x);
|
||||
[_, .., _]: print(3);
|
||||
end;
|
||||
|
|
|
|||
8
CodeExamples/Patterns/patterns-simple-const.pas
Normal file
8
CodeExamples/Patterns/patterns-simple-const.pas
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
begin
|
||||
var a := 3.14;
|
||||
match a with
|
||||
1.0, 2.0, 3.0: Println(1); // Надо исправить: double не матчит с integer - несоответствие типов.
|
||||
3.13, 3.14, 3.15, 3.16: print(2);
|
||||
123.0: print(3);
|
||||
end;
|
||||
end.
|
||||
7
CodeExamples/Patterns/patterns-simple-tuple.pas
Normal file
7
CodeExamples/Patterns/patterns-simple-tuple.pas
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
begin
|
||||
match (1, 2, 'string') with
|
||||
(1, _, 1): Println(1); // Нет проверки типов каждого элемента tuple - надо ли?
|
||||
(1, _, 'strin'): print(2);
|
||||
(_,_,'string'): print(3);
|
||||
end;
|
||||
end.
|
||||
|
|
@ -33,7 +33,7 @@ begin
|
|||
|
||||
// match .. with
|
||||
match a with
|
||||
Person('Вася', 12, CardInfo('12345678', var cv)): Println(cv);
|
||||
Person(1, 12, CardInfo('12345678', var cv)): Println(cv); // Нет проверки соответсвия типов при деконструировании - добавить.
|
||||
Person('Вася', _, CardInfo(cardNum, 324)): Println(cardNum);
|
||||
Person(_, _, CardInfo(_, x)): Println(x);
|
||||
end;
|
||||
|
|
|
|||
Loading…
Reference in a new issue