Re: One benefit of having a REPL

2009-11-29 Thread Danny Woods
On Nov 28, 1:20 pm, John Harrop jharrop...@gmail.com wrote:
 One benefit of having a REPL: it makes regular expressions usable. So easy
 to test and tweak your RE compared to the traditional compile/test/debug
 cycle! I never even bothered with the java.util.regex package before Clojure
 as it was too painful to use.


You just reminded me of a utility I wrote in Ruby some years ago to
interactively build regular expressions.  I hacked up a Clojure
version in the past hour or so, and pushed it up to github at
http://github.com/dannywoodz/regex-toolbox.

Unfortunately, I can't claim to have come up with the idea, but
implementing it was good fun. :-)

Feedback always welcome!

Cheers,
Danny.

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


reduce with-precision using BigDecimal

2009-11-29 Thread Gaz
Hi, apologies if this is a silly question. Im having some confusion
with the following code:

(with-precision 3 (/ 36.02M 4.00M))
9.01M

This is what i would expect. This however:

(with-precision 3 (/ (reduce + [15.00M 15.01M 3.00M 3.01M])
4.0M))
9M

Seems a bit odd? Or am I missing something obvious :(

Thanks for 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


Re: roll call of production use?

2009-11-29 Thread Joel Westerberg
I have written a production web app with compojure. It was a very nice
experience. First project I have pulled of totally TDD and the
functional aspect of clojure really makes tests so much easier and
more truthful, although there sometimes seems to sneak in some
exceptions I didn't expect from the java side.

It was a small ad campaign site with some SMS functionality, with web
pages formatted for mobile phones. Really nice to be able to just wrap
our java libs for sending SMS and device recognition. The compojure
HTML generator is fantastic, extremely powerful and easy to use. I am
amazed how compact the end code is.

I deployed a war file on tomcat 5.5. The app is stable and very fast.
One thing I would have liked to have was to start swank-server from
the war to provide an easy way to do hot updates and inspection, but I
ran into some problem with *1 etc not being defined so I gave up on
that. I prefer to deploy a war because I did not want to write my own
init.d script and bug test that.

Overall - a very nice experience.

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


Re: Deep deref

2009-11-29 Thread Rich Hickey
On Tue, Nov 24, 2009 at 3:14 AM, Christophe Grand christo...@cgrand.net wrote:
 On Mon, Nov 23, 2009 at 11:56 PM, John Harrop jharrop...@gmail.com wrote:

 I'm starting to think that for some tasks Clojure could use a concept of
 row locking with maps.  It would mean having a map-of-refs type that was
 integrated with the STM, so multiple updates whose keys didn't collide could
 occur concurrently.
 It *might* be possible to do this using commute and update-in, with a ref
 wrapping the whole map. The tricky thing is you want the update-ins to
 commute if the keys are not the same, but not if they are. Perhaps we need a
 conditional commute that takes two extra arguments, a value to test and a
 binary predicate. Then it could be done with (conditional-commute key = map
 update-in [key] val-transform-fn).
 The idea here being, in this case, that if two of these were done in
 overlapping transactions, the first arguments would be compared using the
 second argument. If the result was true one transaction would be retried, if
 false the operations would commute. (If the second arguments to the two
 conditional-commutes differed the transaction would be retried.)

 I had a similar idea but more general: being able to specify invariants
 inside a transaction. Commit will procede only if the invariant still holds.
 Your proposed conditional-commute could be rewritten:

 ;; (conditional-commute key = map update-in [key] val-transform-fn)
 (invariant (@map key))
 (commute map update-in [key] val-transform-fn)

 See the attached patch for a prototype.


I had forgotten about this, could you please make an issue for it? I'd
like to look into it for a future feature.

Thanks,

Rich

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


Re: reduce with-precision using BigDecimal

2009-11-29 Thread Gareth jones
Agh that makes sense, I thought I was going crazy but I guess it's  
obvious now you point it out... Thanks for the help :D

Gaz

Sent from my iPhone

On Nov 29, 2009, at 10:36 AM, Ahmed Fasih wuzzyv...@gmail.com wrote:

 Hi, without knowing much about what's going on, note that

 user= (reduce + [15.00M 15.01M 3.00M 3.01M])
 36.02M
 user= (with-precision 3 (reduce + [15.00M 15.01M 3.00M 3.01M]))
 36.0M

 So an intermediate step in the calculation is rounded down to 3
 decimals and that rounding error is carried through. So the 9M with
 3-precision would mean 9.00M.

 Amazing! It might be getting in your way here, but functions changing
 their operation because they were called via with-precision speaks
 to a flexibility that I've only seen in Lisps.

 On Nov 28, 10:27 pm, Gaz gareth.e.jo...@gmail.com wrote:
 Hi, apologies if this is a silly question. Im having some confusion
 with the following code:

 (with-precision 3 (/ 36.02M 4.00M))
 9.01M

 This is what i would expect. This however:

 (with-precision 3 (/ (reduce + [15.00M 15.01M 3.00M 3.01M])
 4.0M))
 9M

 Seems a bit odd? Or am I missing something obvious :(

 Thanks for 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 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


ANN: Web application framework (beta)

2009-11-29 Thread jim
I finally got time to find the bug in my web application framework.
Here is the code to the framework:

http://intensivesystems.net/tutorials/code/web_session.clj

And here is a very simple sample app:

http://intensivesystems.net/tutorials/code/web_app.clj

The top level app is defined like this:

(def web-app (web-while (constantly true)
(web-seq get-name
get-age
get-gender
(web-cond
 male? male-options
 :else female-options)
show-summary)))

Documentation is here:

http://intensivesystems.net/tutorials/web_sessions.html

This is beta code, so I'd be interested in any feedback. I'm starting
work on the tutorial that explains how the code works and also the
continuation monad. Trying to figure the code out just by reading the
source will be extremely difficult unless you already have a very good
understanding of the continuation monad, and even then the things I
had to do to make the browser back button work really clog up the
code.

Jim

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


Re: ANN: Web application framework (beta)

2009-11-29 Thread Jim Powers
On Sun, Nov 29, 2009 at 7:21 PM, jim jim.d...@gmail.com wrote:

 I finally got time to find the bug in my web application framework.
 Here is the code to the framework:

 http://intensivesystems.net/tutorials/code/web_session.clj


This does indeed look cool, but here's the problem I have with all of the
continuation-style web-frameworks: they do not scale.  This is to say in a
web-server farm setting you need a workable stickiness approach since you
always have to be routed back to the machine with the continuation you need.
 So:

   - In the case of machine or process failure all state information is
   lost.
   - It is pretty easy to wind up with a very unbalanced web farm as due to
   the randomness of user activity it is possible to have all of your active
   users load-balanced onto only a few machines.
   - If you force-ably load balance based on session count you can easily
   under-utilize your web farm.
   - Since one of the benefits of continuation-based web frameworks is the
   amount and richness of the data that can be transferred between pages, but
   this (potentially lots of data) coupled with the problems listed above, can
   become a serious problem under certain (potentially not-predictable)
   circumstances.

Clearly what would be desired is portable continuations that can be loaded
on any machine and/or duplicated/replicated for failure cases.

This said, the web_session code is cool, but any thoughts on addressing the
more general problems?

-- 
Jim Powers

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

Re: reduce with-precision using BigDecimal

2009-11-29 Thread Joseph Smith
What you want is to set the 'scale' of the BigDecimal.

There doesn't seem to be a nice clojure macro for it, but this works:
user= (.setScale (reduce + [15.00M 15.01M 3.00M 3.01M]) 3)
36.020M


---
Joseph Smith
j...@uwcreations.com
(402)601-5443





On Nov 29, 2009, at 2:02 PM, Gareth jones wrote:

 Agh that makes sense, I thought I was going crazy but I guess it's
 obvious now you point it out... Thanks for the help :D

 Gaz

 Sent from my iPhone

 On Nov 29, 2009, at 10:36 AM, Ahmed Fasih wuzzyv...@gmail.com wrote:

 Hi, without knowing much about what's going on, note that

 user= (reduce + [15.00M 15.01M 3.00M 3.01M])
 36.02M
 user= (with-precision 3 (reduce + [15.00M 15.01M 3.00M 3.01M]))
 36.0M

 So an intermediate step in the calculation is rounded down to 3
 decimals and that rounding error is carried through. So the 9M with
 3-precision would mean 9.00M.

 Amazing! It might be getting in your way here, but functions changing
 their operation because they were called via with-precision speaks
 to a flexibility that I've only seen in Lisps.

 On Nov 28, 10:27 pm, Gaz gareth.e.jo...@gmail.com wrote:
 Hi, apologies if this is a silly question. Im having some confusion
 with the following code:

 (with-precision 3 (/ 36.02M 4.00M))
 9.01M

 This is what i would expect. This however:

 (with-precision 3 (/ (reduce + [15.00M 15.01M 3.00M 3.01M])
 4.0M))
 9M

 Seems a bit odd? Or am I missing something obvious :(

 Thanks for 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 post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient  
 with your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

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


Re: ANN: Web application framework (beta)

2009-11-29 Thread jim
Not yet. :) You bring up some good points that I hadn't thought of
yet. The itch I was scratching was how to easily write a web
application for a limited number of users. I wanted to make that task
cheap enough to be something a single programmer could do very
quickly.

OTOH, your comments have sparked a few thoughts. I've got to get the
continuation monad tutorial written and then I may think about them.

Jim

Jim Powers wrote:
 On Sun, Nov 29, 2009 at 7:21 PM, jim jim.d...@gmail.com wrote:

  I finally got time to find the bug in my web application framework.
  Here is the code to the framework:
 
  http://intensivesystems.net/tutorials/code/web_session.clj


 This does indeed look cool, but here's the problem I have with all of the
 continuation-style web-frameworks: they do not scale.  This is to say in a
 web-server farm setting you need a workable stickiness approach since you
 always have to be routed back to the machine with the continuation you need.
  So:

- In the case of machine or process failure all state information is
lost.
- It is pretty easy to wind up with a very unbalanced web farm as due to
the randomness of user activity it is possible to have all of your active
users load-balanced onto only a few machines.
- If you force-ably load balance based on session count you can easily
under-utilize your web farm.
- Since one of the benefits of continuation-based web frameworks is the
amount and richness of the data that can be transferred between pages, 
 but
this (potentially lots of data) coupled with the problems listed above, can
become a serious problem under certain (potentially not-predictable)
circumstances.

 Clearly what would be desired is portable continuations that can be loaded
 on any machine and/or duplicated/replicated for failure cases.

 This said, the web_session code is cool, but any thoughts on addressing the
 more general problems?

 --
 Jim Powers

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


Re: ANN: Web application framework (beta)

2009-11-29 Thread David Brown
On Sun, Nov 29, 2009 at 11:09:38PM -0500, Jim Powers wrote:

Clearly what would be desired is portable continuations that can be loaded
on any machine and/or duplicated/replicated for failure cases.

All of the persistent classes in Clojure, including continuations
claim to implement Serializable.  Not sure how well it actually works,
but if implemented, it should be possible to send a closure even to a
different machine.

David

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