Clarity on Stuart Sierra's component system

2014-11-28 Thread Colin Yates
Hi all,

Am I right in thinking that in order to use 
https://github.com/stuartsierra/component every consumer of a component 
must also be a component?

For example, if I have a component DB and I want to use that DB in (defn 
blob-query [db criteria]...), do I pull the DB out of the system map and 
call it or am I expected to make a BlobQuery component which offers a 
(blob-query [criteria]) API?

Initially I thought the system was just the stateful components, but 
after watching https://www.youtube.com/watch?v=13cmHf_kt-Q and reading the 
doc, particularly the all or nothing warnings I think I might have missed 
something.

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 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.


ring-transit issue

2014-11-28 Thread Thomas
Hi,

I am using the ring-transit middleware but something doesn't seem to be 
quite right. Below is the code on the server side:

(defn get-test-data []
  {:a 1 :b 2})

(defroutes app-routes
  (GET / [] (main-page))
  (wrap-transit-response
(GET /test [] (get-test-data)))
  (route/resources /)
  (route/not-found Not Found))

(def app
  (- app-routes
  (handler/site)
  (wrap-transit-params)))

On the client I am getting this error when using cljs-ajax:

something bad happened: 200 Unexpected end of input  Format should have 
been Transit

and the content-length is reported as 0 by postman. I am sure the error is 
between my ears ;)  but I have no idea what!! Any ideas?

TIA,
Thomas

-- 
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] stateful-check 0.1.0 - test stateful systems with test.check

2014-11-28 Thread Jan Stępień
Hi Carlo,

Thanks for sharing! I see that generative testing of statful computations 
is a popular topic in the Clojure world these days; I think we've started 
working on our libraries nearly the same day :)

https://github.com/jstepien/states

All the best,
Jan

-- 
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: ring-transit issue

2014-11-28 Thread Ahmad Hammad
Remove wrap-transit-response from your routes. You need to add 
(wrap-transit-response) to your middleware just like you have 
(wrap-transit-params). The latter handles incoming request params, while 
the former response collections.

On Friday, November 28, 2014 2:00:20 PM UTC, Thomas wrote:

 Hi,

 I am using the ring-transit middleware but something doesn't seem to be 
 quite right. Below is the code on the server side:

 (defn get-test-data []
   {:a 1 :b 2})

 (defroutes app-routes
   (GET / [] (main-page))
   (wrap-transit-response
 (GET /test [] (get-test-data)))
   (route/resources /)
   (route/not-found Not Found))

 (def app
   (- app-routes
   (handler/site)
   (wrap-transit-params)))

 On the client I am getting this error when using cljs-ajax:

 something bad happened: 200 Unexpected end of input  Format should have 
 been Transit

 and the content-length is reported as 0 by postman. I am sure the error is 
 between my ears ;)  but I have no idea what!! Any ideas?

 TIA,
 Thomas


-- 
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] stateful-check 0.1.0 - test stateful systems with test.check

2014-11-28 Thread Carlo Zancanaro
Hey Jan!

On Fri, Nov 28, 2014 at 06:37:06AM -0800, Jan Stępień wrote:
 Thanks for sharing! I see that generative testing of statful computations 
 is a popular topic in the Clojure world these days;

Yeah, it certainly seems to be that way. I was re-invigorated to work on
stateful-check after watching a talk from the conj about generative
integration tests.

 I think we've started working on our libraries nearly the same day :)
 
 https://github.com/jstepien/states

I've actually seen your library since writing stateful-check. When I
experimented with it, though, I found its shrinking to be a bit lacking.
With stateful-check I've actually implemented my own shrinking of
commands to try to improve the shrinking results (it essentially tries
to prune irrelevant commands before trying to shrink individual
commands).

I was quite interested in your approach of using a single function per
specification property (precondition/postcondition/next-state). I
thought that would be a bit constricting when it comes to actually
writing test cases, though, so I've opted instead to have each of those
defined per-command. How have you found that to be in practice?

Thanks!

Carlo

-- 
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.


signature.asc
Description: Digital signature


Re: Clarity on Stuart Sierra's component system

2014-11-28 Thread Max Countryman
Hi Colin,

I'm by no means an expert on Component but I have used it for my last several 
projects. What I've discovered is where I have query functions such as yours I 
pass the db component through to their call sites from a component which 
contains the db as state. For example, I have a component which contains 
various HTTP routing logic. Some of my routes result in db queries. To 
facilitate this I pass the db all the way through. It's sometimes a little 
clunky and there may be better ways of doing this, e.g. maybe all the routes 
which depended on db state could be partitioned in their own component. 

I hope that's helpful,


Max

 On Nov 28, 2014, at 03:28, Colin Yates colin.ya...@gmail.com wrote:
 
 Hi all,
 
 Am I right in thinking that in order to use 
 https://github.com/stuartsierra/component every consumer of a component must 
 also be a component?
 
 For example, if I have a component DB and I want to use that DB in (defn 
 blob-query [db criteria]...), do I pull the DB out of the system map and call 
 it or am I expected to make a BlobQuery component which offers a (blob-query 
 [criteria]) API?
 
 Initially I thought the system was just the stateful components, but after 
 watching https://www.youtube.com/watch?v=13cmHf_kt-Q and reading the doc, 
 particularly the all or nothing warnings I think I might have missed 
 something.
 
 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 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: Clarity on Stuart Sierra's component system

2014-11-28 Thread James Reeves
On 28 November 2014 at 10:28, Colin Yates colin.ya...@gmail.com wrote:

 Am I right in thinking that in order to use
 https://github.com/stuartsierra/component every consumer of a component
 must also be a component?


Nope.


 For example, if I have a component DB and I want to use that DB in (defn
 blob-query [db criteria]...), do I pull the DB out of the system map and
 call it or am I expected to make a BlobQuery component which offers a
 (blob-query [criteria]) API?


You only need to make something a component if it has a lifecycle. If you
just want to use a database connection, pass the component as an argument
to a function.

Look at it another way: do you need to keep blob-query around? Does it have
state? If not, then it doesn't need to be a component.

- 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.


Re: Clarity on Stuart Sierra's component system

2014-11-28 Thread Colin Yates
Thanks both. James, that is what I was hoping.

I guess I got a bit misled with the combination of his Customers
example in the video, the all or nothing warnings and I do not
intend that application functions should receive the top-level system
as an argument. Rather, functions are defined in terms of components.
 (from the front page on github).

I guess we can just (:interesting-component system) once the system has started?

(Without writing a single line of code though, I can see the
temptation to make stateless consumers Components just for the ease of
use :)).

On 28 November 2014 at 15:00, James Reeves ja...@booleanknot.com wrote:
 On 28 November 2014 at 10:28, Colin Yates colin.ya...@gmail.com wrote:

 Am I right in thinking that in order to use
 https://github.com/stuartsierra/component every consumer of a component must
 also be a component?


 Nope.


 For example, if I have a component DB and I want to use that DB in (defn
 blob-query [db criteria]...), do I pull the DB out of the system map and
 call it or am I expected to make a BlobQuery component which offers a
 (blob-query [criteria]) API?


 You only need to make something a component if it has a lifecycle. If you
 just want to use a database connection, pass the component as an argument to
 a function.

 Look at it another way: do you need to keep blob-query around? Does it have
 state? If not, then it doesn't need to be a component.

 - 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 a topic in the
 Google Groups Clojure group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/clojure/WC983q33Nes/unsubscribe.
 To unsubscribe from this group and all its topics, 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: Clarity on Stuart Sierra's component system

2014-11-28 Thread James Reeves
On 28 November 2014 at 15:20, Colin Yates colin.ya...@gmail.com wrote:

 I guess I got a bit misled with the combination of his Customers
 example in the video, the all or nothing warnings and I do not
 intend that application functions should receive the top-level system
 as an argument. Rather, functions are defined in terms of components.
  (from the front page on github).

 I guess we can just (:interesting-component system) once the system has
 started?


Your system should call your functions, not the other way around.

You can have functions that are not components, but all functions should be
called from a component. The direction of the program should flow down from
the system to its components, then down into individual functions.

- 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.


Re: Clarity on Stuart Sierra's component system

2014-11-28 Thread Colin Yates
Ah OK. I was confused a little about what makes a component, it isn't
just state it is also about lifecycle.

Imagine a health-check which polls some service to see if it is
there, it needs the service and some ohDear notifier component but it
doesn't have any state as such (or at least no state that changes over
time), but it does have a notion of start/stopping. This would be a
good candidate because it has a lifecycle.

Thanks again.

On 28 November 2014 at 15:54, James Reeves ja...@booleanknot.com wrote:
 On 28 November 2014 at 15:20, Colin Yates colin.ya...@gmail.com wrote:

 I guess I got a bit misled with the combination of his Customers
 example in the video, the all or nothing warnings and I do not
 intend that application functions should receive the top-level system
 as an argument. Rather, functions are defined in terms of components.
  (from the front page on github).

 I guess we can just (:interesting-component system) once the system has
 started?


 Your system should call your functions, not the other way around.

 You can have functions that are not components, but all functions should be
 called from a component. The direction of the program should flow down from
 the system to its components, then down into individual functions.

 - 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 a topic in the
 Google Groups Clojure group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/clojure/WC983q33Nes/unsubscribe.
 To unsubscribe from this group and all its topics, 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.


reduced doesn't work inside reductions

2014-11-28 Thread myguidingstar
 

(reduce (fn [acc x]
  (if ( acc 10)
(reduced acc)
(+ acc x)))
0 
(range 100))
;; = 15
(reductions (fn [acc x]
  (if ( acc 10)
(reduced acc)
(+ acc x)))
0 
(range 100))
;; thows ClassCastException clojure.lang.Reduced cannot be cast to 
java.lang.Number  clojure.lang.Numbers.gt (Numbers.java:227)
Is it a bug or intended behavior?

-- 
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: reduced doesn't work inside reductions

2014-11-28 Thread Nicola Mometto

This has already been fixed, and reductions will support reduced in
1.7.0.
In the meantime you can use 1.7.0-alpha4.

Nicola

myguidingstar writes:



 (reduce (fn [acc x]
   (if ( acc 10)
 (reduced acc)
 (+ acc x)))
 0
 (range 100))
 ;; = 15
 (reductions (fn [acc x]
   (if ( acc 10)
 (reduced acc)
 (+ acc x)))
 0
 (range 100))
 ;; thows ClassCastException clojure.lang.Reduced cannot be cast to 
 java.lang.Number  clojure.lang.Numbers.gt (Numbers.java:227)
 Is it a bug or intended behavior?

--

-- 
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.


[ANN] defprecated 0.1.0 - deprecation made easy

2014-11-28 Thread Alexander Yakushev
Hello everyone,

I wrote this tiny library mostly because there was no automatic way to 
deprecate separate function arities in Clojure. And while I was at it, I 
added some commonly needed features too. So here's what *defprecated* is 
capable of:

   - adding deprecation notice to the docs
   - printing a warning when deprecated function/macro is used (customize 
   to print once or every time)
   - deprecating specific arities so `:forms` metadata is automatically 
   updated (and only deprecated arities fire a warning).
   
You can find information on how to use it here: 
https://github.com/alexander-yakushev/defprecated

Regards,

Alex Yakushev

-- 
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: Clarity on Stuart Sierra's component system

2014-11-28 Thread James Reeves
On 28 November 2014 at 16:02, Colin Yates colin.ya...@gmail.com wrote:

 Ah OK. I was confused a little about what makes a component, it isn't
 just state it is also about lifecycle.

 Imagine a health-check which polls some service to see if it is
 there, it needs the service and some ohDear notifier component but it
 doesn't have any state as such (or at least no state that changes over
 time), but it does have a notion of start/stopping. This would be a
 good candidate because it has a lifecycle.


Exactly right.

- 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.


Re: Core.async unordered pipeline-blocking ?

2014-11-28 Thread Francis Avila
I had a need for this too some time ago. It's not very hard to write 
yourself. Whatever trickiness there is in these functions is in handling 
exceptions and orchestrating shutdown.

I put my version up in a gist with some other async utility functions I 
wrote: https://gist.github.com/favila/8e7ad6ea5b01bd7466ff
You are looking for fast-pipeline-blocking.

On Thursday, November 27, 2014 3:32:43 PM UTC-6, Niels van Klaveren wrote:

 Recently in creating load testing I've been in need of throttling certain 
 mixed IO/CPU bound processes and have been using claypoole.core/upmap for 
 those situations

 (require '[com.climate.claypoole :as cp])

 (defn wait-and-return
   [w]
   (Thread/sleep (* 1000 w))
   w)

 (def to-sort
   [38 20 22 24 36 2 30 18 32 0 4 34 14 28 6 16 12 26 8 10])

 (def timesorted
   (time (doall (cp/upmap 20 wait-and-return to-sort

 timesorted
 Elapsed time: 38004.512729 msecs
 = (var clay.core/timesorted)
 = (0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38)


 This is just an example to show blocking processes returning in a 
 different order, while being restricted to a certain number of threads. I 
 know this won't work with a threadpool smaller than to-sort.

 Other parts of these tests would benefit from core.async techniques, but I 
 haven't found a satisfactory combination of the two. What I'm really 
 looking for is a way to use core.async pipeline-blocking syntax, which 
 takes a fixed number of parallel processes, a from channel, a transducer 
 and a to channel, but returns the results from the transducers unordered 
 (ie. fasted delivered first. Something like this, but with an ordered 
 outcome.

 (require '[clojure.core.async :as a])

 (def to-sort
   (a/to-chan [38 20 22 24 36 2 30 18 32 0 4 34 14 28 6 16 12 26 8 10]))

 (defn wait-and-return
   [w]
   (Thread/sleep (* 1000 w))
   w)

 (def sorted
   (a/chan))

 (def xwait
   (map wait-and-return))

 (def sorter
   (a/pipeline-blocking 20 sorted xwait to-sort))

 (time (a/!! (a/into [] sorted)))


 Is there a function like that, or would there be a recommended way to do 
 something like this in core.async ?

 Regards,

 Niels


-- 
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.


Bug? with-redefs fails on functions with primitive type hints

2014-11-28 Thread Brian Marick
A Midje user reports a bug that is actually a Clojure behavior. Does it 
count as a bug?


Consider the following:

(defn test-fn [^long x] x); Note hint
(defn do-something [x] (test-fn x))

(with-redefs [test-fn (fn [x] (prn :x x) x)]
  (do-something non-int))

In Clojures from 1.5 to 1.7-alpha3, this blows up. Here's the 1.7 exception:

Exception in thread main java.lang.ClassCastException:
scratch.t_core$eval8616$fn__8617 cannot be cast to
clojure.lang.IFn$LO, compiling:(scratch/t_core.clj:21:36)

Changing the ^long to a ^Long allows the redef to go through.

--
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: Bug? with-redefs fails on functions with primitive type hints

2014-11-28 Thread Sean Corfield
On Nov 28, 2014, at 12:59 PM, Brian Marick mar...@exampler.com wrote:
 A Midje user reports a bug that is actually a Clojure behavior. Does it count 
 as a bug?

If you're mocking a function that is specifically declared to take a long 
(primitive), shouldn't the mocked call also be declared to take a long?

(defn test-fn [^long x] x); Note hint
#'user/test-fn
(defn do-something [x] (test-fn x))
#'user/do-something
(with-redefs [test-fn (fn [^long x] (prn :x x) x)] ; Note hint here too!
  (do-something non-int))

And this fails (as expected):

ClassCastException java.lang.String cannot be cast to java.lang.Number  
user/do-something (form-init1785865955014487522.clj:1)

Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

Perfection is the enemy of the good.
-- Gustave Flaubert, French realist novelist (1821-1880)



-- 
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: Bug? with-redefs fails on functions with primitive type hints

2014-11-28 Thread Brian Marick



Sean Corfield wrote:

If you're mocking a function that is specifically declared to take a long 
(primitive), shouldn't the mocked call also be declared to take a long?


Midje has an idea called a metaconstant 
https://github.com/marick/Midje/wiki/Metaconstants. Metaconstants are used to document that nothing 
about a test value matters except what you explicitly mention (by declaring what values particular 
functions have when applied to the test value). It's useful at making tests more abstract, closer 
to for all statements.

So the actual (still example) code looked something like:

   (fact convert any integer into a map thing
 (function-under-test ..any-integer..) = {..any-integer [..any-integer..]}
 (provided
   (intlister ..any-integer..) = [..any-integer..]))


If this isn't a bug, I wouldn't expect Clojure to change. Once one chooses 
static types, one has many crosses to bear, and this would be another. But the 
way it works for non-primitives but not primitives could conceivably be a 
symptom of an important bug.

--
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: Core.async unordered pipeline-blocking ?

2014-11-28 Thread Niels van Klaveren
Thanks so much for sharing, Francis ! It might be simple to some, but I 
haven't had an opportunity yet to get acquainted well enough with 
core.async. Clojure has so much useful libraries, but some force you to get 
your head around (for me) completely new paradigms which can take time. 
Reading your code did provide me a with lot of new insights, as well as 
having a very useful tool I can use.

All time I can devote to learning Clojure have been in projects at work I 
have to do by myself, often needing to be put together on short notice. 
There's a snowball's chance in hell of collaboration with my colleagues 
from the firmly Java entrenched development department. I need to have a 
solid idea how I can get from start to finish in a very short time, for 
which Clojure has been quite awesome in some ways, but quite hard in 
others. The awesome community is often just the push in the back to get 
over these hurdles though.

Now I have all parts in hand I can start improving some more mature 
projects by introducing core.async into them. Wiring up existing pieces 
will get me more experience and confidence to dive deeper into async 
libraries. Thanks again for the last part of the puzzle, I'm pretty sure I 
will be able to finish putting it together now !

On Friday, November 28, 2014 6:10:05 PM UTC+1, Francis Avila wrote:

 I had a need for this too some time ago. It's not very hard to write 
 yourself. Whatever trickiness there is in these functions is in handling 
 exceptions and orchestrating shutdown.

 I put my version up in a gist with some other async utility functions I 
 wrote: https://gist.github.com/favila/8e7ad6ea5b01bd7466ff
 You are looking for fast-pipeline-blocking.

 On Thursday, November 27, 2014 3:32:43 PM UTC-6, Niels van Klaveren wrote:

 Recently in creating load testing I've been in need of throttling certain 
 mixed IO/CPU bound processes and have been using claypoole.core/upmap 
 for those situations

 (require '[com.climate.claypoole :as cp])

 (defn wait-and-return
   [w]
   (Thread/sleep (* 1000 w))
   w)

 (def to-sort
   [38 20 22 24 36 2 30 18 32 0 4 34 14 28 6 16 12 26 8 10])

 (def timesorted
   (time (doall (cp/upmap 20 wait-and-return to-sort

 timesorted
 Elapsed time: 38004.512729 msecs
 = (var clay.core/timesorted)
 = (0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38)


 This is just an example to show blocking processes returning in a 
 different order, while being restricted to a certain number of threads. I 
 know this won't work with a threadpool smaller than to-sort.

 Other parts of these tests would benefit from core.async techniques, but 
 I haven't found a satisfactory combination of the two. What I'm really 
 looking for is a way to use core.async pipeline-blocking syntax, which 
 takes a fixed number of parallel processes, a from channel, a transducer 
 and a to channel, but returns the results from the transducers unordered 
 (ie. fasted delivered first. Something like this, but with an ordered 
 outcome.

 (require '[clojure.core.async :as a])

 (def to-sort
   (a/to-chan [38 20 22 24 36 2 30 18 32 0 4 34 14 28 6 16 12 26 8 10]))

 (defn wait-and-return
   [w]
   (Thread/sleep (* 1000 w))
   w)

 (def sorted
   (a/chan))

 (def xwait
   (map wait-and-return))

 (def sorter
   (a/pipeline-blocking 20 sorted xwait to-sort))

 (time (a/!! (a/into [] sorted)))


 Is there a function like that, or would there be a recommended way to do 
 something like this in core.async ?

 Regards,

 Niels



-- 
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.


[ANN] Clara Rules 0.7.0 Released

2014-11-28 Thread Ryan Brush
I just pushed release 0.7.0 of Clara, a forward-chaining production rule 
engine in Clojure.  Beyond some bug fixes and performance improvements, the 
most significant new feature is described at [1]: support for any variable 
bound in a constraint is visible to arbitrary expressions in subsequent 
constraints. 

I also have created a separate Google group for Clara at [2]. Clara is now 
being used significantly at my day job and there have been enough external 
questions that a separate space makes sense.

The rate of significant changes to Clara's core is slowing down, but from 
my obviously biased perspective I think that's because Clara is maturing 
into a good alternative to other JVM-based production rule engines. I 
suspect most members of this group would rather write Clojure than in a DSL 
specific to some rule engine...which is what Clara aims to do. 

Best,
Ryan

[1]
*https://github.com/rbrush/clara-rules/issues/66*
[2]
*https://groups.google.com/forum/#!forum/clara-rules* 

-- 
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: reduced doesn't work inside reductions

2014-11-28 Thread Brandon Bloom
For reference, here's the 
ticket: http://dev.clojure.org/jira/browse/CLJ-1185

And the 
commit: 
https://github.com/clojure/clojure/commit/b45b067f56c78b8128f57913e662d9638ee480c5

On Friday, November 28, 2014 11:19:41 AM UTC-5, Nicola Mometto wrote:


 This has already been fixed, and reductions will support reduced in 
 1.7.0. 
 In the meantime you can use 1.7.0-alpha4. 

 Nicola 

 myguidingstar writes: 

  
  
  (reduce (fn [acc x] 
(if ( acc 10) 
  (reduced acc) 
  (+ acc x))) 
  0 
  (range 100)) 
  ;; = 15 
  (reductions (fn [acc x] 
(if ( acc 10) 
  (reduced acc) 
  (+ acc x))) 
  0 
  (range 100)) 
  ;; thows ClassCastException clojure.lang.Reduced cannot be cast to 
 java.lang.Number  clojure.lang.Numbers.gt (Numbers.java:227) 
  Is it a bug or intended behavior? 

 -- 


-- 
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.