From 4b86ef77955f5bb4f134252c15ef30fd51a243c3 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sun, 24 Oct 2021 02:15:13 +0200 Subject: Fixes lambda functions not always working. --- data/unit-testing/access_constant_index.fate | 2 +- data/unit-testing/access_pointer.fate | 100 --------------------------- data/unit-testing/allocate_and_free.fate | 13 ++-- data/unit-testing/field_access.fate | 70 ++++++++++++------- data/unit-testing/filter.fate | 85 ++++++++++++++++++----- data/unit-testing/fold.fate | 16 +++-- data/unit-testing/map.fate | 6 +- 7 files changed, 131 insertions(+), 161 deletions(-) delete mode 100644 data/unit-testing/access_pointer.fate (limited to 'data') diff --git a/data/unit-testing/access_constant_index.fate b/data/unit-testing/access_constant_index.fate index 74bf705..f98a034 100644 --- a/data/unit-testing/access_constant_index.fate +++ b/data/unit-testing/access_constant_index.fate @@ -38,7 +38,7 @@ (global int i) (for (set! i 0) (=< i 10) (set! i (+ i 1)) - (add! (list:range 0 i 1) lili) + (list:add! (list:range 0 i 1) lili) ) (assert! (= (var lili.10.0) 0) [FAILED] (var test_name) lili.10.0 was (var lili.10.0).) diff --git a/data/unit-testing/access_pointer.fate b/data/unit-testing/access_pointer.fate deleted file mode 100644 index 9ec3e44..0000000 --- a/data/unit-testing/access_pointer.fate +++ /dev/null @@ -1,100 +0,0 @@ -(fate_version 1) - -(global string test_name) - -(set! test_name ( ACCESS POINTER )) - -(global (list int) li) -(global (ptr (list int)) li_ptr) - -(set! li (range 0 10 1)) -(set! li_ptr (ptr li)) - -(global int i) - -(for (set! i 0) (=< i 10) (set! i (+ i 1)) - (assert! (= (at (access_ptr i li)) (var i)) - [FAILED] ACCESS POINTER assert failed on (var i) for li. - ) - (assert! (= (at (access_ptr i li_ptr)) (var i)) - [FAILED] ACCESS POINTER assert failed on (var i) with for li_ptr. - ) -) - -(global (list (list int)) lili) - -(for (set! i 0) (=< i 10) (set! i (+ i 1)) - (add! (range 0 i 1) lili) -) - -(assert! - (= (at (access_ptr 0 (at (access_ptr 10 lili)))) 0) - [FAILED] (var test_name) lili.10.0 was - (at (access_ptr 0 (at (access_ptr 10 lili)))) for part A. -) -(assert! - (= (at (access_ptr 1 (at (access_ptr 9 lili)))) 1) - [FAILED] (var test_name) lili.9.1 was - (at (access_ptr 1 (at (access_ptr 9 lili)))) for part A. -) -(assert! - (= (at (access_ptr 2 (at (access_ptr 8 lili)))) 2) - [FAILED] (var test_name) lili.8.2 was - (at (access_ptr 2 (at (access_ptr 8 lili)))) for part A. -) -(assert! - (= (at (access_ptr 3 (at (access_ptr 7 lili)))) 3) - [FAILED] (var test_name) lili.7.3 was - (at (access_ptr 3 (at (access_ptr 7 lili)))) for part A. -) -(assert! - (= (at (access_ptr 4 (at (access_ptr 6 lili)))) 4) - [FAILED] (var test_name) lili.6.4 was - (at (access_ptr 4 (at (access_ptr 6 lili)))) for part A. -) -(assert! - (= (at (access_ptr 5 (at (access_ptr 5 lili)))) 5) - [FAILED] (var test_name) lili.5.5 was - (at (access_ptr 5 (at (access_ptr 5 lili)))) for part A. -) -(assert! - (= (at (access_ptr 3 (at (access_ptr 4 lili)))) 3) - [FAILED] (var test_name) lili.4.3 was - (at (access_ptr 3 (at (access_ptr 4 lili)))) for part A. -) -(assert! - (= (at (access_ptr 2 (at (access_ptr 3 lili)))) 2) - [FAILED] (var test_name) lili.3.2 was - (at (access_ptr 2 (at (access_ptr 3 lili)))) for part A. -) -(assert! - (= (at (access_ptr 1 (at (access_ptr 2 lili)))) 1) - [FAILED] (var test_name) lili.2.1 was - (at (access_ptr 1 (at (access_ptr 2 lili)))) for part A. -) -(assert! - (= (at (access_ptr 0 (at (access_ptr 1 lili)))) 0) - [FAILED] (var test_name) lili.1.0 was - (at (access_ptr 0 (at (access_ptr 1 lili)))) for part A. -) -(assert! - (= (at (access_ptr 0 (at (access_ptr 0 lili)))) 0) - [FAILED] (var test_name) lili.0.0 was - (at (access_ptr 0 (at (access_ptr 0 lili)))) for part A. -) - -(assert! (= (at (access_ptr 0 lili.10)) 0) [FAILED] (var test_name) lili.10.0 was (at (access_ptr 0 lili.10)) for part B.) -(assert! (= (at (access_ptr 1 lili.9)) 1) [FAILED] (var test_name) lili.9.1 was (at (access_ptr 1 lili.9)) for part B.) -(assert! (= (at (access_ptr 2 lili.8)) 2) [FAILED] (var test_name) lili.8.2 was (at (access_ptr 2 lili.8)) for part B.) -(assert! (= (at (access_ptr 3 lili.7)) 3) [FAILED] (var test_name) lili.7.3 was (at (access_ptr 3 lili.7)) for part B.) -(assert! (= (at (access_ptr 4 lili.6)) 4) [FAILED] (var test_name) lili.6.4 was (at (access_ptr 4 lili.6)) for part B.) -(assert! (= (at (access_ptr 5 lili.5)) 5) [FAILED] (var test_name) lili.5.5 was (at (access_ptr 5 lili.5)) for part B.) -(assert! (= (at (access_ptr 3 lili.4)) 3) [FAILED] (var test_name) lili.4.3 was (at (access_ptr 3 lili.4)) for part B.) -(assert! (= (at (access_ptr 2 lili.3)) 2) [FAILED] (var test_name) lili.3.2 was (at (access_ptr 2 lili.3)) for part B.) -(assert! (= (at (access_ptr 1 lili.2)) 1) [FAILED] (var test_name) lili.2.1 was (at (access_ptr 1 lili.2)) for part B.) -(assert! (= (at (access_ptr 0 lili.1)) 0) [FAILED] (var test_name) lili.1.0 was (at (access_ptr 0 lili.1)) for part B.) -(assert! (= (at (access_ptr 0 lili.0)) 0) [FAILED] (var test_name) lili.0.0 was (at (access_ptr 0 lili.0)) for part B.) - -[COMPLETED] ACCESS POINTER - -(end!) diff --git a/data/unit-testing/allocate_and_free.fate b/data/unit-testing/allocate_and_free.fate index 8998236..9c1ccb1 100644 --- a/data/unit-testing/allocate_and_free.fate +++ b/data/unit-testing/allocate_and_free.fate @@ -11,16 +11,15 @@ [FAILED] Test 0 ) -(free! (at p0)) +(free! p0) -(add! (default (ptr int)) lp0) -(add! (default (ptr int)) lp0) -(add! (default (ptr int)) lp0) -(add! (default (ptr int)) lp0) +(list:add! (default (ptr int)) lp0) +(list:add! (default (ptr int)) lp0) +(list:add! (default (ptr int)) lp0) +(list:add! (default (ptr int)) lp0) (allocate! lp0.0) -(allocate! (at (access_pointer 1 lp0))) -(allocate! (access_pointer 1 lp0))) +(allocate! (at (ptr lp0.1))) [COMPLETED] diff --git a/data/unit-testing/field_access.fate b/data/unit-testing/field_access.fate index d9d582a..87c143c 100644 --- a/data/unit-testing/field_access.fate +++ b/data/unit-testing/field_access.fate @@ -4,40 +4,40 @@ (set! test_name ( FIELD ACCESS )) -(declare_structure test_struct_type0 +(declare_structure #test_struct_type0 (int i) (int j) (int k) ((list int) li) ) -(declare_structure test_struct_type1 +(declare_structure #test_struct_type1 (int i) - (test_struct_type0 ts0) - ((list test_struct_type0) lts) + (#test_struct_type0 ts0) + ((list #test_struct_type0) lts) ) -(declare_structure test_struct_type2 +(declare_structure #test_struct_type2 (int i) - (test_struct_type0 ts0) - (test_struct_type1 ts1) + (#test_struct_type0 ts0) + (#test_struct_type1 ts1) ) -(global test_struct_type0 ts0_0) -(global test_struct_type0 ts0_1) -(global test_struct_type1 ts1_0) -(global test_struct_type1 ts1_1) -(global test_struct_type2 ts2_0) +(global #test_struct_type0 ts0_0) +(global #test_struct_type0 ts0_1) +(global #test_struct_type1 ts1_0) +(global #test_struct_type1 ts1_1) +(global #test_struct_type2 ts2_0) -(set_fields! ts0_0 +(struct:set_fields! ts0_0 (i 42) (j 69) (k 420) (li (list:range 0 10 1)) ) -(set_fields! ts0_1 +(struct:set_fields! ts0_1 (i 42) (j 69) (k 420) @@ -47,20 +47,30 @@ (li (list:range 11 20 1)) ) -(set_fields! ts1_0 +(struct:set_fields! ts1_0 (i 1337) (ts0 (var ts0_0)) - (lts (add (var ts0_1) (add (var ts0_0) (default (list test_struct_type0))))) + (lts + (list:add + (var ts0_1) + (list:add (var ts0_0) (default (list #test_struct_type0))) + ) + ) ) -(set_fields! ts1_1 +(struct:set_fields! ts1_1 (i 1337) (ts0 (var ts0_1)) - (lts (add (var ts0_0) (add (var ts0_1) (default (list test_struct_type0))))) + (lts + (list:add + (var ts0_0) + (list:add (var ts0_1) (default (list #test_struct_type0))) + ) + ) ) (set! ts2_0 - (set_fields (default test_struct_type2) + (struct:set_fields (default #test_struct_type2) (i -1337) (ts0 (var ts0_0)) (ts1 (var ts1_1)) @@ -68,7 +78,13 @@ ) (assert! - (= (get_field i ts0_0) (var ts0_0.i) (get_field k ts0_1) (var ts0_1.k) 42) + (= + (struct:get_field i ts0_0) + (var ts0_0.i) + (struct:get_field k ts0_1) + (var ts0_1.k) + 42 + ) [FAILED] (var test_name) Test 0. (newline) ts0_0.i = (var ts0_0.i) @@ -77,7 +93,13 @@ ) (assert! - (= (get_field i ts0_1) (var ts0_1.i) (get_field k ts0_0) (var ts0_0.k) 420) + (= + (struct:get_field i ts0_1) + (var ts0_1.i) + (struct:get_field k ts0_0) + (var ts0_0.k) + 420 + ) [FAILED] (var test_name) Test 1. (newline) ts0_0.k = (var ts0_0.k) @@ -87,9 +109,9 @@ (assert! (= - (field i ts0_1) - (get_field i (set_fields ts1_0 (i 420))) - (get_field i (field ts0 (field ts1 ts2_0))) + (struct:field i ts0_1) + (struct:get_field i (struct:set_fields ts1_0 (i 420))) + (struct:get_field i (struct:field ts0 (struct:field ts1 ts2_0))) 420 ) [FAILED] (var test_name) Test 2. diff --git a/data/unit-testing/filter.fate b/data/unit-testing/filter.fate index ce202e7..e86b420 100644 --- a/data/unit-testing/filter.fate +++ b/data/unit-testing/filter.fate @@ -12,17 +12,28 @@ (set! 0to10odd (list:filter - (lambda ((int i) (int two) (int one)) (= (mod i two) (var one))) + (partial + (lambda + ( + (int two) + (int one) + (int i) + ) + (= (mod i two) (var one)) + ) + 2 + 1 + ) 0to10 - 2 - 1 ) ) -(local (lambda bool (int)) filter_fun) +(local + (lambda bool (int)) filter_fun + (lambda ((int i)) (= (mod i 2) 0)) +) (global (list int) 0to10evena) -(set! filter_fun (lambda ((int i)) (= (mod i 2) 0))) (global (list int) 0to10eveno) (set! 0to10even (list:filter filter_fun 0to10) @@ -90,10 +101,19 @@ (set! 0to10even2 (var 0to10)) (list:filter! - (lambda ((int i) (int two) (int one)) (= (mod i two) (var one))) + (partial + (lambda + ( + (int two) + (int one) + (int i) + ) + (= (mod i two) (var one)) + ) + 2 + 1 + ) 0to10odd2 - 2 - 1 ) (list:filter! filter_fun 0to10even2) @@ -155,10 +175,20 @@ (set! 0to10odd (list:indexed_filter - (lambda ((int ix) (int i) (int two) (int one)) (= (mod i two) (var one))) + (partial + (lambda + ( + (int two) + (int one) + (int ix) + (int i) + ) + (= (mod i two) (var one)) + ) + 2 + 1 + ) 0to10 - 2 - 1 ) ) @@ -226,10 +256,20 @@ (set! 0to10even2 (var 0to10)) (list:indexed_filter! - (lambda ((int ix) (int i) (int two) (int one)) (= (mod i two) (var one))) + (partial + (lambda + ( + (int two) + (int one) + (int ix) + (int i) + ) + (= (mod i two) (var one)) + ) + 2 + 1 + ) 0to10odd2 - 2 - 1 ) (list:indexed_filter! indexed_filter_fun 0to10even2) @@ -308,14 +348,21 @@ ) (list:indexed_filter! - (lambda ((int ix) (int i) ((list int) o)) - (exactly_one - (> i 0) - (list:is_member (var ix) o) + (partial + (lambda + ( + ((list int) o) + (int ix) + (int i) + ) + (exactly_one + (> i 0) + (list:is_member (var ix) o) + ) ) + (list:range 1 21 2) ) oli1 - (list:range 1 21 2) ) (assert! diff --git a/data/unit-testing/fold.fate b/data/unit-testing/fold.fate index 7148aa2..ec3fa8a 100644 --- a/data/unit-testing/fold.fate +++ b/data/unit-testing/fold.fate @@ -53,12 +53,14 @@ (set! 10to0_1 (list:foldr - (lambda (((list int) res) (int e) (int mod)) - (list:add (- e mod) res) + (partial + (lambda ((int mod) ((list int) res) (int e)) + (list:add (- e mod) res) + ) + 10 ) (default (list int)) (list:range 10 20 1) - 10 ) ) @@ -143,12 +145,14 @@ (set! 10to20_1 (list:foldl - (lambda (((list int) res) (int e) (int mod)) - (list:add (- e mod) res) + (partial + (lambda ((int mod) ((list int) res) (int e)) + (list:add (- e mod) res) + ) + 10 ) (default (list int)) (list:range 20 30 1) - 10 ) ) diff --git a/data/unit-testing/map.fate b/data/unit-testing/map.fate index 1ecaf10..13a1053 100644 --- a/data/unit-testing/map.fate +++ b/data/unit-testing/map.fate @@ -16,9 +16,8 @@ (set! li2 (list:map - (lambda ((int i) (int mod)) (* i mod)) + (partial (lambda ((int mod) (int i)) (* i mod)) 2) (list:range 0 10 1) - 2 ) ) @@ -86,9 +85,8 @@ (set! li2 (list:indexed_map - (lambda ((int ix) (int i) (int mod)) (+ (* i ix) mod)) + (partial (lambda ((int mod) (int ix) (int i)) (+ (* i ix) mod)) 1000) (list:range 10 20 1) - 1000 ) ) -- cgit v1.2.3-70-g09d2