Skip to content

Commit 585f546

Browse files
committed
improve test_snip
1 parent ee31951 commit 585f546

File tree

4 files changed

+92
-26
lines changed

4 files changed

+92
-26
lines changed

TODO

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
- not as lazy as they could be:
2+
3+
print
4+
++
5+
6+
both seemt to be strict, so eg. "join_sep ", " (map print primes)" never
7+
returns, "print primes" never returns
8+
9+
- finish new test_snip.def
10+
11+
- add multiple definitions, finish function argument destructuring
12+
13+
sym has a field for "next definition", initially NULL
14+
15+
` add_defining looks for an existing sym with this name, if it finds
16+
one, add a new sym called "{name}-$$4" or whatever
17+
18+
chase to the end of "next definition" on the existing sym, append our
19+
new sym
20+
21+
during compile, generate code like
22+
23+
fred a b c
24+
= destructured_fred, args_match
25+
= fred-$$1 a b c
26+
{
27+
destructured_fred = rhs of fred
28+
args_match = a_matches && b_matches && c_matches
29+
}
30+
31+
if a func has many RHS and the last RHS uses destrucuring, generate a
32+
final def with
33+
34+
fred a b c
35+
= error "no def of fred matches args a b c";
36+
37+
- error if more than one def of fred has no destructuring
38+
- error if defs don't all have the same number of args
39+
- error if a def with no destructuring isn't the last def
40+
141
- try < > in the image titlebar
242

343
seems to get stuck on eg. mp3 files

share/nip4/start/_list.def

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ difference = foldl @ converse @ delete;
4444
* drop 3 "abcd" == "d"
4545
* drop :: num -> [*] -> [*]
4646
*/
47-
drop n l
47+
drop n l
4848
= l, n <= 0 || l == []
4949
= drop (n - 1) (tl l);
5050

@@ -93,11 +93,11 @@ flatten x
9393

9494
/* foldl fn st l: fold list l from the left with function fn and start st
9595
*
96-
* Start from the left hand end of the list (unlike foldr, see below).
96+
* Start from the left hand end of the list (unlike foldr, see below).
9797
* foldl is less useful (and much slower).
9898
*
9999
* foldl fn start [a,b .. z] = ((((st fn a) fn b) ..) fn z)
100-
* foldl :: (* -> ** -> *) -> * -> [**] -> *
100+
* foldl :: (* -> ** -> *) -> * -> [**] -> *
101101
*/
102102
foldl fn st l
103103
= st, l == []
@@ -221,15 +221,15 @@ len l
221221
* limit :: [*] -> *
222222
*/
223223
limit l
224-
= error "incorrect use of limit",
224+
= error "incorrect use of limit",
225225
l == [] || tl l == [] || tl (tl l) == []
226226
= a, a == b
227227
= limit (b : x)
228228
{
229229
a:b:x = l;
230230
}
231231

232-
/* Turn a function of n args into a function which takes a single arg of an
232+
/* Turn a function of n args into a function which takes a single arg of an
233233
* n-element list.
234234
*/
235235
list_1ary fn x = fn x?0;
@@ -248,13 +248,13 @@ map f l
248248
= [], l == [];
249249
= f (hd l) : map f (tl l);
250250

251-
/* map2 fn l1 l2: map two lists together with fn
251+
/* map2 fn l1 l2: map two lists together with fn
252252
*
253253
* map2 :: (* -> ** -> ***) -> [*] -> [**] -> [***]
254254
*/
255255
map2 fn l1 l2 = map (list_2ary fn) (zip2 l1 l2);
256256

257-
/* map3 fn l1 l2 l3: map three lists together with fn
257+
/* map3 fn l1 l2 l3: map three lists together with fn
258258
*
259259
* map3 :: (* -> ** -> *** -> ****) -> [*] -> [**] -> [***] -> [****]
260260
*/
@@ -348,7 +348,7 @@ sortc comp l
348348
n = len l;
349349
n2 = (int) (n / 2);
350350

351-
/* merge l1 l2: merge sorted lists l1 and l2 to make a single
351+
/* merge l1 l2: merge sorted lists l1 and l2 to make a single
352352
* sorted list
353353
*/
354354
merge l1 l2
@@ -397,38 +397,38 @@ sortr l = sortc more l;
397397
split fn l
398398
= [], l == [] || l' == []
399399
= head : split fn tail
400-
{
400+
{
401401
nfn = not @ fn;
402402

403403
l' = dropwhile fn l;
404404
head = takewhile nfn l';
405405
tail = dropwhile nfn l';
406-
}
406+
}
407407

408408
/* splits fn l: break a list into sections separated by a single fn
409409
*
410410
* split (equal ',') ",,1" == ["", "", "1"]
411411
* split :: (* -> bool) -> [*] -> [[*]]
412412
*/
413413
splits fn l
414-
= [], l == []
414+
= [], l == []
415415
= head : splits fn tail
416-
{
416+
{
417417
fn' = not @ fn;
418-
dropif x
418+
dropif x
419419
= [], x == []
420420
= tl x;
421421

422422
head = takewhile fn' l;
423423
tail = dropif (dropwhile fn' l);
424-
}
424+
}
425425

426426
/* splitpl fnl l: split a list up with a list of predicates
427427
*
428428
* splitpl [is_digit, is_letter, is_digit] "123cat" == ["123", "cat", []]
429429
* splitpl :: [* -> bool] -> [*] -> [[*]]
430430
*/
431-
splitpl fnl l
431+
splitpl fnl l
432432
= l, fnl == []
433433
= head : splitpl (tl fnl) tail
434434
{
@@ -448,7 +448,7 @@ split_lines n l
448448
/* take n l: take the first n elements from list l
449449
* take :: num -> [*] -> [*]
450450
*/
451-
take n l
451+
take n l
452452
= [], n <= 0
453453
= [], l == []
454454
= hd l : take (n-1) (tl l);
@@ -463,7 +463,7 @@ takewhile fn l
463463
= hd l : takewhile fn (tl l), fn (hd l)
464464
= [];
465465

466-
/* zip2 l1 l2: zip two lists together
466+
/* zip2 l1 l2: zip two lists together
467467
*
468468
* zip2 [1,2] ['a', 'b', 'c'] == [[1,'a'],[2,'b']]
469469
* zip2 :: [*] -> [**] -> [[*,**]]

src/heap.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,6 +2698,9 @@ shell_pelement(Reduce *rc, PElement *base)
26982698
g_assert(FALSE);
26992699
}
27002700

2701+
// print output as we go
2702+
fflush(stdout);
2703+
27012704
return TRUE;
27022705
}
27032706

test/workspaces/test_snip.def

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ test_unary op_name fn
3535
]);
3636
image = (to_real @ fn @ ifmt @ to_image) x;
3737
number = (to_real @ fn @ nfmt) x;
38-
matrix = (to_real @ fn @ ifmt @ to_matrix) x;
38+
//matrix = (to_real @ fn @ ifmt @ to_matrix) x;
39+
matrix = image;
3940
}
4041
}
4142

@@ -53,11 +54,12 @@ test_binary op_name fn
5354
]);
5455
image = to_real (fn ((ifmt @ to_image) x) ((ifmt @ to_image) y));
5556
number = to_real (fn (nfmt x) (nfmt y));
56-
matrix = to_real (fn ((ifmt @ to_matrix) x) ((ifmt @ to_matrix) y));
57+
//matrix = to_real (fn ((ifmt @ to_matrix) x) ((ifmt @ to_matrix) y));
58+
matrix = image;
5759
}
5860
}
5961

60-
tests = [
62+
tests = concat [
6163
test_binary "add" add,
6264
test_binary "subtract" subtract,
6365
test_binary "multiply" multiply,
@@ -70,8 +72,10 @@ tests = [
7072
test_unary "constant multiplied by" (converse multiply 7),
7173
test_unary "constant subtracted from" (subtract 4),
7274
test_unary "subtract constant" (converse subtract 4),
73-
["" ++ "a" == "a", "concat"],
74-
[hd [1, error "nope"] == 1, "lazy hd"]
75+
[
76+
["" ++ "a" == "a", "concat"],
77+
[hd [1, error "nope"] == 1, "lazy hd"]
78+
]
7579
]
7680
{
7781
// libvips divide returns 0 for divide by zero
@@ -82,9 +86,28 @@ tests = [
8286
}
8387

8488
main
85-
= concat (map print_result tests) ++ "\n"
89+
= [
90+
map (const '.') pass,
91+
map print_fail fail,
92+
"\n"
93+
]
8694
{
87-
print_result result
88-
= ".", result?0
89-
= error result?1;
95+
split fn l
96+
= foldr split_item [[], []] l
97+
{
98+
split_item x sofar
99+
= [pass', fail']
100+
{
101+
[pass, fail] = sofar;
102+
pass'
103+
= x : pass, fn x
104+
= pass;
105+
fail'
106+
= x : fail, !fn x
107+
= fail;
108+
}
109+
}
110+
111+
[pass, fail] = split (extract 0) tests;
112+
print_fail x = "FAIL: " ++ x?1;
90113
}

0 commit comments

Comments
 (0)