ClojureScript can't call JavaScript functions relying on `this`

2011-08-28 Thread Kevin Lynagh
I am having trouble using ClojureScript to call JavaScript functions that exploit prototype injection. If I'm reading `defmethod :emit invoke` correctly, https://github.com/clojure/clojurescript/blob/master/src/clj/cljs/compiler.clj#L513 ClojureScript always seems to compile f(x) JavaScript

Re: Define a protocol as a superset of another

2011-08-28 Thread Alexandre Patry
Thanks Luc and Stuart for your answers. I will try to make my protocols more orthogonal than hierarchical in order to make them fit this philosophy. On 2011-08-28, at 3:43 PM, Stuart Sierra wrote: > Hi Alexandre, > > Clojure Protocols do not support inheritance. This was a design choice. > P

Re: JVM 7 support (invokedynamic)

2011-08-28 Thread Tal Liron
> Well, the statement you just made is true, but nonetheless you are the > one who is mistaken. The emit() method is called, but if not enough > information was present at compile time to resolve to a real method > call (that is, if `method = null` was executed), then the emit() code > emits

Re: JVM 7 support (invokedynamic)

2011-08-28 Thread Alan Malloy
On Aug 28, 12:41 pm, Tal Liron wrote: > > If you look at the links in my previous e-mail (specifically this one > >https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/C...). > > The reflection is done in the compiler only when there is a tag (i.e. a type > > hint). Otherwise the co

Re: Define a protocol as a superset of another

2011-08-28 Thread Stuart Sierra
Hi Alexandre, Clojure Protocols do not support inheritance. This was a design choice. Protocols are more than just Java interfaces because they can contain method implementations for pre-existing classes. Inheritance would make the call site caching in the implementation of protocols more compl

Re: JVM 7 support (invokedynamic)

2011-08-28 Thread Tal Liron
> If you look at the links in my previous e-mail (specifically this one > https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L1364). > > The reflection is done in the compiler only when there is a tag (i.e. a type > hint). Otherwise the compiler just emits an in

Re: Define a protocol as a superset of another

2011-08-28 Thread Luc Prefontaine
I'll be more specific :) "If you are used to Java style type inheritance you might be surprised that there is no explicit record/protocol mechanism for defining one type as a “sub-type” of another and inheriting the super-type’s implementation. You might even think that Clojure datatypes are le

Re: Define a protocol as a superset of another

2011-08-28 Thread Alexandre Patry
On 2011-08-28, at 2:27 PM, Luc Prefontaine wrote: > On Sun, 28 Aug 2011 14:19:46 -0400 > Alexandre Patry wrote: > Some reading: > > http://david-mcneil.com/post/1475458103/implementation-inheritance-in-clojure Thanks for the quick answer. >From what I understand, this article talks about inhe

Re: Define a protocol as a superset of another

2011-08-28 Thread Luc Prefontaine
On Sun, 28 Aug 2011 14:19:46 -0400 Alexandre Patry wrote: Some reading: http://david-mcneil.com/post/1475458103/implementation-inheritance-in-clojure Luc P. > Hi, > > I would like to define a protocol as a super set of another. For > example: > > (defprotocol P1 > (f [this])) > > (defproto

Define a protocol as a superset of another

2011-08-28 Thread Alexandre Patry
Hi, I would like to define a protocol as a super set of another. For example: (defprotocol P1 (f [this])) (defprotocol P1WithExtras ;; something like :extends P1 (g [this])) ;; P1WithExtras should now contain f and g. I may have missed, but I did not find how to do it from the documentat

Re: JVM 7 support (invokedynamic)

2011-08-28 Thread Paul Stadig
On Sun, Aug 28, 2011 at 10:58 AM, Tal Liron wrote: > I wonder if it would be that difficult to replace the reflector code with >> an invokedynamic. There is a way to get from a java.lang.reflect.Method to a >> java.lang.invoke.MethodHandle (see >> java.lang.invoke.MethodHandles.Lookup.unreflect).

Re: JVM 7 support (invokedynamic)

2011-08-28 Thread Tal Liron
> > Paul also points out areas where MethodHandles can replace the rather >> sticky reflection work that Clojure does now to massage calls to non-Clojure >> libraries. That's not entirely related to the invokedynamic stuff I'm >> working on, so I think I'll leave it to somebody else to take a s

Re: JVM 7 support (invokedynamic)

2011-08-28 Thread Paul Stadig
On Sun, Aug 28, 2011 at 10:25 AM, Tal Liron wrote: > Progress! > > I am staring right now at my JVM 7 build of Clojure that uses invokedynamic > for Vars that contain functions. It essentially works, well enough for > experimentation. A few of my simple apps seem to work fine with it. > > There a

Re: JVM 7 support (invokedynamic)

2011-08-28 Thread Paul Stadig
On Sat, Aug 27, 2011 at 8:31 PM, Tal Liron wrote: > I can think of a few ways in which it would be possible to distribute a > clojure.jar that supports JVM 7 features while still falling back to JVM 5 > compatibility. So, I don't think this was ever a barrier. But you obviously > unconvinced by m

Re: JVM 7 support (invokedynamic)

2011-08-28 Thread Tal Liron
Progress! I am staring right now at my JVM 7 build of Clojure that uses invokedynamic for Vars that contain functions. It essentially works, well enough for experimentation. A few of my simple apps seem to work fine with it. There are still a lot of problems: the Clojure test suite fails, and m

Re: map vs. pmap

2011-08-28 Thread artg
fixed it (defn t [m] (let [r (java.util.Random.)] (dotimes [i m] (. r nextDouble))) (Thread/sleep 1000)) (defn testmap [f n m] (time (doall (f t (repeat n m) user=> (testmap map 8 200) "Elapsed time: 8869.942784 msecs" (nil nil nil nil nil nil nil nil) user=> (testmap pmap 8 20

Re: How to import libs in Clojure?

2011-08-28 Thread Wanderfels
Hello, sorry for late answering. i had problems with my internet conn. like you said my mistake was using -cp and -classpath together. i now did ... > java -cp clojure.jar;C:\CLOJURE\lib\clojure-contrib-1.2.0.jar clojure.main ... and now it works: > user=> (require 'clojure.contrib.str-utils)

Re: map vs. pmap

2011-08-28 Thread artg
Thanks. I looked at Java doc for random which says "This method is properly synchronized to allow correct use by more than one thread. However, if many threads need to generate pseudorandom numbers at a great rate, it may reduce contention for each thread to have its own pseudorandom-number generat