Bill James | 1 Feb 01:33 2011
Picon

Re: Ridiculously massive slowdown when working with images

On Jan 31, 1:40 pm, Bill James <w_a_x_... <at> yahoo.com> wrote:
> (set! *warn-on-reflection* true)
>
> (def buffer-size 1920000)
> (def array (byte-array buffer-size))
>
> (defmacro add [m n] `(unchecked-add (int ~m) (int ~n)))
> (defmacro uinc [m] `(unchecked-inc ~m))
> (defmacro amove[a i j] `(aset ~a ~j (aget ~a ~i)))
>
> (defn java-like0 [^bytes cpu_array]
>   (loop [i (int 0)]
>     (if (< i (int buffer-size))
>       (let [b (byte (aget cpu_array i))
>             g (byte (aget cpu_array (unchecked-add i (int 1))))
>             r (byte (aget cpu_array (unchecked-add i (int 2))))
>             a (byte (aget cpu_array (unchecked-add i (int 3))))]
>         (aset cpu_array i a)
>         (aset cpu_array (unchecked-add i (int 1)) b)
>         (aset cpu_array (unchecked-add i (int 2)) g)
>         (aset cpu_array (unchecked-add i (int 3)) r)
>         (recur (unchecked-add i (int 4)))))))
>
> ;;;  Make buffer-size a local.
> (defn java-like1 [^bytes cpu_array]
>   (let [buffer-size (int buffer-size)]
>     (loop [i (int 0)]
>       (if (< i (int buffer-size))
>         (let [b (byte (aget cpu_array i))
>               g (byte (aget cpu_array (unchecked-add i (int 1))))
(Continue reading)

Alex Miller | 1 Feb 01:33 2011

Re: how to print-dup records?

We wrapped defrecord in a macro that created a factory function then
had print-dup print a call to that function.

https://github.com/david-mcneil/defrecord2

You can also find pprint in there too.

On Jan 31, 11:26 am, Seth <wbu... <at> gmail.com> wrote:
> This is my attempt:
>
> (defn record? [a]
>   (and (map? a) (not (instance? clojure.lang.APersistentMap a))))
>
> (defmethod print-dup clojure.lang.IPersistentMap [m, ^Writer w]
>   (if (record? m)
>     (do (.write w "#=(")
>         (print-dup (class m) w) (.write w ". ")
>         (doall (map #(do (print-dup % w) (.write w " ")) (map second (seq
> m))))
>         (.write w ")")
>         )
>     (do
>       (#'clojure.core/print-meta m w)
>       (.write w "#=(")
>       (.write w (.getName (class m)))
>       (.write w "/create ")
>       (#'clojure.core/print-map m print-dup w)
>       (.write w ")"))))
>
> ;;used fromhttp://groups.google.com/group/clojure/browse_thread/thread/cb5246d07...
(Continue reading)

Jason Wolfe | 1 Feb 05:33 2011

Defrecord and = docstring clarifications (regarding record equality)

I just ran into the following surprise:

user> (defrecord P [])
user.P
user> (defrecord Q [])
user.Q
user> (= (P.) (Q.))
false
user> (.equals (P.) (Q.))
true

This is not a bug (but I do find it confusing -- I did not expect (P.)
and (Q.) to collide as map keys):
http://groups.google.com/group/clojure/browse_frm/thread/7ba5215d59f2f177

However, the docstring of defrecord says it "will define type-and-
value-based equality and hashCode".   Perhaps this could be
clarified?

Along the same lines, the docstring of = says "same as Java
x.equals(y), except it ... compares numbers and collections in a type-
independent manner".   To me, this seems to imply the opposite of what
actually happens with records.

Thanks, Jason

--

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure <at> googlegroups.com
(Continue reading)

Ken Wesson | 1 Feb 05:43 2011
Picon

Re: Defrecord and = docstring clarifications (regarding record equality)

On Mon, Jan 31, 2011 at 11:33 PM, Jason Wolfe <jason <at> w01fe.com> wrote:
> I just ran into the following surprise:
>
> user> (defrecord P [])
> user.P
> user> (defrecord Q [])
> user.Q
> user> (= (P.) (Q.))
> false
> user> (.equals (P.) (Q.))
> true
>
> This is not a bug (but I do find it confusing -- I did not expect (P.)
> and (Q.) to collide as map keys):
> http://groups.google.com/group/clojure/browse_frm/thread/7ba5215d59f2f177
>
> However, the docstring of defrecord says it "will define type-and-
> value-based equality and hashCode".   Perhaps this could be
> clarified?

It seems clear enough to me that type is a factor in equality.

The real bug here is that .equals returns true in this case.

> Along the same lines, the docstring of = says "same as Java
> x.equals(y), except it ... compares numbers and collections in a type-
> independent manner".   To me, this seems to imply the opposite of what
> actually happens with records.

There is where clarification is needed, namely that records are not
(Continue reading)

Bill James | 1 Feb 06:10 2011
Picon

Re: Ridiculously massive slowdown when working with images

On Jan 31, 1:33 pm, Bill James <w_a_x_... <at> yahoo.com> wrote:
> On Jan 31, 5:46 am, B Smith-Mannschott <bsmith.o... <at> gmail.com> wrote:
>
> > > Yes, that speeds it up considerably.  If I can get Java server
> > > installed
> > > on my machine, I'll post some timings.
>
> > What is this "java server" of which you speak.  In JVMs I'm familiar
> > with (Sun/Oracle, OpenJDK) it's just a matter of passing the option
> > -server to java when starting it.
>
> > // Ben
>
> Usually Windoze doesn't have the Java server executable.
> You have to download the Java JDK.

More precisely, the missing file is
C:\Program Files\Java\jre6\bin\server\jvm.dll

--

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure <at> 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+unsubscribe <at> googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

(Continue reading)

Robert McIntyre | 1 Feb 08:04 2011
Picon

Re: How to disallow unlisted optional argument keys?

You win sir.  That is the most beautiful way.

sincerely,
--Robert McIntyre

On Sun, Jan 30, 2011 at 7:59 PM, Bill James <w_a_x_man <at> yahoo.com> wrote:
> Alexander Yakushev wrote:
>> Why not use a constraint? It looks much cleaner.
>>
>> (defn hello [& {:keys [a b] :as input}]
>>          {:pre [(= (set (keys input)) #{:a :b})]}
>>          "hello")
>>
>> You can learn more about constraints here: http://vimeo.com/channels/fulldisclojure#8399758
>
>
> {:pre [(clojure.set/subset? (set (keys input)) #{:a :b})]}
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure <at> 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+unsubscribe <at> 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
(Continue reading)

.Bill Smith | 1 Feb 15:34 2011
Picon

Re: How to disallow unlisted optional argument keys?

Yes, that's very succinct.  Of course, it isn't cheap.  I mean I wouldn't put it in the inner loop of Robert's image processing code.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure <at> 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+unsubscribe <at> googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
Saul Hazledine | 1 Feb 16:50 2011
Picon

LDAP library?

Hello,
  This question has been asked before but it was over a year ago. I
need to start using Clojure with LDAP and I was wondering if anybody
had written a clojure library to do this rather than using the
standard Java JNDI API (which doesn't look like much fun and is a
further abstraction on top of LDAP).

I am looking for something simple that allows me to lookup/add/delete/
edit an entry for a given distinguished name without any fancy
searching. I'd like connection pools though.

I'm thinking of writing a thin layer on top of the Unbound SDK if
nothing else is available:
http://www.unboundid.com/products/ldapsdk/

Has anyone done this already?
Saul

--

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure <at> 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+unsubscribe <at> googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

George Jahad | 1 Feb 21:39 2011
Picon

a handy little function I haven't seen before

get-all-fields dumps all the fields contained by the object.  Handy
for exploring functions with closures, like those created by partial,
comp, and memoize.

https://gist.github.com/806595

--

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure <at> 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+unsubscribe <at> googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Straszheim, Jeff | 1 Feb 22:09 2011

Weird nested macro problem

So, I have a macro that looks something like this:

(defmacro test-failure
  [& forms]
  `(handler-case :type
     ~ <at> forms
     (~'handle :error/error
       (println "error happened"))))

(My real macro is more complex, but this gives the idea.)

If I eval

 (test-failure (println "test"))

I get:

 => Unable to resolve symbol: handle in this context

However, if I macroexpand-1 the thing, I get:

 (macroexpand-1 '(test-failure (println "test")))

 => (clojure.contrib.condition/handler-case :type (println "test") (handle :error/error
(clojure.core/println "error happened")))

That is correct, and if I eval just that it works fine.

Here is an interesting thing:  if I do this:

 (macroexpand '(test-failure (println "test")))

I get

 => (try (println "test") (handle :error/error (clojure.core/println "error happened")) (catch
clojure.contrib.condition.Condition c__19__auto__ (clojure.core/binding
[clojure.contrib.condition/*condition-object* c__19__auto__
clojure.contrib.condition/*condition* (clojure.core/meta c__19__auto__)
clojure.contrib.condition/*selector* (:type (clojure.core/meta c__19__auto__))]
(clojure.core/cond :else (clojure.contrib.condition/raise)))))

It's expanded the handler-case part, but the "handle" is still there.  That seems wrong to me.

I've tried lots of different ways to specify handle besides ~'handle, but they all seem to fail.

Any suggestions?

--

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure <at> 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+unsubscribe <at> googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Gmane