TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Objects vs closures

74 pointsby progover 14 years ago

6 comments

shawndumasover 14 years ago
I invoke the ko rule...<p>Situational Cycle: a move sequence that starts and ends at the same position such that at the end of that cycle it is the same player's turn as it was at the start. If cycles are allowed without restrictions on them, it is possible for a game to go on indefinitely. [1]<p>The 'ko' situation is the most common cycle that occurs in the game of go.<p>Ko: a situation where two alternating single stone captures would repeat the original board position. The alternating captures could repeat indefinitely, preventing the game from ending. The ko rule resolves the situation. [2]<p>----<p>[1]: <a href="http://senseis.xmp.net/?Cycle" rel="nofollow">http://senseis.xmp.net/?Cycle</a><p>[2]: <a href="http://senseis.xmp.net/?Ko" rel="nofollow">http://senseis.xmp.net/?Ko</a>
nadamover 14 years ago
I like the approach in Scala: every function is an object, and every object which provide an apply() method can be used as a function.
评论 #1982597 未加载
jaekwonover 14 years ago
I like the koan in the end. Now if only one can hit me in the head such that I understand the duality of electricity and magnetism...
评论 #1982748 未加载
评论 #1982707 未加载
noblethrasherover 14 years ago
A closure is also a poor man's class (sort of).<p>I've often wished that C# let me implement interfaces with anonymous classes. Since it doesn't, I get around it by creating AdHoc classes for interfaces that I use a lot.<p>For instance, if I have an interface Foo defined as:<p><pre><code> interface Foo { string Bar(int x); } </code></pre> then I also create a corresponding class called AdHocFoo defined like so:<p><pre><code> class AdHocFoo : Foo { Func&#60;int, string&#62; _bar; public AdHocFoo(Func&#60;int, string&#62; bar) { _bar = bar; } public string Bar(int x) { return _bar(x); } } </code></pre> I've written a little program that creates these AdHoc class definitions from interfaces.
beza1e1over 14 years ago
"so closures can be, and are, used to implement very effective objects with multiple methods"<p>I don't really believe this to be efficient. The linked text by Kiselyov implements the dispatch via Scheme's (case ...) expression. Efficient dynamic dispatch means one indirection through a vtable, so one load instruction more compared to a normal function call. Which compilers for functional languages can perform this optimization?<p>Since we are talking about Scheme here, we could compare the dispatch to dynamic languages like Python or Ruby, where the dispatch means looking up a string in a hashmap. I'm willing to believe that Scheme's case can keep up with that.
评论 #1983744 未加载
评论 #1982947 未加载
评论 #1984529 未加载
doki_penover 14 years ago
I wish that _why didn't leave potion behind. One of the coolest thing about potion is that everything is a function. For example, if you have an integer named a that has a value of one, the a() will return 1. I hadn't seen that in any other language. Are there other languages with this feature?