Re: Advice for building backend REST services from scratch using clojure

2014-10-07 Thread jongwon.choi
With Lispy languages, you can do whatever you want without worrying too 
much about underlying web server, db, etc.

I use my own constructors like:


(define-crud-handler :employee [:path [customers cust-id sites site-id 
employees] :auth-required? true]
  {:collection {:create (employees-create cust-id site-id)
 :read (employees-collection-read cust-id site-id
   :req-params 
[number draw] [number start] [number length]

order search)
 :partial-update (update-employees-collection-pref [number cust-id] [number 
site-id]
  
 :req-params [keyword payment-schedule] next-pay-date)
 :delete employees-collection-delete
 }
   :element {:read (employees-element-read cust-id site-id employee-id)
 :update (employees-element-modify cust-id site-id employee-id)
 :delete employees-element-delete
 }})

...

(define-crud-fn employees-element-modify [cust-id site-id employee-id]
  (dl/update-item :employee
  {:site-id site-id :id employee-id}
  (into {} (map (fn [[k v]] [k [:put v]]) 
(get-json-parameters)))
  :return :updated-new))


In this way, I can maintain proper abstraction layers and free to change 
underlying web server or db.

On Friday, 11 April 2014 00:13:19 UTC+10, Kashyap CK wrote:

 Hi,
 I have the opportunity to build a set of services from scratch. I plan to 
 use clojure for this.
 I'd like to experiment with options available out there - options such as 
 - what webserver, what database etc. I'd like it very much if you could 
 share some of your experiences in this and possibly some pitfalls to avoid.
 Regards,
 Kashyap


-- 
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: Advice for building backend REST services from scratch using clojure

2014-10-07 Thread jongwon.choi
With Lispy languages, you can do whatever you want without worrying too 
much about underlying web server, db, etc.

I use my own constructors like:


(define-crud-handler :employee [:path [customers cust-id sites site-id 
employees] :auth-required? true]
  {:collection {:create (employees-create cust-id site-id)
 :read (employees-collection-read cust-id site-id
   :req-params 
[number draw] [number start] [number length]

order search)
 :partial-update (update-employees-collection-pref [number cust-id] [number 
site-id]
  
 :req-params [keyword payment-schedule] next-pay-date)
 :delete (employees-collection-delete cust-id site-id)
 }
   :element {:read (employees-element-read cust-id site-id employee-id)
 :update (employees-element-modify cust-id site-id employee-id)
 :delete (employees-element-delete cust-id site-id employee-id)
 }})

...

(define-crud-fn employees-element-modify [cust-id site-id employee-id]
  (dl/update-item :employee
  {:site-id site-id :id employee-id}
  (into {} (map (fn [[k v]] [k [:put v]]) 
(get-json-parameters)))
  :return :updated-new))


In this way, I can maintain proper abstraction layers and free to change 
underlying web server or db.


-- 
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] Silk, an isomorphic routing library for Clojure and ClojureScript

2014-10-07 Thread Olli Piepponen
Has anyone here had a chance to use Silk for a project they'd be willing to 
share? I'm a front-end web-dev newbie who has been researching server-side 
Om/React rendering, and it seems like Silk is ideal for this use case. However 
I'd be much more comfortable starting out if there were some examples to go by.

On Tuesday, August 5, 2014 10:04:07 AM UTC+7, Dom Kiva-Meyer wrote:
 I have recently been experimenting with isomorphic Clojure and ClojureScript 
 architecture. The goal is to make Clojure[Script] web applications that can 
 share logic for routing, rendering, and other functionality in order to be 
 able run in both server-side and browser-side environments.
 
 
 
 
 I couldn't find a suitable routing library that worked in both Clojure and 
 ClojureScript nor could I find a routing library with a design that was 
 suitable for porting to the other platform, so I wrote one.
 
 
 
 https://github.com/DomKM/silk
 
 
 
 
 
 The core functionality of Silk is entirely compatible with both Clojure and 
 ClojureScript.
 
 
 Silk is easily extensible, which is especially important for an isomorphic 
 library. For example, you may have routes that, on the server, should only 
 match GET requests, but which should also work in the browser where you are 
 not routing from an HTTP request. This functionality is trivial to add to 
 Silk (and, as a convenience, is built in).
 
 
 
 
 
 In Silk, route matching and handling are decoupled. While this is an 
 important architecture concern anywhere, it is an essential feature for 
 isomorphism. Matching URLs on the server and browser will be very similar, 
 but what you do after will likely be entirely different. You can think of 
 routing in Silk as bidirectional (yes, routes are named) pure functions that 
 match URLs to extract parameters or take parameters to form URLs.
 
 
 
 
 
 
 
 If this sounds like it could be useful for you, please give it a try and let 
 me know what you think.
 
 
 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.


com.stuartsierra/component ring/compojure example

2014-10-07 Thread JPatrick Davenport
Hello,
I'm trying to create a web app. I'm having the damnest time trying to 
figure out how to layer my application. I want to pass protocol 
implementations to the routes. The protocols define interacting with 
various data sources that I need down the way. 

I saw Stuart Sierra's talk about Component. It looks to satisfy my needs. 
What I can't find is an example project for component and compojure. 
Unfortunately the project com.stuartsierra/component is poorly named. 
Googling for component + compojure brings back mostly false positives.

Does anyone have a gist or blog post about how to do this?

Thanks,
JPD

-- 
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: com.stuartsierra/component ring/compojure example

2014-10-07 Thread gaz jones
Here is a toy app that downloads nzbs from usenet:

https://github.com/gar3thjon3s/leacher

It's not documented, but it works. The component stuff is hooked up here:

https://github.com/gar3thjon3s/leacher/blob/master/src/clj/leacher/main.clj#L53



On 7 October 2014 12:33, JPatrick Davenport virmu...@gmail.com wrote:

 Hello,
 I'm trying to create a web app. I'm having the damnest time trying to
 figure out how to layer my application. I want to pass protocol
 implementations to the routes. The protocols define interacting with
 various data sources that I need down the way.

 I saw Stuart Sierra's talk about Component. It looks to satisfy my needs.
 What I can't find is an example project for component and compojure.
 Unfortunately the project com.stuartsierra/component is poorly named.
 Googling for component + compojure brings back mostly false positives.

 Does anyone have a gist or blog post about how to do this?

 Thanks,
 JPD

 --
 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: com.stuartsierra/component ring/compojure example

2014-10-07 Thread Daniel Szmulewicz
You may want to look here for integrating components in your app. 

https://github.com/danielsz/system/


On Tuesday, October 7, 2014 2:33:33 PM UTC+3, JPatrick Davenport wrote:

 Hello,
 I'm trying to create a web app. I'm having the damnest time trying to 
 figure out how to layer my application. I want to pass protocol 
 implementations to the routes. The protocols define interacting with 
 various data sources that I need down the way. 

 I saw Stuart Sierra's talk about Component. It looks to satisfy my needs. 
 What I can't find is an example project for component and compojure. 
 Unfortunately the project com.stuartsierra/component is poorly named. 
 Googling for component + compojure brings back mostly false positives.

 Does anyone have a gist or blog post about how to do this?

 Thanks,
 JPD


-- 
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: Advice for building backend REST services from scratch using clojure

2014-10-07 Thread gvim

On 11/04/2014 09:17, Colin Yates wrote:

  * you can fight it as hard as you like but you will eventually end up
using emacs, clojure-mode, cider, paredit and magit and then wonder
how you ever lived without it, but not without spending at least a
month or two cursing anything to do with emacs :).



Whilst I love Emacs, clojure-mode  cider for working with Clojure I 
wasted far too much time trying to get a Clojurescript browser repl 
working with cider. Tried Weasel but it didn't seem to be keeping up 
with Clojurescript releases or else it was some other mysterious bug. 
Austin seemed to require far too much boilerplate addition to get 
anything working so I eventually resorted to Lighttable which has smooth 
interaction with a browser repl in Chrome.


Until the whole lein/cider/Clojurescript/browser repl toolchain settles 
into something stable I would caution anyone trumpeting the advantages 
of Emacs. For Clojurescript the current state of play seems to favour 
Lighttable and Cursive.


gvim

--
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: Advice for building backend REST services from scratch using clojure

2014-10-07 Thread gvim

On 11/04/2014 09:17, Colin Yates wrote:

  * you can fight it as hard as you like but you will eventually end up
using emacs, clojure-mode, cider, paredit and magit and then wonder
how you ever lived without it, but not without spending at least a
month or two cursing anything to do with emacs :).



To supplement my last post, I would add that the main factor against 
Lighttable, for me, is its insane memory consumption. I don't know 
whether or not it was due to leaving it on overnight but I found it 
consuming 1.4GB RAM when I returned to editing the other day. To some 
accustomed to working with Java/JVM languages this may not be such a big 
deal but to me it matters as I work on my laptop much of the time.


gvim

--
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: Advice for building backend REST services from scratch using clojure

2014-10-07 Thread Colin Fleming
To be fair, Cursive doesn't yet provide a great CLJS REPL solution either,
although that is coming soon. Right now, for ease of getting a CLJS REPL up
and running Light Table definitely wins.

On 8 October 2014 05:20, gvim gvi...@gmail.com wrote:

 On 11/04/2014 09:17, Colin Yates wrote:

   * you can fight it as hard as you like but you will eventually end up
 using emacs, clojure-mode, cider, paredit and magit and then wonder
 how you ever lived without it, but not without spending at least a
 month or two cursing anything to do with emacs :).


 Whilst I love Emacs, clojure-mode  cider for working with Clojure I
 wasted far too much time trying to get a Clojurescript browser repl working
 with cider. Tried Weasel but it didn't seem to be keeping up with
 Clojurescript releases or else it was some other mysterious bug. Austin
 seemed to require far too much boilerplate addition to get anything working
 so I eventually resorted to Lighttable which has smooth interaction with a
 browser repl in Chrome.

 Until the whole lein/cider/Clojurescript/browser repl toolchain settles
 into something stable I would caution anyone trumpeting the advantages of
 Emacs. For Clojurescript the current state of play seems to favour
 Lighttable and Cursive.

 gvim


 --
 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: [ANN] async-sockets - work with sockets using core.async channels

2014-10-07 Thread Brian Guthrie
On Sun, Oct 5, 2014 at 11:57 PM, Zach Tellman ztell...@gmail.com wrote:

 If I'm reading this correctly, you're using non-blocking thread pools for
 blocking operations on the sockets.  Given more than N connections (last
 time I looked the thread pool's size was 42), you risk deadlock or at the
 very least poor average throughput.


I'd thought the thread pool's size was a function of your core count plus
some constant, which I believe is 42. But yes, that is a constraint, and
deadlock is a risk with too many concurrent connections. I haven't tried to
measure throughput yet but that seems like a reasonable next step. Thanks
for the code review!

-- 
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] async-sockets - work with sockets using core.async channels

2014-10-07 Thread Brian Guthrie
On Mon, Oct 6, 2014 at 12:10 AM, adrian.med...@mail.yu.edu wrote:

 Zach makes an excellent point; I've used AsyncSocketChannels and its irk (
 http://docs.oracle.com/javase/8/docs/api/java/nio/channels/AsynchronousServerSocketChannel.html),
 with core.async in the past. Perhaps replacing your direct java.net.Sockets
 with nio classes that can be given CompletionHandlers (
 http://docs.oracle.com/javase/7/docs/api/java/nio/channels/CompletionHandler.html)
 would be a better fit.


Once I do some performance instrumentation I'll give that a shot. I admit
that I'm not familiar with all the implications of using the nio classes;
were I to switch, is it safe to continue using go blocks, or is it worth
explicitly allocating a single thread per socket?

Brian

-- 
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] Silk, an isomorphic routing library for Clojure and ClojureScript

2014-10-07 Thread Dylan Butman
Sorry i don't have time to really explain any of this...

but here's some code I pulled out of a recent project. maybe it'll be helpful 
to you. unfortunately I can't share the whole project.

https://gist.github.com/pleasetrythisathome/7adbdc9c8b7ab689df45

-- 
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] Clojure instaREPL for web

2014-10-07 Thread Lauri Hartikka
A web based clojure instaREPL,

Check it out :)

http://clojurerepl.com


-- 
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] async-sockets - work with sockets using core.async channels

2014-10-07 Thread adrian . medina
It's not about 'safety' (depending on what that means in this context), but 
as Zach pointed out, if you aren't careful about backpressure you can run 
into performance bottlenecks with unrestrained async IO operations because 
although they let you code as if you could handle an unlimited amount of 
connections, obviously that isn't true. There is only a finite amount of 
data that can be buffered in and out of any network according to its 
hardware. When you don't regulate that, your system will end up spending an 
inordinate amount of time compensating for this. You don't need to worry 
about this with regular io because the thread per connection 
abstraction effectively bounds your activity within the acceptable physical 
constraints of the server. 

On Tuesday, October 7, 2014 2:49:30 PM UTC-4, Brian Guthrie wrote:


 On Mon, Oct 6, 2014 at 12:10 AM, adrian...@mail.yu.edu javascript: 
 wrote:

 Zach makes an excellent point; I've used AsyncSocketChannels and its irk (
 http://docs.oracle.com/javase/8/docs/api/java/nio/channels/AsynchronousServerSocketChannel.html),
  
 with core.async in the past. Perhaps replacing your direct java.net.Sockets 
 with nio classes that can be given CompletionHandlers (
 http://docs.oracle.com/javase/7/docs/api/java/nio/channels/CompletionHandler.html)
  
 would be a better fit. 


 Once I do some performance instrumentation I'll give that a shot. I admit 
 that I'm not familiar with all the implications of using the nio classes; 
 were I to switch, is it safe to continue using go blocks, or is it worth 
 explicitly allocating a single thread per socket?

 Brian


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


Evaluation order

2014-10-07 Thread Johannes Langøy
Hi, I can't figure this out.  I have these two functions:

(defn get-number []
  (try (let [input (read-string (read-line))]
 (if (number? input)
   input
   (get-number)))
   (catch Exception e (get-number

(defn selection-handler [tests]
  (dotimes [i (count tests)]
(printf (%s) %s: %s\n
(inc i)
(first (nth tests i))
(or (second (nth tests i))
--)))
  (loop [input (dec (get-number))]
(if ((set (range (count tests))) input)
  (nth tests input)
  (recur (dec (get-number))

Now, the problem is that when I run selection-handler, the dotimes output 
isn't printed until (get-number) has returned. Why is this?

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


What is the reasoning behind the Transducers eduction function?

2014-10-07 Thread Jason Gilman
There's a few new functions that have been added with Transducers which 
mostly have very clear use cases to me. What are the use cases for the new 
eduction 
http://clojure.github.io/clojure/branch-master/clojure.core-api.html#clojure.core/eduction
 function? 
(which looks like it was previously called iteration). The example at 
http://clojure.org/transducers is informative. It looks similar to sequence 
in that it produces something that is seq-able with the major difference 
being that the transform is applied each time the sequence is traversed.

You can see the difference here in this code (This uses iteration instead 
of eduction because I was on 1.7.0-alpha2)

(def to-str-iteration 
  (iteration (map (fn [i]
(println iteration i)
(str i)))
 (range 3)))

(def to-str-seq 
  (sequence (map (fn [i]
   (println sequence i)
   (str i)))
(range 3)))

(println First iteration)
(dorun to-str-iteration)
(println Second iteration)
(dorun to-str-iteration)
(println First sequence)
(dorun to-str-seq)
(println Second sequence)
(dorun to-str-seq)

Printed:
First iteration
iteration 0
iteration 0
iteration 1
iteration 2
Second iteration
iteration 0
iteration 0
iteration 1
iteration 2
First sequence
sequence 0
sequence 1
sequence 2
Second sequence

Should we use eduction when we need side effects or reading the current 
state during a transform and sequence when the transform is pure? Or is 
there a subtler difference between the two that I'm missing?

-- 
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: Evaluation order

2014-10-07 Thread adrian . medina
*output

On Tuesday, October 7, 2014 8:17:34 PM UTC-4, adrian...@mail.yu.edu wrote:

 You need to flush the input stream after printing. Call 
 (clojure.core/flush) to do so.

 On Tuesday, October 7, 2014 4:51:05 PM UTC-4, Johannes Langøy wrote:

 Hi, I can't figure this out.  I have these two functions:

 (defn get-number []
   (try (let [input (read-string (read-line))]
  (if (number? input)
input
(get-number)))
(catch Exception e (get-number

 (defn selection-handler [tests]
   (dotimes [i (count tests)]
 (printf (%s) %s: %s\n
 (inc i)
 (first (nth tests i))
 (or (second (nth tests i))
 --)))
   (loop [input (dec (get-number))]
 (if ((set (range (count tests))) input)
   (nth tests input)
   (recur (dec (get-number))

 Now, the problem is that when I run selection-handler, the dotimes output 
 isn't printed until (get-number) has returned. Why is this?



-- 
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: Evaluation order

2014-10-07 Thread adrian . medina
You need to flush the input stream after printing. Call 
(clojure.core/flush) to do so.

On Tuesday, October 7, 2014 4:51:05 PM UTC-4, Johannes Langøy wrote:

 Hi, I can't figure this out.  I have these two functions:

 (defn get-number []
   (try (let [input (read-string (read-line))]
  (if (number? input)
input
(get-number)))
(catch Exception e (get-number

 (defn selection-handler [tests]
   (dotimes [i (count tests)]
 (printf (%s) %s: %s\n
 (inc i)
 (first (nth tests i))
 (or (second (nth tests i))
 --)))
   (loop [input (dec (get-number))]
 (if ((set (range (count tests))) input)
   (nth tests input)
   (recur (dec (get-number))

 Now, the problem is that when I run selection-handler, the dotimes output 
 isn't printed until (get-number) has returned. Why is this?


-- 
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] async-sockets - work with sockets using core.async channels

2014-10-07 Thread Sun Ning

BTW, is there any network based core.async channel available now?

On 10/08/2014 04:36 AM, adrian.med...@mail.yu.edu wrote:
It's not about 'safety' (depending on what that means in this 
context), but as Zach pointed out, if you aren't careful about 
backpressure you can run into performance bottlenecks with 
unrestrained async IO operations because although they let you code as 
if you could handle an unlimited amount of connections, obviously that 
isn't true. There is only a finite amount of data that can be buffered 
in and out of any network according to its hardware. When you don't 
regulate that, your system will end up spending an inordinate amount 
of time compensating for this. You don't need to worry about this with 
regular io because the thread per connection abstraction 
effectively bounds your activity within the acceptable physical 
constraints of the server.


On Tuesday, October 7, 2014 2:49:30 PM UTC-4, Brian Guthrie wrote:


On Mon, Oct 6, 2014 at 12:10 AM, adrian...@mail.yu.edu
javascript: wrote:

Zach makes an excellent point; I've used AsyncSocketChannels
and its irk

(http://docs.oracle.com/javase/8/docs/api/java/nio/channels/AsynchronousServerSocketChannel.html

http://docs.oracle.com/javase/8/docs/api/java/nio/channels/AsynchronousServerSocketChannel.html),
with core.async in the past. Perhaps replacing your direct
java.net.Sockets with nio classes that can be given
CompletionHandlers

(http://docs.oracle.com/javase/7/docs/api/java/nio/channels/CompletionHandler.html

http://docs.oracle.com/javase/7/docs/api/java/nio/channels/CompletionHandler.html)
would be a better fit.


Once I do some performance instrumentation I'll give that a shot.
I admit that I'm not familiar with all the implications of using
the nio classes; were I to switch, is it safe to continue using go
blocks, or is it worth explicitly allocating a single thread per
socket?

Brian

--
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 
mailto: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: What is the reasoning behind the Transducers eduction function?

2014-10-07 Thread Laurent PETIT
Hello,

eduction does not return a seq, or anything already concrete like that,
rather it returns a new reducible, with the interesting property lying in
the retention of the xform argument (a transducer).

This allows you, for instance, to pass around a collection with all the
processing steps but the final rendering of the result (a seq? an aggregate
result? a vector ? nil?) = it's up to the user of the educible.

Since the educible is an unreduced form of the initial collection, then
every time it will be realized into a concrete value, the hidden (behind
the xform) collection will be traversed, and the transducer-returned
reducing function called.

Le mercredi 8 octobre 2014, Jason Gilman jason.gil...@gmail.com a écrit :

 There's a few new functions that have been added with Transducers which
 mostly have very clear use cases to me. What are the use cases for the new
 eduction
 http://clojure.github.io/clojure/branch-master/clojure.core-api.html#clojure.core/eduction
  function?
 (which looks like it was previously called iteration). The example at
 http://clojure.org/transducers is informative. It looks similar to
 sequence in that it produces something that is seq-able with the major
 difference being that the transform is applied each time the sequence is
 traversed.

 You can see the difference here in this code (This uses iteration instead
 of eduction because I was on 1.7.0-alpha2)

 (def to-str-iteration
   (iteration (map (fn [i]
 (println iteration i)
 (str i)))
  (range 3)))

 (def to-str-seq
   (sequence (map (fn [i]
(println sequence i)
(str i)))
 (range 3)))

 (println First iteration)
 (dorun to-str-iteration)
 (println Second iteration)
 (dorun to-str-iteration)
 (println First sequence)
 (dorun to-str-seq)
 (println Second sequence)
 (dorun to-str-seq)

 Printed:
 First iteration
 iteration 0
 iteration 0
 iteration 1
 iteration 2
 Second iteration
 iteration 0
 iteration 0
 iteration 1
 iteration 2
 First sequence
 sequence 0
 sequence 1
 sequence 2
 Second sequence

 Should we use eduction when we need side effects or reading the current
 state during a transform and sequence when the transform is pure? Or is
 there a subtler difference between the two that I'm missing?

 --
 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
 javascript:_e(%7B%7D,'cvml','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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com');.
 For more options, visit https://groups.google.com/d/optout.



-- 
Laurent Petit

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