Re: Invoking varargs Java methods

2012-01-15 Thread Norman Gray

Wolodja, hello.

On 2012 Jan 11, at 16:34, Wolodja Wentland wrote:

 I've stumbled over varargs in Clojure before and Alan Malloy came up with a
 nice solution [0] which I expanded slightly:
 
 --- snip ---
 (defmacro real-varargs [method required-count  array-type]
  (let [args (repeatedly (inc required-count) gensym)]
`(let [f# (fn [~@args]
(~method ~@args))]
   (fn [ args#]
 (let [[before# after#] (split-at ~required-count args#)]
   (apply f# `(~@before# ~(into-array ~@array-type after#

Thanks for this -- it looks entertaining.  Clojure macros are coming next, for 
me (but I'm postponing them for the moment, because I'm trying to work out 
Racket macros, and trying to grok both at once could be injurious).

Norman


-- 
Norman Gray  :  http://nxg.me.uk

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Proxies and overriding protected methods

2012-01-15 Thread Norman Gray

Greetings.

I'm not understanding proxies.  Can anyone advise me what I'm missing?

I try the following:

user= (def m (proxy [java.util.HashMap] []
 (finalize []
   ;(proxy-super finalize)
   (prn finalizing...))
 (hashCode []
   99)))
#'user/m
user= (.hashCode m)
99
user= (.finalize m)
IllegalArgumentException No matching field found: finalize for class 
user.proxy$java.util.HashMap$0  clojure.lang.Reflector.getInstanceField 
(Reflector.java:289)
user= (ancestors m)
nil
user= 

(the 'proxy-super' is commented out, just to reassure myself that its presence 
is not somehow the root of the problem)

I'm afraid that the documentation of the 'proxy' macro is too terse for me to 
work out what's supposed to be happening here.

The documentation says that 'proxy' creates a instance of a proxy class that 
implements the named class/interface(s) by calling the supplied fns.  That 
suggests (without quite saying so) that 'm' should be an extension of class 
java.util.HashMap, in this case, and this is corroborated by the remark that 
If a method fn is not provided for a class method, the _superclass_ methd will 
be called (my emphasis, note the docs' misspelling of 'methd').  However, the 
null result of (ancestors m) suggests instead that 'm' extends only Object, and 
that it handles _all_ of its method calling by delegation through reflection on 
the class being proxied.

It's the second interpretation that seems to explain why I can't override 
protected method 'finalize' (although that would suggest that I could create a 
new method 'finalize', which shadows Object.finalize without overriding it, and 
doesn't really explain why I'm seeing this error).  That said, however, the 
docs stress that Note that while method fns can be provided to override 
protected methods..., which seems to say that what I'm trying to do, here, 
should be possible.  The rest of that sentence seems to suggest that something 
more complicated is happening, without revealing quite what.

Also Fogus and Houser (in The Joy of Clojure, p211) give an example of using 
'proxy', in which they illustrate a function proxying FilterOutputStream, and 
say that The proxy returned by screaming-filter extends the Java class 
java.io.FilterOutputStream.  That seems to suggest that the proxy is indeed a 
subclass of the thing it's proxying.

Finally, the on-line discussion of gen-class at 
http://clojure.org/compilation mentions that one of the facilities it 
provides is Exposing inherited protected members.  However the description of 
gen-class, there, does strongly suggest that it's a heavyweight, exotic thing, 
intended for fuller JVM interop rather than everyday use, and is telling me, in 
effect, these aren't the macros you're looking for; move along.  It sounds as 
if getting involved in gen-class in this context would be an unidiomatic way of 
doing something fairly simple, namely producing an anonymous extension of a 
class which overrides a protected method.

What am I missing?

Thanks for any pointers.  Best wishes,

Norman


-- 
Norman Gray  :  http://nxg.me.uk



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Cannot access variables without namespace in ClojureScript repl.

2012-01-15 Thread Takahiro Hozumi
Hi,
In my browser repl, which follows the ClojureScript wiki[1], I must
specify variables with namespace even if `in-ns` is used, but I
noticed that I don't have to do in the repl of ClojureScript One[2].

Am I the only one who cannot access variables without namespace?
What makes the diffirence?

log:
ClojureScript:cljs.user (in-ns 'myns)

ClojureScript:myns myns/mydiv ;;with a namespace
#[object HTMLDivElement]

ClojureScript:myns mydiv ;;without a namespace
Error evaluating: mydiv :as .mydiv;\n
#SyntaxError: Unexpected token .
SyntaxError: Unexpected token .
at http://localhost:8080/cljs/clojure/browser/repl.js:21:158

[1] https://github.com/clojure/clojurescript/wiki/Emacs-%26-inferior-lisp-mode
[2] https://github.com/brentonashworth/one/wiki/Development

Thanks.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: i am so bored

2012-01-15 Thread Dennis Haupt
native = not high level

Am 14.01.2012 16:43, schrieb Joseph Smith:
 How about a native I/O library that'll detect the platform and architecture 
 at runtime? Something like java 1.7's nio, but they'll work on clojure hosted 
 on 1.5.x? Make use of JNA to make native calls to get file system details, 
 etc. 
 
 Right now you cannot even stat a file from clojure without calling the stat 
 command from a shell. :/
 
 
 ---
 Joseph Smith
 j...@uwcreations.com
 (402)601-5443
 
 
 On Jan 14, 2012, at 6:12 AM, Dennis Haupt d.haup...@googlemail.com wrote:
 
 hi there,

 i am looking for something to do, preferably something that makes me
 rich, but that is not a must have - if it's interesting, i'll code for free.

 i can offer almost 15 years of coding experience (important: while being
 open minded the whole time). i am a one man army, if you will :)
 (procedural, OO (that one for money), FP, even some assembler). one
 thing i have not yet done is write something big without static type
 checking, so that'll be new.

 clojure has caught my interest. in general, high level programming has.
 i played around with clojure a bit and would like to get something done
 that has at least some purpose. are there any small/new projects looking
 for help?

 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 


-- 

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Help! Migrating to 1.3.0

2012-01-15 Thread Ben Smith-Mannschott
On Sun, Jan 15, 2012 at 01:37, James Reeves jree...@weavejester.com wrote:
 On 14 January 2012 23:34, myriam abramson labwor...@gmail.com wrote:
 I couldn't find quite the equivalent to read-lines from duck-streams. I
 found read-line but it's not the same. Where is the equivalent read-lines
 outside of clojure.contrib?

 There's clojure.core/line-seq, but it doesn't close the reader when
 the seq finishes.

That's true; You're expected to scope this yourself:

(with-open [reader (something-that-produces-a-buffered-reader)]
(something-that-consumes-line-sequence (line-seq reader)))

If you can't structure the computation this way because you're not
sure when or if you'll be consuming the sequence produced by line-seq,
then this becomes a hard problem.

// ben

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Cannot access variables without namespace in ClojureScript repl.

2012-01-15 Thread Brenton
I think the problem here is with the ClojureScript REPL and single-
segment namespaces.

We found a couple of problems with the ClojureScript REPL while
working on One and will address them soon. If you confirm that this is
the problem, please let us know. Also, feel free to add an issue to
JIRA with the steps to reproduce.

Thanks,
Brenton

On Jan 15, 6:57 am, Takahiro Hozumi fat...@googlemail.com wrote:
 Hi,
 In my browser repl, which follows the ClojureScript wiki[1], I must
 specify variables with namespace even if `in-ns` is used, but I
 noticed that I don't have to do in the repl of ClojureScript One[2].

 Am I the only one who cannot access variables without namespace?
 What makes the diffirence?

 log:
 ClojureScript:cljs.user (in-ns 'myns)

 ClojureScript:myns myns/mydiv     ;;with a namespace
 #[object HTMLDivElement]

 ClojureScript:myns mydiv             ;;without a namespace
 Error evaluating: mydiv :as .mydiv;\n
 #SyntaxError: Unexpected token .
 SyntaxError: Unexpected token .
     athttp://localhost:8080/cljs/clojure/browser/repl.js:21:158

 [1]https://github.com/clojure/clojurescript/wiki/Emacs-%26-inferior-lisp...
 [2]https://github.com/brentonashworth/one/wiki/Development

 Thanks.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Cannot access variables without namespace in ClojureScript repl.

2012-01-15 Thread Takahiro
Hi Brenton,
Unfortunately two segment namespaces also causes the same problem.
However, I've found that this problem can be avoided by using `ns`
instead of `in-ns`.

Thanks!

2012/1/15 Brenton bashw...@gmail.com:
 I think the problem here is with the ClojureScript REPL and single-
 segment namespaces.

 We found a couple of problems with the ClojureScript REPL while
 working on One and will address them soon. If you confirm that this is
 the problem, please let us know. Also, feel free to add an issue to
 JIRA with the steps to reproduce.

 Thanks,
 Brenton

 On Jan 15, 6:57 am, Takahiro Hozumi fat...@googlemail.com wrote:
 Hi,
 In my browser repl, which follows the ClojureScript wiki[1], I must
 specify variables with namespace even if `in-ns` is used, but I
 noticed that I don't have to do in the repl of ClojureScript One[2].

 Am I the only one who cannot access variables without namespace?
 What makes the diffirence?

 log:
 ClojureScript:cljs.user (in-ns 'myns)

 ClojureScript:myns myns/mydiv     ;;with a namespace
 #[object HTMLDivElement]

 ClojureScript:myns mydiv             ;;without a namespace
 Error evaluating: mydiv :as .mydiv;\n
 #SyntaxError: Unexpected token .
 SyntaxError: Unexpected token .
     athttp://localhost:8080/cljs/clojure/browser/repl.js:21:158

 [1]https://github.com/clojure/clojurescript/wiki/Emacs-%26-inferior-lisp...
 [2]https://github.com/brentonashworth/one/wiki/Development

 Thanks.

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Proxies and overriding protected methods

2012-01-15 Thread Cedric Greevey
On Sun, Jan 15, 2012 at 6:52 AM, Norman Gray norman.x.g...@gmail.com wrote:

 Greetings.

 I'm not understanding proxies.  Can anyone advise me what I'm missing?

 I try the following:

 user= (def m (proxy [java.util.HashMap] []
 (finalize []
   ;(proxy-super finalize)
   (prn finalizing...))
 (hashCode []
   99)))
 #'user/m
 user= (.hashCode m)
 99
 user= (.finalize m)
 IllegalArgumentException No matching field found: finalize for class 
 user.proxy$java.util.HashMap$0  clojure.lang.Reflector.getInstanceField 
 (Reflector.java:289)
 user= (ancestors m)
 nil
 user=

 (the 'proxy-super' is commented out, just to reassure myself that its 
 presence is not somehow the root of the problem)

 I'm afraid that the documentation of the 'proxy' macro is too terse for me to 
 work out what's supposed to be happening here.

(TL;DR version: just skip to the end.)

It's actually the case that most other clojure.core docstrings are
even terser. :)

 The documentation says that 'proxy' creates a instance of a proxy class that 
 implements the named class/interface(s) by calling the supplied fns.  That 
 suggests (without quite saying so) that 'm' should be an extension of class 
 java.util.HashMap, in this case, and this is corroborated by the remark that 
 If a method fn is not provided for a class method, the _superclass_ methd 
 will be called (my emphasis, note the docs' misspelling of 'methd').  
 However, the null result of (ancestors m) suggests instead that 'm' extends 
 only Object, and that it handles _all_ of its method calling by delegation 
 through reflection on the class being proxied.

Actually, ancestors expects a class rather than an instance, and
returns nil for anything that's not a class.

user= (def x (proxy [Object][] (finalize [] (println foo!
#'user/x
user= (def y (.getClass x))
#'user/y
user= (ancestors y)
#{java.lang.Object clojure.lang.IProxy}

Presto: two Class objects representing superclasses/interfaces
inherited by the class y of the proxy object x.

Furthermore:

user= (seq (.getMethods y))
(#Method public void
user.proxy$java.lang.Object$0.__initClojureFnMappings(clojure.lang.IPersistentMap)
 #Method public void
user.proxy$java.lang.Object$0.__updateClojureFnMappings(clojure.lang.IPersistentMap)
 #Method public clojure.lang.IPersistentMap
user.proxy$java.lang.Object$0.__getClojureFnMappings()
 #Method public boolean user.proxy$java.lang.Object$0.equals(java.lang.Object)
 #Method public java.lang.String user.proxy$java.lang.Object$0.toString()
 #Method public int user.proxy$java.lang.Object$0.hashCode()
 #Method public java.lang.Object user.proxy$java.lang.Object$0.clone()
 #Method public final native void java.lang.Object.wait(long) throws
java.lang.InterruptedException
 #Method public final void java.lang.Object.wait() throws
java.lang.InterruptedException
 #Method public final void java.lang.Object.wait(long,int) throws
java.lang.InterruptedException
 #Method public final native java.lang.Class java.lang.Object.getClass()
 #Method public final native void java.lang.Object.notify()
 #Method public final native void java.lang.Object.notifyAll())

Note: no finalize.

Javadocs for Object show finalize, so it's part of Object and should
at least be inherited even if not overridden. The getMethods call
obviously shows inherited, unoverridden methods as it shows several
final methods of Object such as notifyAll. What is going on here?

Javadocs for Class.getMethod show this: Returns an array containing
Method objects reflecting all the public member methods...

So, nonpublic methods aren't shown. Proxy seems to provide a public
override of clone automatically, but finalize obviously remained
protected, rather than the proxy override in x being public rather
than protected.

So, your problem is actually very simple: you tried to call a
protected method from an unrelated class, which won't even work with
reflection. At least, not normally.

Indeed:

user= (.finalize (Object.))
#IllegalArgumentException java.lang.IllegalArgumentException: No
matching field found: finalize for class java.lang.Object

Same error, with a plain Object.

A different way of calling the method produces a more accurate message:

user= (def z (.getDeclaredMethod Object finalize (into-array Class [])))
#'user/z

Now we have a method handle for Object's finalize method.

user= (.invoke z (Object.) (into-array Object []))
#IllegalAccessException java.lang.IllegalAccessException: Class
user$eval673 can not access a member of class java.lang.Object with
modifiers protected

At the JVM level, your REPL evaluations become little classes with
names like user$eval673. From a given class, such as user$eval673, you
can normally only access protected members of an instance of that
class. This includes inherited ones, unlike with private members, but
the class of the object you're invoking a protected method of must be
the same as or a subclass of the class containing the method invoking

Re: Proxies and overriding protected methods

2012-01-15 Thread Norman Gray

Cedric, hello.

On 2012 Jan 15, at 20:32, Cedric Greevey wrote:

 On Sun, Jan 15, 2012 at 6:52 AM, Norman Gray norman.x.g...@gmail.com wrote:

 user= (def m (proxy [java.util.HashMap] []
(finalize []
  ;(proxy-super finalize)
  (prn finalizing...))
(hashCode []
  99)))
 #'user/m
 user= (.hashCode m)
 99
 user= (.finalize m)
 IllegalArgumentException No matching field found: finalize for class 
 user.proxy$java.util.HashMap$0  clojure.lang.Reflector.getInstanceField 
 (Reflector.java:289)

 (TL;DR version: just skip to the end.)

(not too long at all; read avidly)

I'll work through this again tomorrow, but a couple of things occur to me now.

 Actually, ancestors expects a class rather than an instance, and
 returns nil for anything that's not a class.

Aha.  That's not particularly obvious from the 'ancestors' docs  But I do 
see that in my case above, the new object appears to have some sort of subclass 
relationship with java.util.HashMap:

user= (ancestors (.getClass m)) 
#{clojure.lang.IProxy java.lang.Object java.io.Serializable java.util.Map 
java.util.HashMap java.lang.Cloneable java.util.AbstractMap}

Excellent -- that makes sense.

 So, your problem is actually very simple: you tried to call a
 protected method from an unrelated class, which won't even work with
 reflection. At least, not normally.

Section 6.6.2 of the JLS mentions that A protected member or constructor of an 
object may be accessed from outside the package in which it is declared only by 
code that is responsible for the implementation of that object  (this is 
echoed in Sect 2.7.4 of the JVM spec). Now, the text which follows that seems 
to boil down to saying that subclass implementations can see protected instance 
fields or methods, which we all know, of course.

Also, you established that methods overridden in a proxy are public.

What those two statements appear to mean is that the overriding finalize method 
should be a public one, and that it should be able to call its super.finalize() 
method (of course, in this case the fact that finalize is public doesn't really 
matter, since what matters is that the GC can call finalise(), but we want to 
be able to call finalize() explicitly only to verify that it's there and doing 
what it should)

You conclude that:

 So, a proxy [...] will NOT override Object's finalize method, EVEN IF 
 explicitly
 told to do so and given an implementation for such an override.
 
 Apparently it's treating that as a special case, either as an
 undocumented but intentional limitation of the proxy facility of
 clojure or else as a bug perhaps caused by the JVM treating finalize
 specially.

And further...

 Any further information is probably going to have to come, directly or
 indirectly, from someone who is knowledgeable about the intentions of
 the developers of the proxy macro, and not via the docs, since the
 docs, as you're aware, are mute on any special limitations on which
 protected methods can be overridden (they say only that they can be in
 general, but the user-supplied proxy code will not have access to
 protected fields of the proxied class).

There seem to be a couple of possibilities.

  * There's an edge-case of the legalese in JLS 6.6.2 or JVMS 2.7.4 or 5.4.4 
that is triggered by Clojure's implementation of the proxy class, and which is 
beyond my current forensic powers to spot.

  * Or there's a special case.  The 'generate-proxy' function in 
https://github.com/clojure/clojure/blob/master/src/clj/clojure/core_proxy.clj 
does mention finalize in a test which apparently excludes specifically that 
method from a set of supers' non-private instance methods, but I can't work 
out quite what it's doing with those.  It _may_ be that the goal there is to 
automatically call super.methods for each method in the proxy, and I can see 
why one would want finalize() to be exempt from that, but if so, it may be this 
code which is, inadvertantly or not, preventing extending-classes adding 
finalizers.

The fact that (as you note) the proxy code is documented not to have access to 
protected members does suggest that the proxying class is at least not 
straightforwardly a subclass of the base class.  The Joy of Clojure mentions 
(p196) that Clojure doesn't encourage implementation inheritance, that 
gen-class and proxy only provide something like Java-style implementation 
inheritance, and  suggests (p210) that proxy classes trade flexibility for 
performance.  In this case, I can broadly understand why 'proxy' isn't 
producing what I think, or at least thought, it was producing (a 
straightforward subclass of the proxied class).  But in that case, I'm stumped, 
and don't know how I would go about overriding a finalize() method in an 
idiomatic and non-painful (ie non-gen-class) way.

Best wishes,

Norman


-- 
Norman Gray  :  http://nxg.me.uk



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To 

Re: Libraries for ClojureScript.

2012-01-15 Thread ckirkendall
Manjo,
I think there is considerable benefit in keeping certain APIs similar
between ClojureScript and Clojure.  In places where the intent is the
same I would suggest going with a familiar API.  I took this approach
with enfocus by basing it on enlive.  It sped up my development
because I didn't have to ponder if the semantics were usable. In the
places where my feature set didn't line up, I found myself working and
reworking the apis because they weren't clean enough or they seemed
confusing.  All of that being said, ClojuresSript is very young and I
don't think we have a right way to do things yet. Right now I would be
willing to try any testing library regardless if it matched
Clojure.

Creighton Kirkendall

On Jan 15, 12:37 am, mmwaikar mmwai...@gmail.com wrote:
 Hi,

 My question is about design of libraries for ClojureScript.

 So for ex, there is clojure.test which has some public API. Now assume one
 has used it and is comfortable with its API.
 Now he has to write some ClojureScript code and wants to write some unit
 tests as well.

 Obviously, he'll use some pre-existing JS library / framework, but it will
 have its own API.
 Now -

 1) Does it make sense to write a ClojureScript wrapper over existing JS
 libraries (as there are wrappers over many Java libraries / frameworks)?
 2) Does it make sense, or is it better if this ClojureScript wrapper,
 exposes the same (as far as possible) or similar API to that of one of the
 Clojure libraries? The obvious advantage being the programmer has to get
 accustomed to just one API, which works for Clojure as well as
 ClojureScript.

 Please let me know your views.

 Thanks,
 Manoj.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Lazy sequence efficiency/hashing efficiency tradeoff

2012-01-15 Thread Cedric Greevey
Something got me thinking about the hashes of sequences, and I
realized there would be an efficiency tradeoff there. The hash ought
to depend on at least some of the head elements of the seq, or hash
lookup efficiency goes to hell when seqs are used as map keys or in
sets. The more elements of the seq are used, the better the hash gets,
but with diminishing returns. On the other hand, the more elements of
the seq are used, the more elements of a *lazy* seq must be *realized*
if it is used as a key or placed in a set.

This made me wonder where the tradeoff was, so I wrote this pair of
functions to play warmer-colder with:

(defn q1 [n x] (concat (range n) [x]))
(defn q2 [n] (= (.hashCode (q1 n foo)) (.hashCode (q1 n bar

I figured the minimum n needed to get a true return from q2 would be a
small integer, but the result was rather surprising:

user= (q2 5)
false

It seems to be using potentially all of the elements, which seems
rather inefficient when a few will be enough to get rid of most hash
collisions for commonplace data and in the absence of a collision an
equality test (which needs all the elements up to the first
difference) can be avoided until lookup time, deferring the
realization of potentially very many lazy sequence elements. What's
the rationale here? Are hash collisions caused by differing seqs with
long identical prefixes expected to be commonplace? With strings long
identical prefixes are frequent (e.g. file paths all in some deeply
nested directory, or URLs with similar structure) but this tends to
occur only in situations where long means several tens of
characters and occasionally even more than 100, not fifty thousand or
more...

I also noticed that though using all of the elements (if that is
indeed what it does) permits making the hash consistent with String's
(i.e. (seq foo) and foo would have the same hash) and with the
hashes of vectors, we actually have:

user= (map #(.hashCode %) [foo (seq foo) [\f \o \o]])
(101574 131365 131365)

Vectors and their seqs do indeed appear to have the same hash (right
off this one data point we already have 10^5-to-one odds against their
not doing so, since if they don't then the two identical numbers in
the output above, given their order of magnitude, are a
10^5-to-one-against coincidence *or worse* [more below]). However,
strings seem not to equal their own seqs as to hash code.

Vectors and seqs with the same content in the same order also compare
equal, but a string and its seq don't. (Fortunately, given that they
have different hashes.)

[The exact argument for the probabilities uses Bayes's Theorem: P(A|B)
= P(B|A)P(A)/P(B). If A is the algorithms are different and B is
the hashes are identical, P(B|A) is no more than about 0.1 if
the hashes are fairly uniform on a range spanning at least from 1 to
the observed numbers. A good hash function *should* be fairly uniform
and the actual range of Java hashes spans from -2,147,483,658 to
2,147,483,647 so 0.1 is quite conservative. Suppose we accept a
prior probability of 0.5 for A. Then P(B) would have to be 0.5 +
0.5P(B|A) ~ 0.5, since P(B|A) is very small, and P(A|B) ~ P(B|A) is
also very small. So if we started out with a coin-toss guess as to
whether the null hypothesis A was correct, we'd now be rejecting it
with a pretty strong confidence! Even starting with a likely
probability of 0.9 for A gives P(B) = 0.1 + 0.9P(B|A) ~ 0.1 and
P(A)/P(B) ~ 9, and we still end up rejecting A with a lot of
confidence, as 0.9 is still a very small number. Now, strictly
speaking, we'd have to have chosen the string randomly and uniformly
on some large space of strings to call this number anything close to
scientific, but I'd say it's still a pretty good bet that ... oh why
not just check it: digs up source code Seems that APersistentVector
and ASeq implement hashCode separately, but do indeed use the same
algorithm. It also looks like ASeq's indeed doesn't stop until (and
unless!) it runs out of sequence to consume. The duplication of the
algorithm is presumably for efficiency versus APersistentVector's
using _hash = seq().hashCode(); instead when it computes its hash,
which would wrap the traversal in an extra layer of method calls and
create temporary objects for every element traversed. Still, *why* not
just externalize the algorithm to a static method of clojure.lang.Util
that takes an Iterator and call that from both places? The vector
version already uses the vector's iterator and meanwhile the seq
iterator exists and isn't going to be much less efficient than the
direct traversal in ASeq.hashCode.]

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at

Re: does symbol completion work after 2nd slime-compile-and-load-file ?

2012-01-15 Thread Phil Hagelberg
Andrew ache...@gmail.com writes:

 or is M-x slime-compile-and-load-file the wrong command to use? 

You should use C-c C-k for most compilation. If you want to force a
reload of all the required namespaces, you can use C-c C-l instead. I've
never heard of either of these affecting completion though.

-Phil

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


ClojureScript in IE 9 (does it work?)

2012-01-15 Thread gchristnsn
I can't even call `(js/alert test)' in IE 9, it compiles into:

alert.call(null,test);

and says: Invalid calling object (IE 9 standards mode, in IE 8
standards mode it doesn't recognize the `call' method)

I need `alert' to debug some other glitch which arises in IE 9 (but
all works fine in other browsers), is it by design?

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en