]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/tests/curry.factor
core: Rename iota to <iota> so we can have TUPLE: iota ... ; instead of TUPLE: iota...
[factor.git] / basis / compiler / tests / curry.factor
1 USING: tools.test quotations math kernel sequences
2 assocs namespaces make compiler.units compiler.test
3 locals random ;
4 IN: compiler.tests.curry
5
6 [ 3 ] [ 5 [ [ 2 - ] curry call ] compile-call ] unit-test
7 [ 3 ] [ [ 5 [ 2 - ] curry call ] compile-call ] unit-test
8 [ 3 ] [ [ 5 2 [ - ] 2curry call ] compile-call ] unit-test
9 [ 3 ] [ 5 [ 2 [ - ] 2curry call ] compile-call ] unit-test
10 [ 3 ] [ 5 2 [ [ - ] 2curry call ] compile-call ] unit-test
11 [ 3 ] [ 5 2 [ [ - ] 2curry 9 swap call /i ] compile-call ] unit-test
12 [ 3 ] [ 5 2 [ [ - ] 2curry [ 9 ] dip call /i ] compile-call ] unit-test
13
14 [ -10 -20 ] [ 10 20 -1 [ [ * ] curry bi@ ] compile-call ] unit-test
15
16 [ [ 5 2 - ] ] [ 5 [ [ 2 - ] curry ] compile-call >quotation ] unit-test
17 [ [ 5 2 - ] ] [ [ 5 [ 2 - ] curry ] compile-call >quotation ] unit-test
18 [ [ 5 2 - ] ] [ [ 5 2 [ - ] 2curry ] compile-call >quotation ] unit-test
19 [ [ 5 2 - ] ] [ 5 [ 2 [ - ] 2curry ] compile-call >quotation ] unit-test
20 [ [ 5 2 - ] ] [ 5 2 [ [ - ] 2curry ] compile-call >quotation ] unit-test
21
22 [ [ 6 2 + ] ]
23 [
24     2 5
25     [ [ [ + ] curry ] dip 0 < [ -2 ] [ 6 ] if swap curry ]
26     compile-call >quotation
27 ] unit-test
28
29 [ 8 ]
30 [
31     2 5
32     [ [ [ + ] curry ] dip 0 < [ -2 ] [ 6 ] if swap curry call ]
33     compile-call
34 ] unit-test
35
36 : foobar ( quot: ( ..a -- ..b ) -- )
37     [ call ] keep swap [ foobar ] [ drop ] if ; inline recursive
38
39 [ ] [ [ [ f ] foobar ] compile-call ] unit-test
40
41 [ { 6 7 8 } ] [ { 1 2 3 } 5 [ [ + ] curry map ] compile-call ] unit-test
42 [ { 6 7 8 } ] [ { 1 2 3 } [ 5 [ + ] curry map ] compile-call ] unit-test
43
44 : funky-assoc>map ( assoc quot -- seq )
45     [
46         [ call f ] curry assoc-find 3drop
47     ] { } make ; inline
48
49 [ t ] [| |
50     1000 <iota> [ drop 1,000,000 random 1,000,000 random ] H{ } map>assoc :> a-hashtable
51     a-hashtable [ [ drop , ] funky-assoc>map ] compile-call
52     a-hashtable keys =
53 ] unit-test
54
55 [ 3 ] [ 1 [ 2 ] [ curry [ 3 ] [ 4 ] if ] compile-call ] unit-test
56
57 [ 3 ] [ t [ 3 [ ] curry 4 [ ] curry if ] compile-call ] unit-test
58
59 [ 3 ] [ t [ 3 [ ] curry [ 4 ] if ] compile-call ] unit-test
60
61 [ 4 ] [ f [ 3 [ ] curry 4 [ ] curry if ] compile-call ] unit-test
62
63 [ 4 ] [ f [ [ 3 ] 4 [ ] curry if ] compile-call ] unit-test