4 ms·
How in the world do callables replace closures? Closures can have arguments, callables can't. You cannot pass a ruby lambda expecting arguments to Clojure.
by sreque 16y ago
How in the world do callables replace closures? Closures can have arguments, callables can't. You cannot pass a ruby lambda expecting arguments to Clojure.
- technomancy 16y ago> You cannot pass a ruby lambda expecting arguments to Clojure. I beg to differ: http://github.com/technomancy/clojure-gem/blob/master/test/test_ref.rb#L46 http://github.com/technomancy/clojure-gem/blob/master/test/t...
- sreque 16y agoHave you looked at the source code for that project? It doesn't use callables at all. the orig_commute function, the original commute method on class Ref, gets passed a monkey-patched ruby Proc object that implements the invoke method which takes one argument, a list, containing all of the original ruby arguments. Clojure then most likely calls invoke inside orig_commute through reflection. The end result: a bunch of hackery specific to Ruby and Clojure, something JVM-level closures would help eliminate. Again, you cannot pass a ruby function expecting arguments to Clojure! What your link shows is that you can, however, send monkey-patched versions of ruby functions that implement clojure-specific calling conventions to clojure. :)