Created
September 10, 2022 18:12
-
-
Save theoknock/56a75d1693d09c1e3d569c0f67dda788 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "SimpleBlockComposition.h" | |
typedef typeof(unsigned long(^)(unsigned long)) block; | |
typedef typeof(block *) block_t; | |
typedef typeof(block(^)(block)) block_object; | |
static block (^compose)(block, block) = ^ (block composition, block component) { | |
block temp_comp = composition; | |
block new_comp = ^ (unsigned long c) { printf("composing block chain...\n"); return component(temp_comp(c)); }; | |
return new_comp; | |
}; | |
static unsigned long (^(^(^objects_iterator)(void))(block))(void) = ^{ | |
__block unsigned long audio_state_cond = 0UL; | |
static volatile block object_composition = ^ unsigned long (unsigned long c) { printf("(1) block %lu\n", c); return c; }; | |
__block restrict block_t object_composition_ptr = &object_composition; | |
return ^ (block object) { | |
object_composition = compose(object_composition, object); | |
return ^{ | |
return (*object_composition_ptr)(audio_state_cond = -~audio_state_cond); | |
}; | |
}; | |
}; | |
@interface ViewController () | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view. | |
unsigned long(^(^asdf)(block))(void) = objects_iterator(); | |
unsigned long(^wxyz)(void) = asdf(^ (unsigned long lu) { printf("(B) lu = %lu\n", lu); return lu; }); | |
wxyz(); | |
unsigned long(^mnop)(void) = asdf(^ (unsigned long lu) { printf("(A) lu = %lu\n", lu); return lu; }); | |
wxyz(); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment