closures

Eclipse 4.2 and Java 8

瘦欲@ 提交于 2019-12-06 00:06:05
I found this page stating that Java 8 support for Juno is deffered, but I can't find more information how soon people can exspect to be able to write first closures in Eclipse and get productive with that stuff. Has someone got insight how long we still have to wait? The Java7 features were in 3.7 really quickly, that's why it's kind of odd that this task is deferred. Any comments, ideas? Or maybe even a good workaround? One of the key reasons that Java 8 support was deferred is that Java 8 will be available after Eclipse Juno is released. A major release of Eclipse couldn't be shipped with

Javascript private methods — what is the memory impact?

你说的曾经没有我的故事 提交于 2019-12-05 23:13:47
I'm working on a bit of code where I'm attempting to hide some private variables inside closures. The thing is the environment is fairly constrained in terms of memory, so I'm also concerned with keeping the overall footprint of the classes low. What is the impact of using closures to hide private instance variables and methods when compared to just making all methods and variables on an object public? Would an instance of the one using closures take up more memory than an instance that did not use closures? If so, how much more memory would I expect to use? my code would look like this

closure requires unique access

て烟熏妆下的殇ゞ 提交于 2019-12-05 23:10:32
I'm trying to avoid repeating myself by using a closure in the following code: fn add_raw(&mut self, pair: RawLinkPair) { let convert = |raw: &RawLink| { Link{ id: self.get_or_create(raw.name).id, flow: raw.flow, } }; println!("Hive received pair: {}", pair); let parent = convert(&pair.parent); let child = convert(&pair.child); self.link_concepts(parent, child); } That doesn't work. It gives me this error: hive.rs:64:9: 64:13 error: cannot borrow `*self` as mutable because previous closure requires unique access hive.rs:64 self.link_concepts(parent, child); ^~~~ hive.rs:55:23: 60:10 note:

What is the type of a lambda function?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 23:03:36
问题 In C++0x, I'm wondering what the type is of a lambda function. Specifically: #include<iostream> type1 foo(int x){ return [x](int y)->int{return x * y;}; } int main(){ std::cout<<foo(3)(4);//would output 12 type2 bar = foo(5); std::cout<<bar(6);//would output 30 return 0; } What do I need to replace type1/type2 with to get the above to work? Hopefully you can see what I'm trying to accomplish, so even if this isn't possible by a direct replacement of type1 and type2, perhaps you can guide me

Undefined Behavior with the C++0x Closure: II

雨燕双飞 提交于 2019-12-05 22:04:47
I find the use of the C++0x closure perplexing. My initial report , and the subsequent one , have generated more confusion than explanations. Below I will show you troublesome examples, and I hope to find out why there is an undefined behavior in the code. All the pieces of the code pass the gcc 4.6.0 compiler without any warning. Program No. 1: It Works #include <iostream> int main(){ auto accumulator = [](int x) { return [=](int y) -> int { return x+y; }; }; auto ac=accumulator(1); std::cout << ac(1) << " " << ac(1) << " " << ac(1) << " " << std::endl; std::cout << ac(1) << " " << ac(1) << "

Properly referencing self in dispatch_async

送分小仙女□ 提交于 2019-12-05 21:17:59
问题 How do I properly reference self in a swift closure? dispatch_async(dispatch_get_main_queue()) { self.popViewControllerAnimated(true) } I get the error: Cannot convert the expression's type 'Void' to type 'UIViewController!" Randomly I tried: dispatch_async(dispatch_get_main_queue()) { () self.popViewControllerAnimated(true) } and it worked. Not sure what the extra () does! Anyone care to explain? Thanks! 回答1: This is the same issue as people have run in with these questions: What am I doing

Passing closure to trait method: expected type parameter, found closure

一世执手 提交于 2019-12-05 20:15:35
I'm a bit stumped on how to get this working, I've cut it down from the real thing. I wrote a trait: pub trait Renderable<F: Fn(&PropertyTags)> { fn set_property_changed_callback(&mut self, callback: Option<F>); } Which the 'child' parameter of add_child is restricted by and PropertyTags is just an enum. I've included mock implementations of the type of child to demonstrate my usage: pub struct Child<F: Fn(&PropertyTags)> { property_changed_callback: Option<F>, } impl<F: Fn(&PropertyTags)> Renderable<F> for Child<F> { fn set_property_changed_callback(&mut self, callback: Option<F>) { self

How to call non-escaping closure inside a local closure? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-05 18:14:25
This question already has an answer here: Why do closures require an explicit `self` when they're all non-escaping by default in Swift 3? 2 answers I have a function which looks something like this: func test(closure: () -> ()) { let localClosure = { closure() } localClosure() } This is only an example and does not fully reflect the problem I encountered, obviously here I could have just called closure directly! It should be clear that in the above code, closure cannot escape. However, I get the error: Closure use of non-escaping parameter 'closure' may allow it to escape Now, if localClosure

Inject variable into callback function scope

♀尐吖头ヾ 提交于 2019-12-05 17:01:31
Is this possible to add variable to callback scope? What I want to achieve is: ... Foo.prototype.bar = function(fn) { var baz = "baz!"; fn.call(this); } ... Foo.bar(function() { console.log(baz) // gives "baz!" }); I know I can pass baz variable as an argument or this but I'm interested in something like above. No, it's not possible. The only ways are the ones you pointed out: as an argument or in this . What about doing it this way: var Foo = function(){} Foo.prototype.handle = function(fn) { var baz = "baz !"; eval('(' + fn.toString() + ')();'); } var foo = new Foo; foo.handle(function (){

Why am I getting a “No signature of method”\" error when running the closure recursion example in the Groovy shell?

☆樱花仙子☆ 提交于 2019-12-05 16:59:56
I'm trying to experiment with the Groovy closure recursion example from http://groovy.codehaus.org/JN2515-Closures . I saved the snippet in a file called recursionTest.groovy and loaded it in the shell, but I'm getting a "No signature of method error": // recursionTest.groovy def results = []; { a, b -> results << a a<10 && call(b, a+b) }(1,1) assert results == [1, 1, 2, 3, 5, 8, 13] groovy:000> load recursionTest.groovy ===> [] ERROR groovy.lang.MissingMethodException: No signature of method: java.lang.Boolean.call() is applicable for argument types: (groovysh_evaluate$_run_closure1) values: