Re: A question regarding map destructuring

2010-11-02 Thread Mike Meyer
On Mon, 1 Nov 2010 23:41:47 -0700 (PDT)
Meikel Brandmeyer  wrote:

> Hi,
> 
> On 2 Nov., 03:25, Mike K  wrote:
> 
> > (print-value-a [:b 7 :a 3])
> > ; actually prints nil
> 
> You have to use apply. (apply print-value-a [:b 7 :a 3]).
> 
> Furthermore: how could (let [{a :a} [:b 7 :a 3]] [a]) possibly work?

The same way this one works:

> (defn foo [& {:keys [a b]}] ...)
> 
> is equivalent to
> 
> (defn foo [& options#] (let [{:keys [a b]} (apply hash-map
> options#)] ...))

This only happens if the rest argument destructuring is a hash map -
if I use a vector or a symbol there, then the values don't get turned
into a map. Can't that same mechanism be used in the case where some
non-rest argument is a hash-map trying to destructure a sequence?
So that:

(let [{a :a} [:b 7 :a 3]] ...)

would be equivalent to

(let [x# [:b 7 :a 3]] (let [{a :a} (apply hash-map x#)] ...)

> user=> (let [{a :a} [:b 7 :a 3]] [a])
> [nil]
> user=> (let [{a 2} [:b 7 :a 3]] [a])
> [:a]
> 
> The map destructuring in the defn is a special case of defn, not
> destructuring itself.

Interesting. This means you can't use your second example to
destructure a rest argument:

user=> ((fn [& {a 2}] [a]) :b 7 :a 3)
[nil]

But that's the same behavior as you got with 1.1. But this case:

user=> ((fn [& {a 2}] [a]) 1 7 2 3)
[3] ;; 1.2 behavior; 1.1 returns [nil]

Changed between 1.1 and 1.2.

As much as I hate special cases when they aren't needed, I'm not
arguing that this should change. Handling rest arguments that way is
very useful. It's not at all clear there's a use for doing this
anywhere case, other than to scratch that consistency itch.

 http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
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: defmethod hangs

2010-11-02 Thread Jarl Haggerty
Thanks for look, I figured it was unlikely anyone could give me a
solution, but it was late at night, clojure wasn't telling me
anything, and I was kind of burnt out.  I've been experimenting and
trying to replicate the problem in a smaller program but all I've
learned is that if I move the function now in my let to a defn(adding
some new arguments since it's left the closure), it's the new function
definition where my program freezes, and if I comment out the recur
calls, my program compiles.

On Nov 1, 12:21 am, Meikel Brandmeyer  wrote:
> Hi,
>
> your code is really hard to understand. Please let let to be your
> friend! I extracted things a little bit and put everything in a let.
> Since I have no clue about collission detection in physics engines I
> derived the local names from the operations done "i"nc, "d"ec, etc.
> More meaningful names conveying domain information are left to the
> astute reader as an excercise. ;-)
>
> You probably can replace defstruct with defrecord. defrecord will
> supersede defstruct eventually.
>
> > (defstruct projection-struct :start :stop :start-points :stop-points)
> > (println 1)
>
> Here you can use the type function. Also note: your method won't work.
> Your dispatch function should match your methods in arity. It may take
> more if they are "don't cares" for the dispatch.
>
> > (defmulti projection (fn [shape & _] (type shape)))
> > (println 2)
>
> As I said, some cleanup with let (hopefully without messing things
> up). Also you cannot "call" integers with vectors. You have to use
> nth.
>
>
>
> > (defmethod projection :polygon
> >   [shape plane]
> >   (let [points  (:points shape)
> >         npoints (int (count points))
> >         dotp    #(->> % (nth points) (dot plane))
> >         search  (fn [condition]
> >                   (loop [accum (int 0)
> >                          step  npoints
> >                          from  (int -1)]
> >                     (let [step        (inc (/ step (int 2)))
> >                           iaccum      (+ accum step)
> >                           daccum      (- accum step)
> >                           naccum      (mod iaccum npoints)
> >                           paccum      (mod daccum npoints)
> >                           dotp-accum  (dotp accum)
> >                           dotp-naccum (dotp naccum)
> >                           dotp-paccum (dotp paccum)
> >                           apoints     (nth points accum)
> >                           fpoints     (nth points from)]
> >                       (condp condition dotp-accum
> >                         dotp-naccum (if (= from iaccum)
> >                                       [dotp-naccum [fpoints apoints]]
> >                                       (recur naccum step accum))
> >                         dotp-paccum (if (= from daccum)
> >                                       [dotp-paccum [fpoints apoints]]
> >                                       (recur paccum step accum))
> >                         [dotp-accum [apoints]]
> >         [start start-points] (search <=)
> >         [end   end-points]   (search >=)]
> >     (struct projection-struct start end start-points end-points)))
> > (println 3)
>
> On 1 Nov., 01:10, Jarl Haggerty  wrote:
>
> > I've also redefined the math functions to work with vectors and
> > matrices.
>
> Hmm.. I would suggest to stay away from such experiments until you
> have a better understanding on Clojure.
>
> That all said: I don't have a problem for your real problem. I don't
> see an obvious reason why the defmethod should hang. I would expect
> some quirk in your environment from outside this code snippet.
>
> Sincerely
> Meikel

-- 
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: A question regarding map destructuring

2010-11-02 Thread Meikel Brandmeyer
Hi,

On 2 Nov., 08:14, Mike Meyer  wrote:

> This only happens if the rest argument destructuring is a hash map -
> if I use a vector or a symbol there, then the values don't get turned
> into a map. Can't that same mechanism be used in the case where some
> non-rest argument is a hash-map trying to destructure a sequence?

And in fact this happens. :) It was just me who was wrong. The only
thing one has to remember: a vector is not a seq.

Sincerely
Meikel

-- 
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: defmethod hangs

2010-11-02 Thread Jarl Haggerty
I don't know if it's of any worth but I switched from 1.3.0-alpha2-
SNAPSHOT to 1.2 and my problems are gone.  The simplest way I found to
reproduce the error I was having in 1.3 was to paste this following
function into a repl.  The function is meaningless but I figure it
should at least compile.

(defn search [condition shape plane]
  (let [mod-nth (fn [coll x] (nth coll (mod x (count coll
ceil (fn [x] (inc (int x)))]
(loop [accum 0 step (ceil (/ (count (:points shape)) 2)) from -1]
  (condp condition (vector plane (mod-nth (:points shape) accum))

(vector plane (mod-nth (:points shape) (+ accum step)))
(if (= from (+ accum step))
  [(vector plane (mod-nth (:points shape) (+ accum step)))
   (mod-nth (:points shape) from) (mod-nth (:points shape)
accum)]
  (recur (+ accum step) (ceil (/ step 2)) accum))

(vector plane (mod-nth (:points shape) (- accum step)))
(if (= from (- accum step))
  [(vector plane (mod-nth (:points shape) (- accum step)))
   (mod-nth (:points shape) from) (mod-nth (:points shape)
accum)]
  (recur (- accum step) (ceil (/ step 2)) accum))

[(vector plane (mod-nth (:points shape) accum))
 (mod-nth (:points shape) accum)]


On Nov 1, 12:21 am, Meikel Brandmeyer  wrote:
> Hi,
>
> your code is really hard to understand. Please let let to be your
> friend! I extracted things a little bit and put everything in a let.
> Since I have no clue about collission detection in physics engines I
> derived the local names from the operations done "i"nc, "d"ec, etc.
> More meaningful names conveying domain information are left to the
> astute reader as an excercise. ;-)
>
> You probably can replace defstruct with defrecord. defrecord will
> supersede defstruct eventually.
>
> > (defstruct projection-struct :start :stop :start-points :stop-points)
> > (println 1)
>
> Here you can use the type function. Also note: your method won't work.
> Your dispatch function should match your methods in arity. It may take
> more if they are "don't cares" for the dispatch.
>
> > (defmulti projection (fn [shape & _] (type shape)))
> > (println 2)
>
> As I said, some cleanup with let (hopefully without messing things
> up). Also you cannot "call" integers with vectors. You have to use
> nth.
>
>
>
> > (defmethod projection :polygon
> >   [shape plane]
> >   (let [points  (:points shape)
> >         npoints (int (count points))
> >         dotp    #(->> % (nth points) (dot plane))
> >         search  (fn [condition]
> >                   (loop [accum (int 0)
> >                          step  npoints
> >                          from  (int -1)]
> >                     (let [step        (inc (/ step (int 2)))
> >                           iaccum      (+ accum step)
> >                           daccum      (- accum step)
> >                           naccum      (mod iaccum npoints)
> >                           paccum      (mod daccum npoints)
> >                           dotp-accum  (dotp accum)
> >                           dotp-naccum (dotp naccum)
> >                           dotp-paccum (dotp paccum)
> >                           apoints     (nth points accum)
> >                           fpoints     (nth points from)]
> >                       (condp condition dotp-accum
> >                         dotp-naccum (if (= from iaccum)
> >                                       [dotp-naccum [fpoints apoints]]
> >                                       (recur naccum step accum))
> >                         dotp-paccum (if (= from daccum)
> >                                       [dotp-paccum [fpoints apoints]]
> >                                       (recur paccum step accum))
> >                         [dotp-accum [apoints]]
> >         [start start-points] (search <=)
> >         [end   end-points]   (search >=)]
> >     (struct projection-struct start end start-points end-points)))
> > (println 3)
>
> On 1 Nov., 01:10, Jarl Haggerty  wrote:
>
> > I've also redefined the math functions to work with vectors and
> > matrices.
>
> Hmm.. I would suggest to stay away from such experiments until you
> have a better understanding on Clojure.
>
> That all said: I don't have a problem for your real problem. I don't
> see an obvious reason why the defmethod should hang. I would expect
> some quirk in your environment from outside this code snippet.
>
> Sincerely
> Meikel

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


monads m-seq and m-lift

2010-11-02 Thread Sunil S Nandihalli
Hello everybody,

 I was looking at the functions/macros defined with them I find that m-lift
is very easy and intuitive ..

following is the extract from the monads example ...


(with-monad sequence-m
   (defn pairs [xs]
 ((m-lift 4 #(list :a %1 :b %2 :c %3 :d %4))
  (range 0 3)
  (range 10 13)
  (range 100 103)
  (range 1000 1003

(pairs (range 2))

; Another way to define pairs is through the m-seq operation. It takes


; a sequence of monadic values and returns a monadic value containing


; the sequence of the underlying values, obtained from chaining together


; from left to right the monadic values in the sequence.


(with-monad sequence-m
   (defn pairs [xs]
  (m-seq (list xs xs

can somebody help me understand what is happening in the second one .. ?
when would it be more appropriate to use m-seq instead of m-lift ..

Thanks,
Sunil.

-- 
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: monads m-seq and m-lift

2010-11-02 Thread nicolas.o...@gmail.com
As I understand it, m-seq is transforms a list of monadic computation
into a computation returning the list of result.
The resulting computation just sequentially does every computationin
the sequence and keep the result.

It is useful when the arity is not known at runtime foir example.


On Tue, Nov 2, 2010 at 10:45 AM, Sunil S Nandihalli
 wrote:
> Hello everybody,
>  I was looking at the functions/macros defined with them I find that m-lift
> is very easy and intuitive ..
> following is the extract from the monads example ...
>
> (with-monad sequence-m
>    (defn pairs [xs]
>      ((m-lift 4 #(list :a %1 :b %2 :c %3 :d %4))
>       (range 0 3)
>       (range 10 13)
>       (range 100 103)
>       (range 1000 1003
> (pairs (range 2))
> ; Another way to define pairs is through the m-seq operation. It takes
>
>
> ; a sequence of monadic values and returns a monadic value containing
>
>
> ; the sequence of the underlying values, obtained from chaining together
>
>
> ; from left to right the monadic values in the sequence.
>
>
> (with-monad sequence-m
>    (defn pairs [xs]
>       (m-seq (list xs xs
> can somebody help me understand what is happening in the second one .. ?
> when would it be more appropriate to use m-seq instead of m-lift ..
> Thanks,
> Sunil.
>
> --
> 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



-- 
Sent from an IBM Model M, 15 August 1989.

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


Meta-circular STM for teaching purposes

2010-11-02 Thread Tom Van Cutsem
Hi,

In a couple of months I will teach a new course on concurrent/parallel
programming at the University of Brussels. I will use Clojure for a large
part of the course. I primarily want the students to learn how to make
effective use of the STM as Clojure programmers, but I would also like to
expose them to some "under the hood" implementation details. One option
would be to dive into the actual Java implementation of Clojure's STM, but
my fear is that this will be too complex. Another option I've been thinking
of is to write a simple, didactic STM in Clojure itself (following the SICP
meta-circular interpreters tradition). It goes without saying that high
performance is not the goal here. Rather, it should help students to grasp
atomicity, isolation, interactions between readers/writers, the differences
between alter and commute, etc.

My questions to the list:
- has anyone already experimented with a toy STM in Clojure for didactic
purposes?
- what would be a good resource to start such a design from? (my current
plan is to start from )

Thanks,
Tom

-- 
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: monads m-seq and m-lift

2010-11-02 Thread Konrad Hinsen
On 02.11.2010, at 11:45, Sunil S Nandihalli wrote:

> following is the extract from the monads example ...

It looks quite modified and no longer returns pairs! Here is the original:

(with-monad sequence-m
   (defn pairs [xs]
  ((m-lift 2 #(list %1 %2)) xs xs)))

> ; Another way to define pairs is through the m-seq operation. It takes
>   
>   
> ; a sequence of monadic values and returns a monadic value containing 
>   
>
> ; the sequence of the underlying values, obtained from chaining together  
>   
>
> ; from left to right the monadic values in the sequence.  
>   
>
> (with-monad sequence-m
>(defn pairs [xs]
>   (m-seq (list xs xs
> 
> can somebody help me understand what is happening in the second one .. ? 
> when would it be more appropriate to use m-seq instead of m-lift .. 

In most real-life cases you wouldn't have that choice, as m-lift and m-seq do 
very different things. It's just for making pairs that either one is fine.

One example for the use of m-seq is given right after the pairs example:

(with-monad sequence-m
   (defn ntuples [n xs]
  (m-seq (replicate n xs

This is a generalization from pairs to n-tuples. You couldn't do this using 
m-lift applied to the list function because m-lift requires a fixed arity.

Another example is given later in the example collection under "random number 
generators".

Konrad.

-- 
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: monads m-seq and m-lift

2010-11-02 Thread Ken Wesson
On Tue, Nov 2, 2010 at 7:58 AM, Konrad Hinsen wrote:

> On 02.11.2010, at 11:45, Sunil S Nandihalli wrote:
>
> > following is the extract from the monads example ...
>
> It looks quite modified and no longer returns pairs! Here is the original:
>
> (with-monad sequence-m
>   (defn pairs [xs]
>   ((m-lift 2 #(list %1 %2)) xs xs)))
>
> > ; Another way to define pairs is through the m-seq operation. It takes
> > ; a sequence of monadic values and returns a monadic value containing
> > ; the sequence of the underlying values, obtained from chaining together
> > ; from left to right the monadic values in the sequence.
> > (with-monad sequence-m
> >(defn pairs [xs]
> >   (m-seq (list xs xs
> >
> > can somebody help me understand what is happening in the second one .. ?
> > when would it be more appropriate to use m-seq instead of m-lift ..
>
> In most real-life cases you wouldn't have that choice, as m-lift and m-seq
> do very different things. It's just for making pairs that either one is
> fine.
>
> One example for the use of m-seq is given right after the pairs example:
>
> (with-monad sequence-m
>   (defn ntuples [n xs]
>  (m-seq (replicate n xs
>
> This is a generalization from pairs to n-tuples. You couldn't do this using
> m-lift applied to the list function because m-lift requires a fixed arity.


This wouldn't work?:

(with-monad sequence-m
  (defn ntuples [n xs]
 (apply (m-lift n list) (replicate n xs

(If m-lift is a macro that requires the arity arg to be known at
macroexpansion time:

(with-monad sequence-m
  (defn ntuples [n xs]
 (apply (eval `(m-lift ~n list)) (replicate n xs

instead. Icky, mind you.)

-- 
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: monads m-seq and m-lift

2010-11-02 Thread Konrad Hinsen
On 02.11.2010, at 13:34, Ken Wesson wrote:

> This wouldn't work?:
> 
> (with-monad sequence-m
>   (defn ntuples [n xs]
>  (apply (m-lift n list) (replicate n xs

No.

> (If m-lift is a macro that requires the arity arg to be known at 
> macroexpansion time:
> 
> (with-monad sequence-m
>   (defn ntuples [n xs]
>  (apply (eval `(m-lift ~n list)) (replicate n xs
> 
> instead. Icky, mind you.)

That should work. But once you are at that level of Lisp proficiency, you 
should also have heard the "eval is evil" lesson a few times ;-)

Konrad.

-- 
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: figuring out sets

2010-11-02 Thread tonyl
Wow, this brings more light to the subject. Thank you guys for your
explanations and practical uses.

On Nov 2, 1:31 am, Rasmus Svensson  wrote:
> 2010/11/1 tonyl :
>
> > I was wondering since it uses the dispatch macro and AFAIK
> > there is no api fn to create them like hash-maps to create maps,
> > vector/vec for vectors, or list for lists.
>
> There are parallels to 'hash-map' and 'sorted-map' in the api:
>
> user=> (hash-set :a :b :c)
> #{:a :c :b}
> user=> (sorted-set :a :b :c)
> #{:a :b :c}
>
> Literal maps are hash-maps.
>
> //raek

-- 
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: monads m-seq and m-lift

2010-11-02 Thread Ken Wesson
On Tue, Nov 2, 2010 at 8:55 AM, Konrad Hinsen wrote:

> On 02.11.2010, at 13:34, Ken Wesson wrote:
>
> > This wouldn't work?:
> >
> > (with-monad sequence-m
> >   (defn ntuples [n xs]
> >  (apply (m-lift n list) (replicate n xs
>
> No.
>
> > (If m-lift is a macro that requires the arity arg to be known at
> macroexpansion time:
> >
> > (with-monad sequence-m
> >   (defn ntuples [n xs]
> >  (apply (eval `(m-lift ~n list)) (replicate n xs
> >
> > instead. Icky, mind you.)
>
> That should work. But once you are at that level of Lisp proficiency, you
> should also have heard the "eval is evil" lesson a few times ;-)


Yeah, I wouldn't actually use it for something like that in production code.
In this case I'd use m-seq. In fact the only time I've used eval in
production code, thus far, was in a system that had to generate new
functions on the fly based on data only available at runtime, and for
efficiency reasons those needed to become bytecode and potentially subject
to JIT compilation. So there was a compiler function that took some data,
constructed (fn ...) forms and eval'd them, and returned the resulting
function objects to its caller.

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

A question on distributed computing

2010-11-02 Thread Vivek Khurana
Hi!

 I am currently developing an application where I need to enforce
certain policy on clojure code. My requirement is that code+data can
be sent to a remote node and based on certain access control and
config, one should be able to control whether the remote node is
allowed to execute code or has read only access to the data. The
permission to execute the code can be fine grained such as the remote
node can only edit specific section(s) of the record while it ca read
all the section.
 A common example of this can be health data. One can send patient
record to a remote node and remote node is allowed to add new rows to
specific sections or edit certain sections.
 Any one who has worked on a similar problem ? I am stuck for not been
able to  find a way to enforce the policy on the code+record sent to
remote node using clojure.

regards
Vivek

-- 
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: monads m-seq and m-lift

2010-11-02 Thread Sunil S Nandihalli
Hi Konrad, nicolas and Ken,

Thanks for help. I am sure I will need more help when I try to walk through
the rest of the examples.

But the idea of monads is really neat..:)..


Sunil.

On Tue, Nov 2, 2010 at 7:19 PM, Ken Wesson  wrote:

> On Tue, Nov 2, 2010 at 8:55 AM, Konrad Hinsen 
> wrote:
>
>> On 02.11.2010, at 13:34, Ken Wesson wrote:
>>
>> > This wouldn't work?:
>> >
>> > (with-monad sequence-m
>> >   (defn ntuples [n xs]
>> >  (apply (m-lift n list) (replicate n xs
>>
>> No.
>>
>> > (If m-lift is a macro that requires the arity arg to be known at
>> macroexpansion time:
>> >
>> > (with-monad sequence-m
>> >   (defn ntuples [n xs]
>> >  (apply (eval `(m-lift ~n list)) (replicate n xs
>> >
>> > instead. Icky, mind you.)
>>
>> That should work. But once you are at that level of Lisp proficiency, you
>> should also have heard the "eval is evil" lesson a few times ;-)
>
>
> Yeah, I wouldn't actually use it for something like that in production
> code. In this case I'd use m-seq. In fact the only time I've used eval in
> production code, thus far, was in a system that had to generate new
> functions on the fly based on data only available at runtime, and for
> efficiency reasons those needed to become bytecode and potentially subject
> to JIT compilation. So there was a compiler function that took some data,
> constructed (fn ...) forms and eval'd them, and returned the resulting
> function objects to its caller.
>
>  --
> 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: A question on distributed computing

2010-11-02 Thread Ken Wesson
On Tue, Nov 2, 2010 at 11:03 AM, Vivek Khurana wrote:

> Hi!
>
>  I am currently developing an application where I need to enforce
> certain policy on clojure code. My requirement is that code+data can
> be sent to a remote node and based on certain access control and
> config, one should be able to control whether the remote node is
> allowed to execute code or has read only access to the data. The
> permission to execute the code can be fine grained such as the remote
> node can only edit specific section(s) of the record while it ca read
> all the section.
>  A common example of this can be health data. One can send patient
> record to a remote node and remote node is allowed to add new rows to
> specific sections or edit certain sections.
>  Any one who has worked on a similar problem ? I am stuck for not been
> able to  find a way to enforce the policy on the code+record sent to
> remote node using clojure.
>

That seems impossible assuming you don't trust the software running on the
other node.

What's possible instead is to give data to the remote node on a need-to-know
basis, keep a local copy, and have the remote node submit a changed version
of the data to the local node, which then uses the local copy to undo any
changes that are outside of what is permitted (or to detect them and reject
the entire transaction if any occurred, etc.).

-- 
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: A question on distributed computing

2010-11-02 Thread Sunil S Nandihalli
Hi Vivek,
 Well you could cryptographically sign the data and check the signature in
case you want to verify that the data was not modified.. and you should
require all the nodes to sign the data that they modify and make sure that
no node accepts data that is not signed.. Just an idea..
I have not done anything like this.
Regards,
Sunil.

On Tue, Nov 2, 2010 at 9:26 PM, Ken Wesson  wrote:

> On Tue, Nov 2, 2010 at 11:03 AM, Vivek Khurana wrote:
>
>> Hi!
>>
>>  I am currently developing an application where I need to enforce
>> certain policy on clojure code. My requirement is that code+data can
>> be sent to a remote node and based on certain access control and
>> config, one should be able to control whether the remote node is
>> allowed to execute code or has read only access to the data. The
>> permission to execute the code can be fine grained such as the remote
>> node can only edit specific section(s) of the record while it ca read
>> all the section.
>>  A common example of this can be health data. One can send patient
>> record to a remote node and remote node is allowed to add new rows to
>> specific sections or edit certain sections.
>>  Any one who has worked on a similar problem ? I am stuck for not been
>> able to  find a way to enforce the policy on the code+record sent to
>> remote node using clojure.
>>
>
> That seems impossible assuming you don't trust the software running on the
> other node.
>
> What's possible instead is to give data to the remote node on a
> need-to-know basis, keep a local copy, and have the remote node submit a
> changed version of the data to the local node, which then uses the local
> copy to undo any changes that are outside of what is permitted (or to detect
> them and reject the entire transaction if any occurred, etc.).
>
>  --
> 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: From jetty to war?

2010-11-02 Thread Luke VanderHart
fanvie, two comments:

1. It will get better over time, of course, as standard practices for
Clojure shake out.
2. You don't need 99% of the special crap that Spring/Grails gives
you. Clojure's abstractions are smaller, yes, but the're just as
powerful, and give you more control, in a more standardized way, then
Spring does.

 A couple of examples:

A. Beans & wiring. Spring adds a lot of value in Java - the whole
problem they solve, however, is completely irrelevant in Clojure.
Instead of stateful or singleton beans, just use a namespace filled
with functions. Equally as versatile, equally as configurable, much
less mental and typographical overhead, and all within the language
itself without requiring extra config. If you want another layer of
indirection between your caller and callee, it's trivial to def that
out, too.

B. Security integration. Spring gives you elaborate security-filter-
chains that manage request and session scoped authorization and user
objects, all of which wrap the basic servlet API. Clojure, with
stateless first-class functions, makes this far simpler. In Ring, for
example, all your security functions can be implemented as middleware
that just throws a :user onto the request map. I've done it - it's
literally easier to write a Clojure middleware function that handles
authentication from scratch than it is to figure out how to wire in
whatever spring security filter you need. And all the code you need to
write is actually 100% relevant to your authentication logic. To my
mind, this is a vast improvement over Spring, where the few nuggets of
actual logic are lost in a sea of Java filters, wrappers and xml
configuration files.

The same holds true of most other Spring/Grails idioms, such as MVC,
JDBC access, AOP, etc.


On Nov 1, 5:34 pm, faenvie  wrote:
> my short-time experience with implementing webapps on
> a clojure-base is:
>
> i feel like in the very early days of java-servlet-api and j2ee.
>
> productivity way way way behind springframework or grails
>
> i don't even want to think about doing something sophisticated
> like security-integration.
>
> and of course this is not surprising because everything is
> new and much things are built up from scratch.
>
> esp. when it comes to build and webapp-deployment i feel a
> mismatch that hurts.
>
> (this is an average java-programmer with 2+ years experience
> in implementing webapps with springframework and grails)
>
> thanks & have a successful time

-- 
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: figuring out sets

2010-11-02 Thread Alan
Except when they are small enough to conveniently be array-maps:

user=> (class (into {} (zipmap (range) (range 8
clojure.lang.PersistentArrayMap
user=> (class (into {} (zipmap (range) (range 9
clojure.lang.PersistentHashMap

But those behave just like hash-maps, so you can ignore the
difference.

On Nov 1, 11:31 pm, Rasmus Svensson  wrote:
> 2010/11/1 tonyl :
>
> > I was wondering since it uses the dispatch macro and AFAIK
> > there is no api fn to create them like hash-maps to create maps,
> > vector/vec for vectors, or list for lists.
>
> There are parallels to 'hash-map' and 'sorted-map' in the api:
>
> user=> (hash-set :a :b :c)
> #{:a :c :b}
> user=> (sorted-set :a :b :c)
> #{:a :b :c}
>
> Literal maps are hash-maps.
>
> //raek

-- 
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: to macro or not?

2010-11-02 Thread Laurent PETIT
2010/10/30 Tim Daly :
>  Macros in lisp get used for three general purposes, at least
> in my experience.
>
> The first purpose is efficiency. In common lisp you will find
> that you can generate very machine-efficient (aka optimized
> fortran level) binary instruction sequences if you add type
> information. This gets tedious to do in code so you write a
> macro. So (+ x y) has to assume that x and y are anything,
> including non-numeric. If you write a (plus x y) macro it
> can expand to
> (the fixnum (+ (the fixnum x) (the fixnum y)))
> which I have seen optimized into a single machine instruction.
> Macros could be used to solve the boxing/unboxing issues in
> Clojure.

For writing DSLs, consider the excellent speak of cgrand at the conj :
(not= DSL macros)

Here are the slides: http://speakerrate.com/talks/4895-not-dsl-macros


>
> The second purpose is novel control structure. Axiom uses a
> type-dispatch macro that does a "method lookup" in a "class"
> (bad analogy but...) and the type dispatch macro gets expanded
> at compile time to a constant-index offset into a fixed-array
> data structure. So the total cost is a single index pointer fetch
> at runtime. You could write a "domap" macro that works like the
> "map" function but isn't lazy. Replace your "map" with "domap"
> and solve the lazy issue mentioned in another thread (or just use
> seq :-) )
>
> The third purpose is a domain specific language. At work my team
> always communicates using certain words and phrases such as CCAs,
> behavior catalogs, etc. and we use a locally invented notation.
> I took the notation and added parentheses in all the right places
> and implemented macros for them. Now I can take a specification,
> plop in some parens, and execute the specification. This makes it
> much easier to ensure the implementation follows the specification.
> It also allows me to macro-expand the same line of code for several
> kinds of output Our files are XML but our displays are for humans.
> Since both outputs come from the same macro I know they match.
>
> Macros are not hard but you need to think like a compiler rather
> than a programmer. You are transforming a program into a program.
>
> Macros really bring home the point that your program is data and
> your data is a program. It is worth learning to write macros just
> for that insight alone.
>
> Tim Daly
>
>
> On 10/28/2010 3:55 PM, Raoul Duke wrote:
>>
>> hi,
>>
>> not looking to stir up a pot, looking to learn from people's
>> experience. i've heard that in CL land, one is told to avoid macros as
>> long as possible. i've heard other folks in the Clojure world say that
>> if you aren't using macros, then sorta why bother use a Lisp since you
>> are missing out on one of the most powerful differentiators. then
>> reading about Conj it sounds like some folks say stay away from macros
>> if you can.
>>
>> any way of teasing out when macros are ok? :-) i mean, are they only
>> ok for the internals of the Clojure system?
>>
>> 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 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: to macro or not?

2010-11-02 Thread Ken Wesson
On Tue, Nov 2, 2010 at 1:38 PM, Laurent PETIT wrote:

> 2010/10/30 Tim Daly :
> >  Macros in lisp get used for three general purposes, at least
> > in my experience.
> >
> > The first purpose is efficiency. In common lisp you will find
> > that you can generate very machine-efficient (aka optimized
> > fortran level) binary instruction sequences if you add type
> > information. This gets tedious to do in code so you write a
> > macro. So (+ x y) has to assume that x and y are anything,
> > including non-numeric. If you write a (plus x y) macro it
> > can expand to
> > (the fixnum (+ (the fixnum x) (the fixnum y)))
> > which I have seen optimized into a single machine instruction.
> > Macros could be used to solve the boxing/unboxing issues in
> > Clojure.
>
> For writing DSLs, consider the excellent speak of cgrand at the conj :
> (not= DSL macros)
>
> Here are the slides: http://speakerrate.com/talks/4895-not-dsl-macros


Here's something odd: I can't view the slides. I have Chrome and Firefox
here. If I go there in Chrome the grey box that I assume should contain the
slides is blank. I'm guessing they used Flash instead of Java or AJAX; and I
haven't been able to get Flash working in Chrome.

On the other hand if I go there in Firefox I get told "The connection was
reset". This happens also if I prepend "www." to the domain name. So
apparently speakerrate.com slams the door on Firefox users -- I thought that
kind of browser-discrimination stupidity went out with the 90s? -- and
indeed violates RFCs by having www.speakerrate.com respond with RST to a
connection on port 80.

-- 
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: From jetty to war?

2010-11-02 Thread Wilson MacGyver
On Tue, Nov 2, 2010 at 12:49 PM, Luke VanderHart
 wrote:
> fanvie, two comments:
> 2. You don't need 99% of the special crap that Spring/Grails gives
> you. Clojure's abstractions are smaller, yes, but the're just as
> powerful, and give you more control, in a more standardized way, then
> Spring does.

I'll take exception to this comment. I think calling what grails as a framework
provide you as "special crap", is at best, a disservice to grails as well as
other web framework.

At the end of the day, people want to deliver a solution for a problem they are
working on. Not focusing on "oh look, shiny technology and abstractions"

There is value in being able to define a domain object, and right off the bat
have ORM taken care of for you, tables created, controllers setup
with CRUD/webservice/scafold.

and then grails war to produce a complete single war file to deploy to any
java application server.

Not everyone "needs" it, but that doesn't make it crap.

---
Omnem crede diem tibi diluxisse supremum.

-- 
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: to macro or not?

2010-11-02 Thread Meikel Brandmeyer
Hi,

Am 02.11.2010 um 18:46 schrieb Ken Wesson:

> http://speakerrate.com/talks/4895-not-dsl-macros

The link works perfectly for me in firefox. No discrimination stupidity here...

Sincerely
Meikel


-- 
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: REQUEST for feedback on http://clojure.org

2010-11-02 Thread Rick Mouritzen
Los Angeles Clojure Users Group
http://clj-la.org/

On Sat, Oct 30, 2010 at 7:38 PM, Alex Miller  wrote:

> Hi all,
>
> I'm doing a bit of doc cleanup on http://clojure.org and I'd welcome
> your feedback on things that are broken or could be improved.  I'm not
> looking (or likely authorized :) to make any drastic changes but if
> there are things that you have run into, please drop a line here or in
> email to alexdmiller at yahoo.com.  Ideally, I'd like people to be
> logging tickets in jira, but I'm not sure it's quite ready for that
> yet.
>
> Some recent changes I've already made:
> - switched all of the old richhickey github references to clojure
> - cleaned up some factually wrong or out of date stuff on getting
> started and download pages
> - added Protocol and Datatypes pages to left nav (the pages have
> existed for 6 months)
> - added a page on starting a user group (still in review, not yet
> linked)
> - currently working on updating the cheat sheet to the 1.2 version
> (and adding links!)
>
> I'm particularly interested in:
> - new user groups or suggestions for the community page
> - stuff that is just wrong or out of date
>
> This DOES NOT include stuff in the API or Contrib autodoc pages.
> Please raise those issues or file tickets on those but that's not what
> I'm focusing on at the moment.
>
> Alex
>
> --
> 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: to macro or not?

2010-11-02 Thread Ken Wesson
On Tue, Nov 2, 2010 at 2:49 PM, Meikel Brandmeyer  wrote:

> Hi,
>
> Am 02.11.2010 um 18:46 schrieb Ken Wesson:
>
> > http://speakerrate.com/talks/4895-not-dsl-macros
>
> The link works perfectly for me in firefox. No discrimination stupidity
> here...
>

Yeah, that's weird. It seems to have been discriminating against Firefox
only temporarily:

Open in Chrome -> works (but no Flash)
Immediately open in Firefox -> RST
Reload -> RST
Reload -> RST
(repeat about 10 times)
(wait a couple minutes)
Reload -> RST
Immediately open in Chrome -> works
Post complaint

(hours later)

You post saying it works in Firefox
Open in Firefox -> works normally.

That's weird. Either it was "down" (in a "the hardware is switched on and
has power and a working internet connection and the OS is booted up and has
a functioning TCP stack but no httpd is running" sort of way) with *exactly*
the correct timing for it to be down whenever I happened to be trying to
access it in Firefox but up whenever I happened to be in Chrome, or else it
was temporarily blocking FF users earlier but has now stopped.

Either is damned weird. ("Down" should, in general, result in timeout
errors, not RST packets. If the machine has power and bandwidth and the OS
will boot then it ought to be able to run the webserver. And the timing
coincidence. Alternatively, browser discrimination that's
on-again-off-again.)

-- 
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: REQUEST for feedback on http://clojure.org

2010-11-02 Thread Kyle R. Burton
>> I'm particularly interested in:
>> - new user groups or suggestions for the community page
>> - stuff that is just wrong or out of date

Philly Clojure Language Club:
http://groups.google.com/group/phl-clojure-language-club

Kyle

-- 
Twitter: @kyleburton
Blog: http://asymmetrical-view.com/
Fun: http://snapclean.me/

-- 
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: From jetty to war?

2010-11-02 Thread lprefontaine
Luke, I must agree with Wilson, other frameworks have some advantages
presently over Clojure for certain tasks.

We use RAILS and JRuby to create CRUD GUIs with ActiveScaffold.
Our controllers are typically 20 lines or less of configuration statements... 
We do not need to maintain HTML templates either.

When I looked at Grails 18 months ago it was requiring more code
lines than Rails for our purpose but this has certainly improved somehow
overtime.

Hard to beat Rails now. We will build some prototype with Conjoure
in the next year or so to see how it fares compared to RAILS.

We are testing a web app to display the medical record in a read only
fashion and we used Compojure coupled with Spring and Hibernate.
It will be in beta testing next week. It has to support 100 users.
Using Hibernate was a logicial choice.

We still use Spring but only to wire low-level stuff (like the
ORM and factoring some objects interfacing with libraries). Spring does
a good job at this and we do not write tons of XML lines or even code
to get this to work.

Luc P.

Wilson MacGyver  wrote ..
> On Tue, Nov 2, 2010 at 12:49 PM, Luke VanderHart
>  wrote:
> > fanvie, two comments:
> > 2. You don't need 99% of the special crap that Spring/Grails gives
> > you. Clojure's abstractions are smaller, yes, but the're just as
> > powerful, and give you more control, in a more standardized way, then
> > Spring does.
> 
> I'll take exception to this comment. I think calling what grails as a 
> framework
> provide you as "special crap", is at best, a disservice to grails as well as
> other web framework.
> 
> At the end of the day, people want to deliver a solution for a problem they 
> are
> working on. Not focusing on "oh look, shiny technology and abstractions"
> 
> There is value in being able to define a domain object, and right off the bat
> have ORM taken care of for you, tables created, controllers setup
> with CRUD/webservice/scafold.
> 
> and then grails war to produce a complete single war file to deploy to any
> java application server.
> 
> Not everyone "needs" it, but that doesn't make it crap.
> 
> ---
> Omnem crede diem tibi diluxisse supremum.
> 
> -- 
> 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


[Bug] StackOverflowError while using map inside a reduce

2010-11-02 Thread Pepijn de Vos
Hi all,

Usually my 'bugs' are in my own code, but this time I talked to three of four 
people on IRC and came up with a one-liner that suffers the same problem my 
project has.

I was optimizing some code to not retain the head of the sequence, but when I 
put a map inside a reduce over a gigantic partitioned seq, I got a stack 
overflow error.

Some people on IRC thought it'd be a problem with reduce or chunked seqs.

The problem is very much reproducible on Clojure 1.2 and one workaround is to 
use pmap, because threads get their own stack. But as said in the docstring of 
pmap, it's very inefficient for small operations like this.

The one-liner:
http://gist.github.com/659491

The project:
http://github.com/pepijndevos/Clomian/blob/master/src/clomian.clj#L33

I hope this can get fixed or that someone can give me a better solution.

Groeten,
Pepijn de Vos
--
Sent from my iPod Shuffle
http://pepijndevos.nl

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


Resources on optimizing Clojure code

2010-11-02 Thread Dan Kefford
Hello fellow clojurians...

I've been using Clojure now fairly regularly for the past two months
solving problems on Project Euler. I've been fairly successful solving
them but there are times where the performance of my code either
stinks (the answer may come back in 5-10 minutes) or not at all even
though I have effectively solved the problem (the code is correct and
will return the answer for n < 1000 but for n < 10^8... forget about
it.)

My question is: are there any materials out there on how to optimize
performance of Clojure code? There doesn't seem to be a lot out there.

Thanks in advance,

dan kefford

-- 
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: A suggestion for the next Conj

2010-11-02 Thread Roger Austin (@RogerTheGeek)
At NCDevCon, we had sessions that were hands-on where the attendees
could bring their laptop and get completely set up with their
programming
environment and tools. Plus, an expert gave a demo on how to get
started
and an overview. Usually, they were half day or full day sessions.

That could be another idea to try at the next Conj, but I don't know
how
many people were Clojure noobs like me.

Either that or have a formal class associated with the Conj that
would
run just before it.

I also like David's idea. NCDevCon had three charities that we
sponsored
using donations, collecting donations for the refreshments and
proceeds
for selling T-shirts. It is an extra, but was well received.

On Oct 31, 8:05 pm, David Cabana  wrote:

> I missed the chance to donate this time.  By the time I read about
> Chas' idea, it was a done deal.  I would like the chance to help out
> next time.  Traditions are a fine thing, and we have been handed the
> chance to start a great one.
>
> Maybe there are some down sides that I'm not seeing, but I think it's
> worth talking about. What do you think?

-- 
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: [Bug] StackOverflowError while using map inside a reduce

2010-11-02 Thread Meikel Brandmeyer
Hi,

Am 02.11.2010 um 12:58 schrieb Pepijn de Vos:

> The one-liner:
> http://gist.github.com/659491

I would expect this is because you pile lazy seq on lazy seq, which then get 
realised, unfolding the whole thing resulting in the stack overflow. Try this:

user=> (reduce #(doall (map + %1 %2)) (partition 5 (range 1e6)))
(950 970 990 1010 1030)

Sincerely
Meikel


-- 
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: Resources on optimizing Clojure code

2010-11-02 Thread Alan
Usually it's more about the algorithm than the language. Java can
generally do things faster than clojure, simply because it has fewer
layers, but the speedup is a linear factor. If the java solution for
1000 elements takes 5ms and your clojure code takes even a second,
it's likely that clojure isn't to blame. Maybe you could post one of
your solutions, or simply compare it to a java solution yourself?

On Nov 2, 10:32 am, Dan Kefford  wrote:
> Hello fellow clojurians...
>
> I've been using Clojure now fairly regularly for the past two months
> solving problems on Project Euler. I've been fairly successful solving
> them but there are times where the performance of my code either
> stinks (the answer may come back in 5-10 minutes) or not at all even
> though I have effectively solved the problem (the code is correct and
> will return the answer for n < 1000 but for n < 10^8... forget about
> it.)
>
> My question is: are there any materials out there on how to optimize
> performance of Clojure code? There doesn't seem to be a lot out there.
>
> Thanks in advance,
>
> dan kefford

-- 
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: Resources on optimizing Clojure code

2010-11-02 Thread David Andrews
Yes, on the handful of Project Euler exercises I've attempted, my
algorithm choice was frequently the source of poor performance.

Are you familiar with the clojure-euler wiki at 
http://clojure-euler.wikispaces.com/
?  After I do an Euler exercise I compare my code and runtime with
other Clojure submissions, and learn a lot from other people's code.

-- 
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: REQUEST for feedback on http://clojure.org

2010-11-02 Thread Jason Wolfe
Not sure if you count this as off limits as part of the API page, but
its first line points to a stale "official source code for clojure"
-- should be updated to the new github repo.

-Jason

On Oct 30, 7:38 pm, Alex Miller  wrote:
> Hi all,
>
> I'm doing a bit of doc cleanup onhttp://clojure.organd I'd welcome
> your feedback on things that are broken or could be improved.  I'm not
> looking (or likely authorized :) to make any drastic changes but if
> there are things that you have run into, please drop a line here or in
> email to alexdmiller at yahoo.com.  Ideally, I'd like people to be
> logging tickets in jira, but I'm not sure it's quite ready for that
> yet.
>
> Some recent changes I've already made:
> - switched all of the old richhickey github references to clojure
> - cleaned up some factually wrong or out of date stuff on getting
> started and download pages
> - added Protocol and Datatypes pages to left nav (the pages have
> existed for 6 months)
> - added a page on starting a user group (still in review, not yet
> linked)
> - currently working on updating the cheat sheet to the 1.2 version
> (and adding links!)
>
> I'm particularly interested in:
> - new user groups or suggestions for the community page
> - stuff that is just wrong or out of date
>
> This DOES NOT include stuff in the API or Contrib autodoc pages.
> Please raise those issues or file tickets on those but that's not what
> I'm focusing on at the moment.
>
> Alex

-- 
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: REQUEST for feedback on http://clojure.org

2010-11-02 Thread Alex Miller
- Jeff, Rick, Kyle - I've added your groups
- added other groups mentioned on #clojure and twitter
- cheat sheet has been updated to 1.2
- new "tips on starting a user group" page added - 
http://clojure.org/start_group
(linked from the community page)
- fixed broken links on contributing page
- fixed old text on top of Datatypes page (pre 1.2)

Alex


On Nov 2, 2:45 pm, "Kyle R. Burton"  wrote:
> >> I'm particularly interested in:
> >> - new user groups or suggestions for the community page
> >> - stuff that is just wrong or out of date
>
> Philly Clojure Language 
> Club:http://groups.google.com/group/phl-clojure-language-club
>
> Kyle
>
> --
> Twitter: @kyleburton
> Blog:http://asymmetrical-view.com/
> Fun:http://snapclean.me/

-- 
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: REQUEST for feedback on http://clojure.org

2010-11-02 Thread Michael Wood
This is perhaps a little off topic, but related.

I see that http://code.google.com/p/clojure/ has been updated
recently, but still references Assembla.

These could do with an update too:

http://sourceforge.net/projects/clojure/
http://sourceforge.net/projects/clojure-contrib/

-- 
Michael Wood 

-- 
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: REQUEST for feedback on http://clojure.org

2010-11-02 Thread Alex Miller
Jason - that's a good catch but out of my purview.  Also, those are
autodocs generated from the (released and thus immutable :) 1.2
afaik.


On Nov 2, 4:12 pm, Jason Wolfe  wrote:
> Not sure if you count this as off limits as part of the API page, but
> its first line points to a stale "official source code for clojure"
> -- should be updated to the new github repo.
>
> -Jason
>
> On Oct 30, 7:38 pm, Alex Miller  wrote:
>
>
>
>
>
>
>
> > Hi all,
>
> > I'm doing a bit of doc cleanup onhttp://clojure.organdI'd welcome
> > your feedback on things that are broken or could be improved.  I'm not
> > looking (or likely authorized :) to make any drastic changes but if
> > there are things that you have run into, please drop a line here or in
> > email to alexdmiller at yahoo.com.  Ideally, I'd like people to be
> > logging tickets in jira, but I'm not sure it's quite ready for that
> > yet.
>
> > Some recent changes I've already made:
> > - switched all of the old richhickey github references to clojure
> > - cleaned up some factually wrong or out of date stuff on getting
> > started and download pages
> > - added Protocol and Datatypes pages to left nav (the pages have
> > existed for 6 months)
> > - added a page on starting a user group (still in review, not yet
> > linked)
> > - currently working on updating the cheat sheet to the 1.2 version
> > (and adding links!)
>
> > I'm particularly interested in:
> > - new user groups or suggestions for the community page
> > - stuff that is just wrong or out of date
>
> > This DOES NOT include stuff in the API or Contrib autodoc pages.
> > Please raise those issues or file tickets on those but that's not what
> > I'm focusing on at the moment.
>
> > Alex

-- 
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: [Bug] StackOverflowError while using map inside a reduce

2010-11-02 Thread John Szakmeister
On Tue, Nov 2, 2010 at 4:49 PM, Meikel Brandmeyer  wrote:
> Hi,
>
> Am 02.11.2010 um 12:58 schrieb Pepijn de Vos:
>
>> The one-liner:
>> http://gist.github.com/659491
>
> I would expect this is because you pile lazy seq on lazy seq, which then get 
> realised, unfolding the whole thing resulting in the stack overflow. Try this:

I'm sorry... I don't quite understand this explanation.  Do you mean
that reduce is realizing the entire list all at once?  I would think
it would grab an element one at a time.  Sorry for the stupid
question, but there's something subtle here that I'm not
understanding.

> user=> (reduce #(doall (map + %1 %2)) (partition 5 (range 1e6)))
> (950 970 990 1010 1030)

Is it because of the way the lazy sequence is being generated?  Would
different implementations of partition or range do better?

Thanks in advance!

-John

-- 
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: [Bug] StackOverflowError while using map inside a reduce

2010-11-02 Thread Rasmus Svensson
2010/11/3 John Szakmeister :
> I'm sorry... I don't quite understand this explanation.  Do you mean
> that reduce is realizing the entire list all at once?  I would think
> it would grab an element one at a time.  Sorry for the stupid
> question, but there's something subtle here that I'm not
> understanding.
>
>> user=> (reduce #(doall (map + %1 %2)) (partition 5 (range 1e6)))
>> (950 970 990 1010 1030)
>
> Is it because of the way the lazy sequence is being generated?  Would
> different implementations of partition or range do better?
>
> Thanks in advance!
>
> -John

I think the problem is that this reduction will build an expression like this:

(map + ... (map + ... (map + ... (map + ... 

When clojure tries to realize an element of the resulting lazy seq,
every level will result in a nested method call, which will eventually
blow the stack.

// raek

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


Java gotchas now clojure gotchas

2010-11-02 Thread box
Math/abs doesn't always return positive numbers. example:


user=> (def min-int -2147483648)
#'user/min-int

user=> min-int
-2147483648

user=> (Math/abs min-int)
-2147483648

user=> (def min-int+1 (+ 1 min-int))
#'user/min-int+1

user=> min-int+1
-2147483647

user=> (Math/abs (- min-int+1 1))
-2147483648

(Math/abs (- Integer/MIN_VALUE 1))
2147483649



so, in order to solve this problem, clojure needs it's own ABS, or it
needs to convert a negative int approaching Integer/MIN_VALUE to
something else before it reaches Integer/MIN_VALUE.

so, does it sound sane for clojure to fix java's surprises?

-- 
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: From jetty to war?

2010-11-02 Thread Chris Riddoch
On Tue, Nov 2, 2010 at 10:49 AM, Luke VanderHart
 wrote:
> fanvie, two comments:
>
> 1. It will get better over time, of course, as standard practices for
> Clojure shake out.
> 2. You don't need 99% of the special crap that Spring/Grails gives
> you. Clojure's abstractions are smaller, yes, but the're just as
> powerful, and give you more control, in a more standardized way, then
> Spring does.

Given other responses, I'd like to chime in with some agreement with
Luke.  I think it's important to be aware of what frameworks do for
you, and what they don't do.  It can be very easy, in a framework like
Rails, to get a simple UI for doing basic CRUD operations on a single
table, and for indicating basic relationships in the model. And
someone's written a little HTML here and there to save you a little
effort in the view.

But what frameworks *don't* give you is a solution to the particular
problem you're working on, and while it seems at first like they've
already written 80% of your app, you'll quickly find that it's really
a lot closer to 8% -- and the easy 8%, at that.

For anything more complicated than a grocery list, the differences
between frameworks is dwarfed by the application-specific logic of
your project.  I'm always amused when people try out some framework by
making a blog, "proving" their framework is better because they could
do it in 20 lines of code instead of 30.

Beware frameworks that claim to be "easy."  It usually means that the
complexity lurks somewhere else.

-- 
Chris Riddoch

-- 
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: Java gotchas now clojure gotchas

2010-11-02 Thread CuppoJava
Personally, I find the added time and complexity required to be
careful about such problems (ie. numerical overflow) is easier to deal
with than later having to optimize subtle performance problems that
arise from these automatic boxing / upcasting solutions. From the
frequency of performance-related posts on the newsgroup, it seems I'm
not the only one who finds optimizing Clojure difficult enough as it
is.
  -Patrick

On Nov 2, 6:22 pm, box  wrote:
> Math/abs doesn't always return positive numbers. example:
>
> user=> (def min-int -2147483648)
> #'user/min-int
>
> user=> min-int
> -2147483648
>
> user=> (Math/abs min-int)
> -2147483648
>
> user=> (def min-int+1 (+ 1 min-int))
> #'user/min-int+1
>
> user=> min-int+1
> -2147483647
>
> user=> (Math/abs (- min-int+1 1))
> -2147483648
>
> (Math/abs (- Integer/MIN_VALUE 1))
> 2147483649
>
> so, in order to solve this problem, clojure needs it's own ABS, or it
> needs to convert a negative int approaching Integer/MIN_VALUE to
> something else before it reaches Integer/MIN_VALUE.
>
> so, does it sound sane for clojure to fix java's surprises?

-- 
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: Java gotchas now clojure gotchas

2010-11-02 Thread Sean Corfield
On Tue, Nov 2, 2010 at 3:22 PM, box  wrote:
> Math/abs doesn't always return positive numbers. example:

Have you tried this on 1.3.0-master-SNAPSHOT?

user=> (def min-int -2147483648)
#'user/min-int
user=> (Math/abs min-int)
2147483648
user=> (def min-int+1 (+ 1 min-int))
#'user/min-int+1
user=> min-int+1
-2147483647
user=> (Math/abs (- min-int+1 1))
2147483648
user=> (Math/abs (- Integer/MIN_VALUE 1))
2147483649
-- 
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

-- 
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: Java gotchas now clojure gotchas

2010-11-02 Thread Benny Tsai
Have you checked out clojure-contrib.math's abs function?  It appears
to do the right thing for the cases you listed.

On Nov 2, 4:22 pm, box  wrote:
> Math/abs doesn't always return positive numbers. example:
>
> user=> (def min-int -2147483648)
> #'user/min-int
>
> user=> min-int
> -2147483648
>
> user=> (Math/abs min-int)
> -2147483648
>
> user=> (def min-int+1 (+ 1 min-int))
> #'user/min-int+1
>
> user=> min-int+1
> -2147483647
>
> user=> (Math/abs (- min-int+1 1))
> -2147483648
>
> (Math/abs (- Integer/MIN_VALUE 1))
> 2147483649
>
> so, in order to solve this problem, clojure needs it's own ABS, or it
> needs to convert a negative int approaching Integer/MIN_VALUE to
> something else before it reaches Integer/MIN_VALUE.
>
> so, does it sound sane for clojure to fix java's surprises?

-- 
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: Java gotchas now clojure gotchas

2010-11-02 Thread ataggart
In a two's-complement system, values always have one more negative
number than positive number. -2147483648 (being the most negative int)
has no positive equivalent that can be expressed as an int (Math/abs
overloads on primitive type).

Sean's example using 1.3.0-SNAPSHOT works because literal numbers are
now read in as longs or doubles.  This is also why the original (Math/
abs (- Integer/MIN_VALUE 1)) gave the desired result as the int was
converted to a long via the subtraction function.

Of course, the same "problem" would arise if one tried to use the most
negative long:

user=> (Math/abs Long/MIN_VALUE)
-9223372036854775808

The unsurprising behavior might be for a clojure abs function to
instead throw an ArithmeticException, since 9223372036854775808 cannot
be expressed as a long.

-- 
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: Java gotchas now clojure gotchas

2010-11-02 Thread box
this is on clojure 1.1 (current ubuntu stable rep)
so, the code below shows ABS returning 2 different values for the
'same' input in clojure. input being Integer.MIN_VALUE.
of course one input is an int and the other is a bigint, but we can't
see the difference in clojure, and as the code shows at the end,
clojure says they are the same input.

@CuppoJava:
to take more care in how we code is a good idea, but i feel that rich
hickey doesn't want users of clojure to be thinking about if a certain
function is going to act a certain way for inputs that clojure says
are the same, but java says are different. i think this type of
problem is on the same level as managing the memory of your
application.

user=> (def min-int-1 (+ -1 min-int))
#'user/min-int-1
user=> min-int-1
-2147483649
user=> (- min-int-1 min-int)
-1
user=> (Math/abs (+ 1 min-int-1))
2147483648
user=> (Math/abs min-int)
-2147483648

user=> (= (+ 1 min-int-1) min-int)
true


@Sean Corfield:
I haven't tried this on clojure 1.3. is it part of the clojure road
map to eliminate the surprises built into the java language? I think
that it would be easy to eliminate a majority of them. a good resource
is the book 'java puzzlers' http://www.javapuzzlers.com/ which
provides the code in the book for free on their website. not all of
the surprises will apply to clojure because they'll be avoided by
avoiding the use of java, but some will still apply, and they should
be considered in the definition of the language, and when using
interop code.


so, in summary, ABS in java has a bug/surprise. clojure uses this
directly. so clojure has a bug in abs. it's really unlikely that
someone will pass abs an Integer.MIN_VALUE, but maybe it should be
considered. i think the more likely thing to happen is that abs will
be passed a number that is a result of another number being
manipulated. so one solution would be to change to a bigint earlier
than the language does now. or maybe closure could make a safe abs
wrapper.

I know it's not a big deal, but when you write a program that uses all
integers (quite easy to program in clojure), and also uses abs, and it
breaks when it hits this bug...

Rich hickey's answer to why he made clojure was that he wanted to
write programs without going crazy, fixing some of the stuff that is
broken in java, that clojure uses, seems like it follows that spirit.

On Nov 2, 9:33 pm, Sean Corfield  wrote:
> On Tue, Nov 2, 2010 at 3:22 PM, box  wrote:
> > Math/abs doesn't always return positive numbers. example:
>
> Have you tried this on 1.3.0-master-SNAPSHOT?
>
> user=> (def min-int -2147483648)
> #'user/min-int
> user=> (Math/abs min-int)
> 2147483648
> user=> (def min-int+1 (+ 1 min-int))
> #'user/min-int+1
> user=> min-int+1
> -2147483647
> user=> (Math/abs (- min-int+1 1))
> 2147483648
> user=> (Math/abs (- Integer/MIN_VALUE 1))
> 2147483649
> --
> Sean A Corfield -- (904) 302-SEAN
> Railo Technologies, Inc. --http://getrailo.com/
> An Architect's View --http://corfield.org/
>
> "If you're not annoying somebody, you're not really alive."
> -- Margaret Atwood

-- 
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: From jetty to war?

2010-11-02 Thread lprefontaine
Ahem..

Your comment misses the point. We chose RAILS because it met 90% of our 
needs... not because of some claims it would solve any problem.
We then selected RAILS over Grails then based on the time it required us to 
code, the # of code lines was a very good measure then to make our final 
selection between these two.

This is why we use a mix of RAILS, Clojure and Spring. We chose the components
best fitted to do specific things in our design. We did not choose a buzz word
and then tried to make everything a nail so we could use a single hammer.

For the medical record read-only view we did in Compojure/Clojure to
extract a tree like model from the database and do html rendering with
hiccup.
Why ? because it was a perfect match for Clojure's abilities and it's very
concise code-wise. There are around 50 tables to grab to display a medical
record. Rails would have been too complex to implement over this
since we only need to provide a read only view.

Choosing between frameworks or making them coexist requires some
knowledge about them, then you can have a selection process and see were
you can apply them.

Doing the reverse is non sense (choosing a framework based on some hyped 
reviews and then use for every need).

BTW, we are driving interactions between several services in an hospital here,
you can bet it's a bit more complex than a grocery list :)

I totally agree that Clojure is a better tool to create abstractions, however
we need to deliver now something that works today in the real world.
Reusing what is available if it eases the pain to deliver is common sense.

We cannot rewrite the whole universe in Clojure in one year. That's a fact.
It's improving but will take some time to cover a number of areas.

None of the above choices we made are static in time. They will change as 
things evolve over time and yes we tend to favor Clojure as much as possible
to replace the other frameworks when an alternate solution is ready.

We do not necessarily wait for prime time here, we are willing to push things
in production that are not yet polished but not at the expense of increased
delivery times and efforts.

And again no we are not in the retail business at all :)))


Luc P.



Chris Riddoch  wrote ..
> On Tue, Nov 2, 2010 at 10:49 AM, Luke VanderHart
>  wrote:
> > fanvie, two comments:
> >
> > 1. It will get better over time, of course, as standard practices for
> > Clojure shake out.
> > 2. You don't need 99% of the special crap that Spring/Grails gives
> > you. Clojure's abstractions are smaller, yes, but the're just as
> > powerful, and give you more control, in a more standardized way, then
> > Spring does.
> 
> Given other responses, I'd like to chime in with some agreement with
> Luke.  I think it's important to be aware of what frameworks do for
> you, and what they don't do.  It can be very easy, in a framework like
> Rails, to get a simple UI for doing basic CRUD operations on a single
> table, and for indicating basic relationships in the model. And
> someone's written a little HTML here and there to save you a little
> effort in the view.
> 
> But what frameworks *don't* give you is a solution to the particular
> problem you're working on, and while it seems at first like they've
> already written 80% of your app, you'll quickly find that it's really
> a lot closer to 8% -- and the easy 8%, at that.
> 
> For anything more complicated than a grocery list, the differences
> between frameworks is dwarfed by the application-specific logic of
> your project.  I'm always amused when people try out some framework by
> making a blog, "proving" their framework is better because they could
> do it in 20 lines of code instead of 30.
> 
> Beware frameworks that claim to be "easy."  It usually means that the
> complexity lurks somewhere else.
> 
> -- 
> Chris Riddoch
> 
> -- 
> 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: Java gotchas now clojure gotchas

2010-11-02 Thread Paul Iannazzo
user=> (Math/abs (- Long/MIN_VALUE 1)

this hung my clojure repl, clojure 1.1

~~
Paul Joseph Iannazzo.



On Tue, Nov 2, 2010 at 10:09 PM, ataggart  wrote:

> In a two's-complement system, values always have one more negative
> number than positive number. -2147483648 (being the most negative int)
> has no positive equivalent that can be expressed as an int (Math/abs
> overloads on primitive type).
>
> Sean's example using 1.3.0-SNAPSHOT works because literal numbers are
> now read in as longs or doubles.  This is also why the original (Math/
> abs (- Integer/MIN_VALUE 1)) gave the desired result as the int was
> converted to a long via the subtraction function.
>
> Of course, the same "problem" would arise if one tried to use the most
> negative long:
>
> user=> (Math/abs Long/MIN_VALUE)
> -9223372036854775808
>
> The unsurprising behavior might be for a clojure abs function to
> instead throw an ArithmeticException, since 9223372036854775808 cannot
> be expressed as a long.
>
> --
> 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: Java gotchas now clojure gotchas

2010-11-02 Thread box
sorry, i wrote too soon.

(Math/abs (- Long/MIN_VALUE 1))
java.lang.IllegalArgumentException: No matching method found: abs
(NO_SOURCE_FILE:0)

so, maybe this is a good time to start a clojure math library. or at
least have some warning when using math libs in clojure.

On Nov 2, 10:32 pm, Paul Iannazzo  wrote:
> user=> (Math/abs (- Long/MIN_VALUE 1)
>
> this hung my clojure repl, clojure 1.1
>
> ~~
> Paul Joseph Iannazzo.
>
> On Tue, Nov 2, 2010 at 10:09 PM, ataggart  wrote:
> > In a two's-complement system, values always have one more negative
> > number than positive number. -2147483648 (being the most negative int)
> > has no positive equivalent that can be expressed as an int (Math/abs
> > overloads on primitive type).
>
> > Sean's example using 1.3.0-SNAPSHOT works because literal numbers are
> > now read in as longs or doubles.  This is also why the original (Math/
> > abs (- Integer/MIN_VALUE 1)) gave the desired result as the int was
> > converted to a long via the subtraction function.
>
> > Of course, the same "problem" would arise if one tried to use the most
> > negative long:
>
> > user=> (Math/abs Long/MIN_VALUE)
> > -9223372036854775808
>
> > The unsurprising behavior might be for a clojure abs function to
> > instead throw an ArithmeticException, since 9223372036854775808 cannot
> > be expressed as a long.
>
> > --
> > 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: Java gotchas now clojure gotchas

2010-11-02 Thread Mark Engelberg
On Tue, Nov 2, 2010 at 7:35 PM, box  wrote:
> so, maybe this is a good time to start a clojure math library. or at
> least have some warning when using math libs in clojure.

To reiterate what was said earlier in this thread,
clojure.contrib.math extends basic math functionality to Clojure's
full numeric tower.  Specifically, clojure.contrib.math/abs will do
what you expect it should do.

This library is broken by the alpha releases of 1.3, but should work
fine with any of the officially released versions of Clojure.

-- 
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: Java gotchas now clojure gotchas

2010-11-02 Thread box
http://richhickey.github.com/clojure-contrib/math-api.html

i just found this.

i guess i wasn't paying attention because i didn't see it stated
before as a solution.

thank you.

On Nov 2, 10:45 pm, Mark Engelberg  wrote:
> On Tue, Nov 2, 2010 at 7:35 PM, box  wrote:
> > so, maybe this is a good time to start a clojure math library. or at
> > least have some warning when using math libs in clojure.
>
> To reiterate what was said earlier in this thread,
> clojure.contrib.math extends basic math functionality to Clojure's
> full numeric tower.  Specifically, clojure.contrib.math/abs will do
> what you expect it should do.
>
> This library is broken by the alpha releases of 1.3, but should work
> fine with any of the officially released versions of Clojure.

-- 
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: Java gotchas now clojure gotchas

2010-11-02 Thread Benny Tsai
The latest API is here:

http://clojure.github.com/clojure-contrib/math-api.html

On Nov 2, 8:50 pm, box  wrote:
> http://richhickey.github.com/clojure-contrib/math-api.html
>
> i just found this.
>
> i guess i wasn't paying attention because i didn't see it stated
> before as a solution.
>
> thank you.
>
> On Nov 2, 10:45 pm, Mark Engelberg  wrote:
>
>
>
>
>
>
>
> > On Tue, Nov 2, 2010 at 7:35 PM, box  wrote:
> > > so, maybe this is a good time to start a clojure math library. or at
> > > least have some warning when using math libs in clojure.
>
> > To reiterate what was said earlier in this thread,
> > clojure.contrib.math extends basic math functionality to Clojure's
> > full numeric tower.  Specifically, clojure.contrib.math/abs will do
> > what you expect it should do.
>
> > This library is broken by the alpha releases of 1.3, but should work
> > fine with any of the officially released versions of Clojure.

-- 
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: Java gotchas now clojure gotchas

2010-11-02 Thread Sean Corfield
On Tue, Nov 2, 2010 at 7:35 PM, box  wrote:
> sorry, i wrote too soon.
>
> (Math/abs (- Long/MIN_VALUE 1))
> java.lang.IllegalArgumentException: No matching method found: abs
> (NO_SOURCE_FILE:0)

On 1.3.0:

user=> (Math/abs (- Long/MIN_VALUE 1))
ArithmeticException integer overflow
clojure.lang.Numbers.throwIntOverflow (Numbers.java:1575)
-- 
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

-- 
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: REQUEST for feedback on http://clojure.org

2010-11-02 Thread ka
Hi Alex,  Can we have a section: Clojure - What's next? Dishes out
some details & links for the next versions and ideas.

-- 
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: From jetty to war?

2010-11-02 Thread Sean Corfield
On Tue, Nov 2, 2010 at 7:26 PM,   wrote:
> Doing the reverse is non sense (choosing a framework based on some hyped
> reviews and then use for every need).
...
> We cannot rewrite the whole universe in Clojure in one year. That's a fact.
> It's improving but will take some time to cover a number of areas.

We seem to be in a similar position. We have a large CFML web
application using frameworks that were decided before I joined the
project. I initially introduced some Scala to handle some
performance-critical XML transformations. Now I'm looking at the
long-term roadmap for what we need to continue to grow our business
and I'm prototyping sections of the application in Clojure but we're a
bit hamstrung by some restrictions in the frameworks that were chosen
(mainly the ColdBox MVC framework - CFML itself is not a problem) so
until I can break some dependency chains, I can't move Clojure into
production. But that will happen fairly soon (this past weekend I
rewrote one core low-level component in Clojure to get us a step
closer).

I expect we'll stay with CFML for application views - CFML is a great
HTML templating language - and we'll switch to a much simpler CFML MVC
framework to replace ColdBox (FW/1 - which I wrote and published last
year) so the controllers will stay in CFML. But the model will slowly
migrate entirely to Clojure over time I expect.
-- 
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

-- 
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: monads m-seq and m-lift

2010-11-02 Thread Sunil S Nandihalli
yea .. I was playing around and modified it in the due coarse.. :)
Sunil.

On Tue, Nov 2, 2010 at 5:28 PM, Konrad Hinsen wrote:

> On 02.11.2010, at 11:45, Sunil S Nandihalli wrote:
>
> > following is the extract from the monads example ...
>
> It looks quite modified and no longer returns pairs! Here is the original:
>
> (with-monad sequence-m
>   (defn pairs [xs]
>   ((m-lift 2 #(list %1 %2)) xs xs)))
>
> > ; Another way to define pairs is through the m-seq operation. It takes
> > ; a sequence of monadic values and returns a monadic value containing
> > ; the sequence of the underlying values, obtained from chaining together
> > ; from left to right the monadic values in the sequence.
> > (with-monad sequence-m
> >(defn pairs [xs]
> >   (m-seq (list xs xs
> >
> > can somebody help me understand what is happening in the second one .. ?
> > when would it be more appropriate to use m-seq instead of m-lift ..
>
> In most real-life cases you wouldn't have that choice, as m-lift and m-seq
> do very different things. It's just for making pairs that either one is
> fine.
>
> One example for the use of m-seq is given right after the pairs example:
>
> (with-monad sequence-m
>   (defn ntuples [n xs]
>  (m-seq (replicate n xs
>
> This is a generalization from pairs to n-tuples. You couldn't do this using
> m-lift applied to the list function because m-lift requires a fixed arity.
>
> Another example is given later in the example collection under "random
> number generators".
>
> Konrad.
>
> --
> 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: A question on distributed computing

2010-11-02 Thread Vivek Khurana


On Nov 2, 8:56 pm, Ken Wesson  wrote:

> That seems impossible assuming you don't trust the software running on the
> other node.
>

 It is not impossible. There are projects by Cornell .University,
jiff[1] and fabric[2] which have achieved the same. Jiff is
modification of java and fabric is based on jiff.Both languages run
inside JVM. So I was wondering if it is possible to add some kind of
access control policy on clojure code, via an extension or as language
feature ?

regards
Vivek

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


clojure-backtracking-monads .. can it emulate prolog?

2010-11-02 Thread Sunil S Nandihalli
Hello everybody,
 I was wondering if one can code in a way semantically similar to prolog
using the backtracking monads.. Has anybody tried it .. ? I did see the
tutorial which demonstrates backtracking monads ..
http://brehaut.net/blog/2010/ghosts_in_the_machine

it is nice .. I have to look at it a little more .. but  in the mean time ..
has anybody attempted to emulate a full-fledged prolog like system using the
monads.. I would love to hear your opinions and experiences.

Thanks,
Sunil.

-- 
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: StackOverflowError while using map inside a reduce

2010-11-02 Thread Meikel Brandmeyer
Hi,

On 3 Nov., 00:40, Rasmus Svensson  wrote:

> I think the problem is that this reduction will build an expression like this:
>
>     (map + ... (map + ... (map + ... (map + ...  levels>
>
> When clojure tries to realize an element of the resulting lazy seq,
> every level will result in a nested method call, which will eventually
> blow the stack.

Exactly. Much better than my try on an explanation. The doall in my
example realises each sequence as it is created by reduce. Hence this
deep nesting level of calls cannot happen.

Sincerely
Meikel

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