DHowett/theos — Issue #9: Refactor %c into generic cached computation functionality
Author: rpetrich
Created: 2011-11-02 06:08:36+00:00
State: open

It should be possible to pass arbitrary expressions into a logos macro and have it dedupe and cache them.
Existing `%c(classname)` expressions could be converted to use this functionality internally.
Additionally, components within theos itself could use this functionality to trim some of the work they perform (would use this for my internal generator)

*Proposed syntax:*
`%cached(x)` yields a C rvalue that references the result of the computation `x` as executed from inside `%init;` (or the automatically generated initializer if none exists)

*Potential extensions:*
Nested cached expressions could be supported to eliminate duplicate work inside of cached expressions themselves. Further, cached expressions that are used only as a subexpression of other cached expressions could be optimized not to escape the scope of `%init`
Lazy initialization via alternate syntax (with/without thread safety?). Would allow syntax like this to workaround glacial apis:
`%cached([[[NSCharacterSet characterSetWithCharactersInString:@"_1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"] invertedSet] retain], lazy)`