Re: Where should 'if-let-all' macro go?

2015-06-10 Thread Mike Rodriguez
I'll chime in with my opinion on this topic. 

I think the existing if-let and similar forms that have a limitation of only 
allowing a single binding is a confusing restriction to place on the familiar 
binding vector construct. I've always been a little uneasy about repurposing 
binding vectors for this restricted single-binding use case.  I'd probably have 
preferred something more like as->, where there is a direct form binding pair. 
However I guess that would ruin the ability to destructure. Just a thought, I 
can live with if-let and it's slightly awkward binding vector though. 

With that said, and as others have mentioned here, I can't imagine this 
proposed if-let-all macro having clear enough semantics to be something in 
Clojure core. There are just way too many caveats and ways to interpret it. I 
can see the motivation for it, but maybe there is a better design to achieve it.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question regarding java array

2015-06-10 Thread Steven Yi
As mentioned by Colin and Andy, I would guess it would be some form of 
boxing and reflection going on.  I tried the following:

(defn array-max [^doubles arr]

  (let [len (alength arr)]

(loop [m Double/NEGATIVE_INFINITY indx 0]

  (if (< indx len)

(recur (max m (aget arr indx)) (unchecked-inc indx))

m


user=> (let [vs (amap (double-array 128) idx ret (Math/random))] 

   (time (array-max vs))) 

"Elapsed time: 3.719835 msecs"

To note, if you check out the source of areduce:

user=> (source areduce)

(defmacro areduce

  "Reduces an expression across an array a, using an index named idx,

  and return value named ret, initialized to init, setting ret to the 

  evaluation of expr at each step, returning ret."

  {:added "1.0"}

  [a idx ret init expr]

  `(let [a# ~a]

 (loop  [~idx 0 ~ret ~init]

   (if (< ~idx  (alength a#))

 (recur (unchecked-inc ~idx) ~expr)

 ~ret


It's just a macro, and so typehinting is going to play a factor.  For 
example, with areduce and a type hint on the array:


(defn array-max2 [^doubles arr]

  (areduce arr idx ret Double/NEGATIVE_INFINITY (max ret (aget arr idx

user=> (let [vs (amap (double-array 128) idx ret (Math/random))] (time 
(array-max vs))) 

 "Elapsed time: 3.314599 msecs"


But with no type hint on arr:


(defn array-max2 [arr]

  (areduce arr idx ret Double/NEGATIVE_INFINITY (max ret (aget arr idx

user=> (let [vs (amap (double-array 128) idx ret (Math/random))] (time 
(array-max2 vs))) 

"Elapsed time: 35612.919192 msecs"


Without a typehint on the arr argument, I also do get boxed math and 
reflection warnings:


Reflection warning, 
/private/var/folders/0k/xj_drd990xxf4q99n2bdknrcgn/T/form-init1595291808747030463.clj:2:3
 
- call to static method alength on clojure.lang.RT can't be resolved 
(argument types: unknown).

Boxed math warning, 
/private/var/folders/0k/xj_drd990xxf4q99n2bdknrcgn/T/form-init1595291808747030463.clj:2:3
 
- call: public static boolean 
clojure.lang.Numbers.lt(long,java.lang.Object).

Reflection warning, 
/private/var/folders/0k/xj_drd990xxf4q99n2bdknrcgn/T/form-init1595291808747030463.clj:2:58
 
- call to static method aget on clojure.lang.RT can't be resolved (argument 
types: unknown, int).

Boxed math warning, 
/private/var/folders/0k/xj_drd990xxf4q99n2bdknrcgn/T/form-init1595291808747030463.clj:2:49
 
- call: public static java.lang.Object 
clojure.lang.Numbers.max(double,java.lang.Object).

form-init1595291808747030463.clj:2 recur arg for primitive local: ret is 
not matching primitive, had: Object, needed: double

Auto-boxing loop arg: ret

Reflection warning, 
/private/var/folders/0k/xj_drd990xxf4q99n2bdknrcgn/T/form-init1595291808747030463.clj:2:3
 
- call to static method alength on clojure.lang.RT can't be resolved 
(argument types: unknown).

Boxed math warning, 
/private/var/folders/0k/xj_drd990xxf4q99n2bdknrcgn/T/form-init1595291808747030463.clj:2:3
 
- call: public static boolean 
clojure.lang.Numbers.lt(long,java.lang.Object).

Reflection warning, 
/private/var/folders/0k/xj_drd990xxf4q99n2bdknrcgn/T/form-init1595291808747030463.clj:2:58
 
- call to static method aget on clojure.lang.RT can't be resolved (argument 
types: unknown, int).

Boxed math warning, 
/private/var/folders/0k/xj_drd990xxf4q99n2bdknrcgn/T/form-init1595291808747030463.clj:2:49
 
- call: public static java.lang.Object 
clojure.lang.Numbers.max(java.lang.Object,java.lang.Object).



On Wednesday, June 10, 2015 at 4:07:09 PM UTC-4, Ritchie Cai wrote:
>
> I'm working on a java array of double with 128 elements. I need the 
> max and min values of the array. So I initially tried areduce and loop, 
> both gives runs around 20 seconds. But when try (apply max (vec array)) I 
> get result under 90 ms.
> Can anyone explain why there is such a big difference?
> Also if want to iterate large java array like this to do some other 
> operations, e.g. convolution, what's the best way to go? Is there another 
> fast way to iterate through array or do I need to convert array into vector?
>
> Thanks
> Ritchie
>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RFC: Collider: Clojure's collections for Java developers

2015-06-10 Thread Ryan Schmitt
I've been developing a library that wraps Clojure's collections for use in 
Java 8 development:

https://github.com/rschmitt/collider

http://rschmitt.github.io/collider/javadoc/

Like my other major Java project, DynamicObject 
, the goal here is two-fold:

(1) Bring the best of Clojure to Java developers (without ruining it), 
thereby making functional programming easier and more familiar
(2) Make the Clojure jar file as common as possible on people's classpaths, 
thereby lowering the bar to Clojure adoption

I'd appreciate any feedback people have on the design: how things are 
structured, named, documented, tested, and so on. I haven't decided to 
stabilize the library yet, so there's still time for breaking changes to be 
made.

Incidentally, the main project I'm aware of that's similar to this is clj-ds 
, a standalone partial fork of Clojure. 
That also looks like a good approach to me, and fairly well-executed; it 
just has different tradeoffs. In particular, I like being able to target 
Java 8. I also like being able to wrap whatever version of Clojure is on 
the runtime classpath.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question regarding java array

2015-06-10 Thread Mikera
Consider using core.matrix with vectorz-clj for operations on large 
numerical arrays / vectors of doubles. It is a *lot* faster than using 
Clojure vectors for this kind of scenario, plus it has a lot of helpful 
array operations already defined.

(use 'clojure.core.matrix)
(def v (array :vectorz (range 128)))

(time (emax v))
=> 127.0
"Elapsed time: 1.179533 msecs"


On Wednesday, 10 June 2015 21:07:09 UTC+1, Ritchie Cai wrote:
>
> I'm working on a java array of double with 128 elements. I need the 
> max and min values of the array. So I initially tried areduce and loop, 
> both gives runs around 20 seconds. But when try (apply max (vec array)) I 
> get result under 90 ms.
> Can anyone explain why there is such a big difference?
> Also if want to iterate large java array like this to do some other 
> operations, e.g. convolution, what's the best way to go? Is there another 
> fast way to iterate through array or do I need to convert array into vector?
>
> Thanks
> Ritchie
>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: using the same middleware (wrap-multipart-params) with different parameters in one app [ring] [compojure]

2015-06-10 Thread Sebastián Moreno
I know this is an old thread, but I came across the same issue today, I 
ended up with something like:

(POST "/upload" request
(multipart/wrap-multipart-params
  (fn [{{file "file"} :params}]
(handle-updload file

Sebastián

On Friday, April 4, 2014 at 2:39:23 AM UTC-3, K Livingston wrote:
>
> I'm trying to dynamically handle the InputStream in file uploads 
> (ring/compojure app via servlet/jetty).  I started with two different 
> versions of the wrap-multipart-params, one is basically a NoOp that just 
> returns the file name, and the other echoes the file back.  They both work 
> fine independently but when I try to bring them both online together, which 
> ever store is defined first is the one I see called regardless of handler.
>
> Can I only have one copy of wrap-multipart-params in the whole app?
>
> How can I change how the InputStream is handled depending on the handler?
>
> Do I need to just have the handler return the IO stream and then change 
> the behavior in each handler function?
>
> example:
> The logging store is called even with POST to /upload-echo.  The echo 
> store is never called.
>
> (defroutes file-list-routes
>   (GET "/list-content"  request (file-list/show-file-list request))
>
>   (GET "/upload-logging" request 
>(upload/simple-upload-file "upload-logging" request))
>   (mp/wrap-multipart-params 
>(POST "/upload-logging" request (upload/upload-logging-file request))
>{:store upload/logging-store})
>
>   (GET "/upload-echo" request 
>(upload/simple-upload-file "upload-echo" request))
>   (mp/wrap-multipart-params 
>(POST "/upload-echo" request (upload/upload-echo-file request))
>{:store upload/echo-store})
>
>   );end route list
>
> These routes are then nested into some other context calls and of course 
> other middleware, until eventually making it up to the servlet.  There are 
> no other calls to wrap-multipart-params in my application.
>
> Thanks for your help,
> Kevin
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question regarding java array

2015-06-10 Thread Colin Yates
Will guess in the dark but would boxing come into play here?

> On 10 Jun 2015, at 21:03, Ritchie Cai  wrote:
> 
> I'm working on a java array of double with 128 elements. I need the max 
> and min values of the array. So I initially tried areduce and loop, both 
> gives runs around 20 seconds. But when try (apply max (vec array)) I get 
> result under 90 ms.
> Can anyone explain why there is such a big difference?
> Also if want to iterate large java array like this to do some other 
> operations, e.g. convolution, what's the best way to go? Is there another 
> fast way to iterate through array or do I need to convert array into vector?
> 
> Thanks
> Ritchie
> 
> 
> -- 
> 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 unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question regarding java array

2015-06-10 Thread Andy Fingerhut
Add this line at the top of your file where you try areduce and loop, and
look for any reflection warnings that occur when loading the file:

(set! *warn-on-reflection* true)

If there are none, probably best to post a link to your code, or paste it
in a message here if it is short enough, so others can give more precise
suggestions.

Andy

On Wed, Jun 10, 2015 at 1:03 PM, Ritchie Cai  wrote:

> I'm working on a java array of double with 128 elements. I need the
> max and min values of the array. So I initially tried areduce and loop,
> both gives runs around 20 seconds. But when try (apply max (vec array)) I
> get result under 90 ms.
> Can anyone explain why there is such a big difference?
> Also if want to iterate large java array like this to do some other
> operations, e.g. convolution, what's the best way to go? Is there another
> fast way to iterate through array or do I need to convert array into vector?
>
> Thanks
> Ritchie
>
>  --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Question regarding java array

2015-06-10 Thread Ritchie Cai
I'm working on a java array of double with 128 elements. I need the max 
and min values of the array. So I initially tried areduce and loop, both 
gives runs around 20 seconds. But when try (apply max (vec array)) I get 
result under 90 ms.
Can anyone explain why there is such a big difference?
Also if want to iterate large java array like this to do some other 
operations, e.g. convolution, what's the best way to go? Is there another 
fast way to iterate through array or do I need to convert array into vector?

Thanks
Ritchie

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANN] Onyx 0.6.0

2015-06-10 Thread Nathan ToddStone
Awesome!

On Tuesday, June 9, 2015 at 7:35:33 AM UTC-7, Michael Drogalis wrote:
>
> I'm happy to announce that Onyx 0.6.0 is officially out!
>
> Blog post: 
> http://michaeldrogalis.github.io/jekyll/update/2015/06/08/Onyx-0.6.0:-Going-Faster.html
> GitHub: https://github.com/onyx-platform/onyx
> Website: www.onyxplatform.org
> Chat: https://gitter.im/onyx-platform
>
> Thanks to all the contributors that helped make this happen!
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Actually using component.

2015-06-10 Thread Dru Sellers
I really am dense at times. :(

I was confusing the 'component' for the system map in this 
line: 
https://github.com/weavejester/duct/blob/master/duct/src/duct/component/endpoint.clj#L6

#PalmToFace

-d

On Tuesday, June 9, 2015 at 5:57:48 PM UTC-5, James Reeves wrote:
>
> On 9 June 2015 at 23:16, Dru Sellers > 
> wrote:
>
>> @James do you only have one component that has all of your routes? or do 
>> you have each component supply its own routes? If you imagine a component 
>> providing its own routes, I'd love to see a duct example with two routes 
>> set up.
>>
>> I believe that would be multiple endpoint components.
>>
>> Looking at 
>> https://github.com/weavejester/duct/blob/master/duct/src/duct/component/endpoint.clj#L7
>>  
>> I'm guessing that duct only expects one endpoint-component - is that 
>> correct?
>>
>
> No, you can have as many endpoint components as you want.
>
> Duct has a handler component that looks for endpoint components in its 
> dependencies, and combines their routes together using 
> compojure.core/routes.
>
> One of the ideas in Duct is to group routes together by purpose, to 
> achieve the modularity of micro-service architecture without the overhead.
>
> For example, let's say you have endpoints foo, bar and baz. Then your 
> system builder in Duct would look like:
>
> (defn new-system [config]
>   (let [config (meta-merge base-config config)]
> (-> (component/system-map
>  :http (jetty-server (:http config))
>  :app  (handler-component (:app config))
>  :foo  (endpoint-component foo-endpoint)
>  :bar  (endpoint-component bar-endpoint)
>  :baz  (endpoint-component baz-endpoint))
> (component/system-using
>  {:http [:app]
>   :app  [:foo :bar :baz]}
>
> - James
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Clojure : event listener on domina library

2015-06-10 Thread dimas . saputra
I hope someone can help me on this. 

I'm using domina  and clojurescript in my 
website project. My problem is i try to make 3 click event in 3 different 
button.

I attach the code snippet below, 

 (defn html1 [] (dom/set-inner-html! (dom/by-id "idofhtml") " lorem 
ipsum ")) (defn ^:export init [] (when (and js/document (.-getElementById 
js/document)) (ev/listen! (dom/by-id "link1") :click html1) (ev/listen! 
(dom/by-id "link2") :click html2) (ev/listen! (dom/by-id "link3") :click 
html3))) (set! (.-onload js/window) init)

Problem is only :


 (ev/listen! (dom/by-id "link1") :click html1)


working, the other two :


 (ev/listen! (dom/by-id "link2") :click html2)
 (ev/listen! (dom/by-id "link3") :click html3)


Doesn't work, Thank you in advance, appreciate any 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.