Sorry Jason, but I don't quite understand, would you please explain it more detailedly? Thanks a lot.
2017-04-13 22:28 GMT+08:00 Winnebeck, Jason <[email protected]> : > Jochen, I had a use case that was very close to this that may or may not > inspire bo zhang for an alternative solution to closure equality. I had to > rely on the Groovy implementation detail that each Closure instance created > from an expression at a line of code had the same class (I did put this > assumption in a unit test in my project so I'd know if that broke). That > let me create a DSL like AngularJS watches: > > def person = [name: 'Jason', skills: ['groovy']] > > person.watch( {skills} ) {oldVal, newVal -> > println "person.$name's skills changed from $oldVal to $newVal" > } > > To implement the watch method, I have a map of Class to watcher's state. > So when the person.watch expression is run again, the state is preserved > from the last run, using the closure's class as the key to recover the > state. In this example, two watches with the same closure definition would > have two states. But if I put the two watch into a function, the closures > would share the same line of code and compare as "equal" > > Jason > > -----Original Message----- > From: Jochen Theodorou [mailto:[email protected]] > Sent: Thursday, April 13, 2017 10:08 AM > To: [email protected] > Subject: Re: How to determine the equality of two closures? > > > > On 13.04.2017 15:56, bo zhang wrote: > > Hello everybody, > > > > I just have encountered a problem thus need your help. I want to treat > > the following closures as "equivalent": > > > > Clousure c1={ > > "This is a closure" > > } > > > > Clousure c2={ > > "This is a closure" > > } > > > > assert closureEqual(c1,c2) > > may I ask how you want to use that? I was thinking about this in the past, > but I failed to create a reasonable scenario in which I would need this. > > > Apparently, even though all fields and methods (the internal bytecode) > > are equal, c1 and c2 are still different classes (xxx_closure$1 and > > xxx_closure$2). AFAIK, everything but name in these two classes are > equal. > > > > Is there any possibilities to achieve my goal? Thank you very much. > > right now, not no. > > bye Jochen > > This email message and any attachments are for the sole use of the > intended recipient(s). Any unauthorized review, use, disclosure or > distribution is prohibited. If you are not the intended recipient, please > contact the sender by reply email and destroy all copies of the original > message and any attachments. >
