相关疑难解决方法(0)

什么是Y-combinator?

Y-combinator是一种来自事物"功能"方面的计算机科学概念.大多数程序员对组合器一无所知,如果他们甚至听说过它们的话.

  • 什么是Y-combinator?
  • 组合器如何工作?
  • 它们有什么用?
  • 它们在程序语言中有用吗?

theory computer-science functional-programming combinators definition

381
推荐指数
14
解决办法
10万
查看次数

弱方法论证语义

有没有办法指定特定方法参数具有弱语义?

详细说明,这是一个按预期工作的Objective-C示例代码:

- (void)runTest {  
    __block NSObject *object = [NSObject new];  
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{  
        [self myMethod:object];  
    });  
    // to make sure it happens after `myMethod:` call  
    dispatch_async(dispatch_get_main_queue(), ^{  
        object = nil;  
    });  
}  
- (void)myMethod:(__weak id)arg0 {  
    NSLog(@"%@", arg0); // <NSObject: 0x7fb0bdb1eaa0>  
    sleep(1);  
    NSLog(@"%@", arg0); // nil  
}  
Run Code Online (Sandbox Code Playgroud)

这是Swift版本,但没有

public func runTest() {  
    var object: NSObject? = NSObject()  
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {  
        self.myMethod(object)  
    }  
    dispatch_async(dispatch_get_main_queue()) {  
        object = nil  
    }  
}  
private func myMethod(arg0: AnyObject?) {  
    println("\(arg0)") //Optional(<NSObject: 0x7fc778f26cf0>)  
    sleep(1)  
    println("\(arg0)") …
Run Code Online (Sandbox Code Playgroud)

arguments weak-references automatic-ref-counting swift

6
推荐指数
3
解决办法
5162
查看次数