Objects vs closures
people.csail.mit.edu
Objects vs closures
1–10 of 19 posts
Re: Objects vs closures
#2Re: Objects vs closures
#3Re: Objects vs closures
#4I like the approach in Scala: every function is an object, and every object which provide an apply() method can be used as a function.
Re: Objects vs closures
#5I 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...
http://en.wikipedia.org/wiki/Classical_electromagnetism_and_... may be interesting. Especially the section "Relationship between electricity and magnetism".
Re: Objects vs closures
#6I 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...
Now, you can arrange your wire in any number of ways to produce a more interesting field. For example you can arrange it in a loop (or several loops). Since, once again the magnetic field is perpendicular to the wire, at the center of the loop it will be perpendicular to the plane of the loop. This way you can make an approximation of a constant field along an axis (just in that small space at the center of the loop/coil).
The fun part is that the inverse relationship also works: a changing magnetic field produces an electric field. Thus, taking a coil and moving a magnet inside of it sufficiently fast produces an electric field, which compels the electric charges in the coil to move producing an AC current. The change in the magnetic field is called the magnetic flux. This process is described by Faraday's law: http://en.wikipedia.org/wiki/Faraday%27s_law_of_induction#Th...
Lastly, Maxwell combined these two equations with two other fundamental equations of electrodynamics (namely, Gauss's law and Gauss's law for magnetism) with some minor corrections for some special cases: http://en.wikipedia.org/wiki/Maxwell%27s_equations. In physics laws and such are very often named not after the first person to discover something, but after the last. From these equations you can derive that light is nothing more than an electromagnetic wave (which of course then goes into the whole duality of light).
Re: Objects vs closures
#7I 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?
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.
Re: Objects vs closures
#8Situational 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]
The 'ko' situation is the most common cycle that occurs in the game of go.
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]
----
Re: Objects vs closures
#9"so closures can be, and are, used to implement very effective objects with multiple methods" 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 opt…
(defprotocol Foo
(bar [this])
(baz [this]))
(defn make-foo [a]
(reify Foo
(bar [this] a)
(baz [this] a)))
(dotimes [_ 10]
(let [x (make-foo 'x)]
(time
(dotimes [_ 1e8]
(bar x)
(baz x))))
So 2 methods called 1 billion times only takes about ~500ms on my 2.66ghz i7 MacbookPro.(of course, Clojure prefers values+behaviors, aka objects, without mucking it up with state)
Re: Objects vs closures
#10I 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...
Feynman explains it nicely in his lectures on physics. The key is relativity. (Magnetism is a relativistic effect of electricity.) http://en.wikipedia.org/wiki/Classical_electromagnetism_and_... may be interesting. Especially the section "Relationship between electricity and magnetism".