-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathy_clang.c
59 lines (46 loc) · 1.52 KB
/
y_clang.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <inttypes.h> /* uintmax_t */
#include <stdio.h> /* printf */
#include <stdlib.h> /* EXIT_SUCCESS */
typedef uintmax_t (^func)( uintmax_t ) ;
typedef struct wrap {
void (^_)( struct wrap , void (^)( func ) ) ;
} wrap;
typedef void (^callback)( func ) ;
void show( uintmax_t value ) {
printf( "%ju" "\n" , value ) ;
}
int main( int argc , char *argv[] ) {
void (^y)(wrap, callback) = ^ void ( wrap gen , callback cb ) {
gen._(
gen
, ^ ( func f ) {
cb( f ) ;
}
);
};
void (^factorial_improver)(wrap, callback) = ^ void ( wrap partial , callback cb ) {
cb( ^ uintmax_t ( uintmax_t n ) {
return n == 0 ? 1
: ({
__block uintmax_t rv = 1;
partial._(
partial
, ^ ( func f ) {
rv = n * f( n - 1 );
});
rv;
}) ;
} );
};
callback fifty = ^ ( func fx ) {
show( fx ( 50 ) ) ;
};
y( (wrap) { ._ = ^ ( wrap partial , callback cb )
{
factorial_improver( partial , cb );
}
}
, fifty
);
return EXIT_SUCCESS;
}