printing fixes, simple type annotations fix, Function and Array type shortcuts removed, '=' in function definition for block/array removed

This commit is contained in:
ProgramSnail 2024-02-23 16:20:02 +03:00
parent d7f1b6c377
commit d8ef39b2bd
11 changed files with 56 additions and 77 deletions

View file

@ -7,7 +7,7 @@
:: module_3 : func1 func2 func3;
:: module_namespace = module_4;
func = {
func {
@ => {
%x := scan;
@ -23,7 +23,7 @@ func = {
};
?? abracadabbra < abracadabra_abracadabra || some_long_name == another_long_name
&&. abracadabra-abracadabra < long_long_long_long_name => io.print x
&&. abracadabra_abracadabra < long_long_long_long_name => io.print x
!! x < 0 => {
x += 1;
io.print y;
@ -51,7 +51,7 @@ fib 'n : @n Int -> Int =
'n =: 0 | 1 => 1
=: _ => fib ('n - 1) + fib 'n;
func_2 = {
func_2 {
%variant := x;
%val | %err := f x;
@ -108,15 +108,15 @@ func_2 = {
: operator definition example
( - ) 'a 'b = 'a + neg 'b;
test.something = {
test.something {
do_something a b c;
}
exec.something = {
exec.something {
do_something a b c;
}
example.something = {
example.something {
do_something a b c;
}
@ -128,8 +128,8 @@ Fruit = @apple Unit
| @banana Unit;
: function that takes array reference argument
bubble_sort 'arr : <> Array['A] = {
swap_occured := true;
bubble_sort 'arr : <> Array['A] {
$ swap_occured := true;
@ swap_occured => {
swap_occured = false;
@ %i : 0 .. 'arr.size => (?? 'arr[i] > 'arr[i + 1] => swap 'arr[i] 'arr[i + 1], swap_occured = true);
@ -137,7 +137,7 @@ bubble_sort 'arr : <> Array['A] = {
}
: bubble_sort with names instead of symbols
bubble_sort_2 'arr : ref Array['A] = {
bubble_sort_2 'arr : ref Array['A] {
var swap_occured := true;
for swap_occured do {
swap_occured = false;
@ -162,17 +162,17 @@ bubble_sort_2 'arr : ref Array['A] = {
.delete <> 'this 'key = do_something; // var methods
generic_type_name_expressions = {
generic_type_name_expressions {
$x := TreeNode[Int Int].new;
$y := std.Array[Int].new;
}
pipes_example = {
pipes_example {
expr |> func_1 a b |> func_2 c d |> print; // print (func_2 (func_1 expr a b) c d)
print <| func_1 a b <| func_2 c d <| expr; // print (func_1 a b (func_2 c d expr))
}
test_ref_access_precendence = {
test_ref_access_precendence {
%x := <> arr[123];
}
@ -208,7 +208,7 @@ result_example 'a! = 'a =: _? => print "value inside"
=: _ => print "error inside";
: function, that returns result
parse_number : Unit! = {
parse_number : Unit! {
%number_str := String.scan;
%number! := Int.parse number_str;
number.print;
@ -228,7 +228,7 @@ tuple_argument_test 'x : (A & B & C) = do_something;
// ((A1 & A2) | B | C) same to Variant[Tuple[A1 A2] B C]
variant_argument_test 'x : ( (A1 & A2) | B | C) = do_something;
literals_test = {
literals_test {
%float_number_literal := 1.0f;
%double_number_literal := 1.0;
%int_literal := 1i;
@ -243,6 +243,13 @@ literals_test = {
%null_literal := null;
}
array_argument_test 'x : [[ Int ]] = do_something;
array_argument_test 'x : A[Int] = do_something;
functional_arguments_test 'x 'y : (( Int -> Int )) (( Float <- Float -> Float )) = do_something;
functional_arguments_test 'x 'y : F[Int -> Int] F[Float <- Float -> Float] = do_something;
type_name_expression_test 'x : Int = A[Int].a.b.c x y z;
array_name_expression_test 'x : Int = [[(A a) b]].a.b.c x y z;
name_expression_test 'x : Int = abacaba.a.b.c x y z;
field_name_expression_test 'x : Int = (abacaba.a).b.c x y z;
array_function_test 'x : Int [[ 'x (do_something 'x) (T 'x)]]