Re: (trace function)

2010-03-05 Thread Michał Marczyk
On 6 March 2010 05:57, TimDaly  wrote:
> Is there a (trace function) facility?
> One of my major debugging tools in Common Lisp is trace.
> I scanned the docs and did not see anything about it.
>
> Tim Daly

Check out clojure.contrib.trace.

Sincerely,
Michał

-- 
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: Leiningen, Clojure and libraries: what am I missing?

2010-03-05 Thread Phil Hagelberg
On Fri, Mar 5, 2010 at 3:56 PM, Brian Schlining  wrote:
>> (3) Managing proprietary libraries and API's that you are developing
>> or using...  Yes you can throw these into your own maven repo, but
>> then you also need to manage, configure and secure a server (when
>> working in a team).
>
> Actually, you can create a project local directory (e.g. myproject/lib or
> the more maven-ish myproject/src/lib) that acts as a maven repository and
> stick your dependencies in that directory. Then you can check it in to
> source control with your project.

If you're using git, this should be avoided. git is remarkably bad at
storing binary data. A number of projects I've been watching have made
this mistake, and they've all had to correct it by rewriting history
down the line, which is very awkward.

-Phil

-- 
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: Leiningen, Clojure and libraries: what am I missing?

2010-03-05 Thread Phil Hagelberg
On Fri, Mar 5, 2010 at 2:38 PM, Rick Moynihan  wrote:
> (1) getting ./config on the classpath so I can keep properties files, json
> config, whatever, separate from code and lib

This is actually what the resources/ directory is for.

> (2) having more than one kind of tests, in different dirs (e.g. specs,
> features) and having their classpaths work through lein.

It would be best if this could be handled by plugins rather than
specified in every project.clj. Currently the plugin framework doesn't
expose the hooks that would be needed for this, but it's definitely on
the short list for version 1.2.0.

> (3) Managing proprietary libraries and API's that you are developing
> or using...  Yes you can throw these into your own maven repo, but
> then you also need to manage, configure and secure a server (when
> working in a team).

I think it would be great if it were easy to run your own clojars
server. Not only for mirroring purposes (poor ato isn't going to be
able to eat the bandwidth bills forever) but also to deal with
situations like this.

But there may be other valid reasons that nobody has even encountered
yet, so I favour having total flexibility anyway.

-Phil

-- 
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: Windows: SLIME/Swank freezes on GUI-related input. (Was: Stumped - Java hangs when using Swing in Slime)

2010-03-05 Thread Phil Hagelberg
On Wed, Mar 3, 2010 at 2:03 PM, Rickard Bennekom  wrote:
> As of Clojure 1.1.0, the problem still persists.
> Apparently, it seems to be linked to Slime input that involves GUI-
> related system calls.
>
> On my system (Windows XP SP3, 32 Bit, JRE 1.6.0_18, JDK 1.6.0_12) it
> can be reproduced as follows:
> 1. Install Clojure Box 1.1.0 (January 5, 2010)
> 2. Start the Slime REPL and enter these lines:
> (use 'clojure.contrib.repl-utils)
> (javadoc "snafu")
> Result: The Slime REPL stalls and doesn't return a result.
> 4. Visit the *inferior-lisp* REPL buffer and place your cursor at the
> command line. Press 'return'.
> Result: The Slime thread continues and opens a Javadoc browser window.
> The Slime REPL returns.
>
> When the above lines are entered directly into the *inferior-lisp*
> buffer they get executed promptly and without errors.

Sorry, I don't have a Windows machine available to debug this problem.
Could you report it on the swank-clojure issue tracker so we can have
a record of it?

http://github.com/technomancy/swank-clojure/issues

Thanks,
Phil

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


(trace function)

2010-03-05 Thread TimDaly
Is there a (trace function) facility?
One of my major debugging tools in Common Lisp is trace.
I scanned the docs and did not see anything about it.

Tim Daly

-- 
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: Data manipulation question

2010-03-05 Thread Base
Wow - there are so many ways to skin a cat (and dog, bird, horse,
wolf, and pig!)

These are all great.  Thank you all so so much

James - I really appreciate walking me thru the methodology.  that is
a big help for those of us just gettting started (particularly when we
dont have much lisp experience)

Brendan - you use a bunch of functions i have never even heard of -
the partial one i have read about and not really understood how i
would use it.  It is great to see it used for an example that I can
dig into.

Thanks all again so very much.

On Mar 5, 6:55 pm, James Reeves  wrote:
> On Mar 5, 7:50 pm, James Reeves  wrote:
>
> >   (apply map merge
> >     (for [k (keys m)]
> >       (for [v (.split (m k) " ")]
> >         {k v}
>
> On reflection, I think this should be
>
> (apply map merge
>   (for [k (keys (first m))]
>     (for [v (.split (m k) " ")]
>       {k v})))
>
> Also, this assumes each map has the same keys, and each value has the
> same number of "words".
>
> - James

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


Re: Data manipulation question

2010-03-05 Thread Tayssir John Gabbour
Yeah, on further reflection, I was just about to delete my message, as
it annoyed me for a couple reasons. ;) The one you mentioned (which
limits its reusability), and also the fact that my function does the
mapping inside it.

All the best,
Tayssir


On Mar 6, 1:54 am, Brendan Ribera  wrote:
> Or if you want something that is agnostic about the structure of your input
> map, try this:
>
> (defn alter-map
>   [in-map]
>   (map (partial reduce merge)
>        (partition
>         (count (keys in-map))
>         (apply interleave
>                (map (fn [p]
>                       (map #(hash-map (first p) %)
>                            (seq (.split (fnext p) "\\s"
>                     in-map)
>
> ; Usage:
> (def data '( {:animal "dog cat bird" :sound "woof meow chirp"
> :number-of-feet "4 4 2"}
>                 {:animal "horse" :sound "ne" :number-of-feet "4"}
>                 {:animal "wolf pig" :sound "howl oink":number-of-feet "4
> 4"}))
> (pprint (map alter-map data))
>
> ;(({:number-of-feet "4", :sound "woof", :animal "dog"}
> ;  {:number-of-feet "4", :sound "meow", :animal "cat"}
> ;  {:number-of-feet "2", :sound "chirp", :animal "bird"})
> ; ({:number-of-feet "4", :sound "ne", :animal "horse"})
> ; ({:number-of-feet "4", :sound "howl", :animal "wolf"}
> ;  {:number-of-feet "4", :sound "oink", :animal "pig"}))
>
> Of course, there's probably a better way to write that.
>
> -Brendan
>
> On Fri, Mar 5, 2010 at 4:36 PM, Tayssir John Gabbour 
> wrote:
>
> > Hi Base,
>
> > Perhaps something like the following:
>
> > (defn normalize-creatures [creatures]
> >  (letfn [(split [str] (seq (.split str "\\s")))]
> >    (for [{:keys [animal sound number-of-feet]} creatures]
> >      (map (fn [a s n]
> >             {:animal a :sound s :number-of-feet n})
> >           (split animal) (split sound) (split number-of-feet)
>
> > ;; *foo* is the test data you mentioned
> > (normalize-creatures *foo*)
> > => (({:animal "dog"   :sound "woof"   :number-of-feet "4"}
> >      {:animal "cat"   :sound "meow"   :number-of-feet "4"}
> >     {:animal "bird"  :sound "chirp"  :number-of-feet "2"})
> >     ({:animal "horse" :sound "ne" :number-of-feet "4"})
> >     ({:animal "wolf"  :sound "howl"   :number-of-feet "4"}
> >     {:animal "pig"   :sound "oink"   :number-of-feet "4"}))
>
> > All the best,
> > Tayssir
>
> > On Mar 6, 1:07 am, Base  wrote:
> > > Hi all -
>
> > > I am trying to transofrm a data structure and am kind of stuck.
>
> > > I currently have a list of maps
>
> > > ( {:animal "dog cat bird" :sound "woof meow chirp" :number-of-feet "4
> > > 4 2"}
> > >   {:animal "horse" :sound "ne" :number-of-feet "4"}
> > >   {:animal "wolf pig" :sound "howl oink":number-of-feet "4 4"} )
>
> > > and want to trasform it to:
>
> > > (
> > >   ({:animal "dog" :sound "woof" :number-of-feet "4" }
> > >    {:animal "cat" :sound "meow" :number-of-feet "4"}
> > >    {:animal "bird" :sound "chirp" :number-of-feet "2"})
>
> > >   ({:animal "horse":sound "n" :number-of-feet "4"})
>
> > >   ({:animal "wolf" :sound "howl" :number-of-feet "4"}
> > >    {:animal "pig" :sound "oink" :number-of-feet "4"})
> > > )
>
> > > *spacing added for clarity*
>
> > > I have tried a few goofy attempts at this that were somewhat
> > > successful. but what I don't like is that most of my attempts (which i
> > > am kind of embarrassed to post) end up looking very un-clojuresque,
> > > and much more imperative looking...and we all know there is a better,
> > > more idiomatic way...
>
> > > any help is (as always) most appreciated.
>
> > > thanks
>
> > > base
>
> > --
> > 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: Data manipulation question

2010-03-05 Thread James Reeves
On Mar 5, 7:50 pm, James Reeves  wrote:
>   (apply map merge
>     (for [k (keys m)]
>       (for [v (.split (m k) " ")]
>         {k v}

On reflection, I think this should be

(apply map merge
  (for [k (keys (first m))]
(for [v (.split (m k) " ")]
  {k v})))

Also, this assumes each map has the same keys, and each value has the
same number of "words".

- James

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


Re: Data manipulation question

2010-03-05 Thread Brendan Ribera
Or if you want something that is agnostic about the structure of your input
map, try this:

(defn alter-map
  [in-map]
  (map (partial reduce merge)
   (partition
(count (keys in-map))
(apply interleave
   (map (fn [p]
  (map #(hash-map (first p) %)
   (seq (.split (fnext p) "\\s"
in-map)

; Usage:
(def data '( {:animal "dog cat bird" :sound "woof meow chirp"
:number-of-feet "4 4 2"}
{:animal "horse" :sound "ne" :number-of-feet "4"}
{:animal "wolf pig" :sound "howl oink":number-of-feet "4
4"}))
(pprint (map alter-map data))

;(({:number-of-feet "4", :sound "woof", :animal "dog"}
;  {:number-of-feet "4", :sound "meow", :animal "cat"}
;  {:number-of-feet "2", :sound "chirp", :animal "bird"})
; ({:number-of-feet "4", :sound "ne", :animal "horse"})
; ({:number-of-feet "4", :sound "howl", :animal "wolf"}
;  {:number-of-feet "4", :sound "oink", :animal "pig"}))

Of course, there's probably a better way to write that.

-Brendan

On Fri, Mar 5, 2010 at 4:36 PM, Tayssir John Gabbour wrote:

> Hi Base,
>
> Perhaps something like the following:
>
> (defn normalize-creatures [creatures]
>  (letfn [(split [str] (seq (.split str "\\s")))]
>(for [{:keys [animal sound number-of-feet]} creatures]
>  (map (fn [a s n]
> {:animal a :sound s :number-of-feet n})
>   (split animal) (split sound) (split number-of-feet)
>
>
> ;; *foo* is the test data you mentioned
> (normalize-creatures *foo*)
> => (({:animal "dog"   :sound "woof"   :number-of-feet "4"}
>  {:animal "cat"   :sound "meow"   :number-of-feet "4"}
> {:animal "bird"  :sound "chirp"  :number-of-feet "2"})
> ({:animal "horse" :sound "ne" :number-of-feet "4"})
> ({:animal "wolf"  :sound "howl"   :number-of-feet "4"}
> {:animal "pig"   :sound "oink"   :number-of-feet "4"}))
>
>
> All the best,
> Tayssir
>
>
>
>
> On Mar 6, 1:07 am, Base  wrote:
> > Hi all -
> >
> > I am trying to transofrm a data structure and am kind of stuck.
> >
> > I currently have a list of maps
> >
> > ( {:animal "dog cat bird" :sound "woof meow chirp" :number-of-feet "4
> > 4 2"}
> >   {:animal "horse" :sound "ne" :number-of-feet "4"}
> >   {:animal "wolf pig" :sound "howl oink":number-of-feet "4 4"} )
> >
> > and want to trasform it to:
> >
> > (
> >   ({:animal "dog" :sound "woof" :number-of-feet "4" }
> >{:animal "cat" :sound "meow" :number-of-feet "4"}
> >{:animal "bird" :sound "chirp" :number-of-feet "2"})
> >
> >   ({:animal "horse":sound "n" :number-of-feet "4"})
> >
> >   ({:animal "wolf" :sound "howl" :number-of-feet "4"}
> >{:animal "pig" :sound "oink" :number-of-feet "4"})
> > )
> >
> > *spacing added for clarity*
> >
> > I have tried a few goofy attempts at this that were somewhat
> > successful. but what I don't like is that most of my attempts (which i
> > am kind of embarrassed to post) end up looking very un-clojuresque,
> > and much more imperative looking...and we all know there is a better,
> > more idiomatic way...
> >
> > any help is (as always) most appreciated.
> >
> > thanks
> >
> > base
>
> --
> 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: Data manipulation question

2010-03-05 Thread Mike Meyer
On Fri, 5 Mar 2010 16:07:55 -0800 (PST)
Base  wrote:

> 
> Hi all -
> 
> I am trying to transofrm a data structure and am kind of stuck.
> 
> I currently have a list of maps
> 
> ( {:animal "dog cat bird" :sound "woof meow chirp" :number-of-feet "4
> 4 2"}
>   {:animal "horse" :sound "ne" :number-of-feet "4"}
>   {:animal "wolf pig" :sound "howl oink":number-of-feet "4 4"} )
> 
> and want to trasform it to:
> 
> (
>   ({:animal "dog" :sound "woof" :number-of-feet "4" }
>{:animal "cat" :sound "meow" :number-of-feet "4"}
>{:animal "bird" :sound "chirp" :number-of-feet "2"})
> 
>   ({:animal "horse":sound "n" :number-of-feet "4"})
> 
>   ({:animal "wolf" :sound "howl" :number-of-feet "4"}
>{:animal "pig" :sound "oink" :number-of-feet "4"})
> )

How about this?

(use '[clojure.contrib.str-utils2 :only [split]])
(defn cook [animals]
  (map (fn [{:keys [animal sound number-of-feet]}]
 (map #(hash-map :animal %1 :sound %2 :number-of-feet %3)
  (split animal #"\s")
  (split sound #"\s")
  (split number-of-feet #"\s")))
   animals))

which gives:

(({:number-of-feet "4", :sound "woof", :animal "dog"}
  {:number-of-feet "4", :sound "meow", :animal "cat"}
  {:number-of-feet "2", :sound "chirp", :animal "bird"})
 ({:number-of-feet "4", :sound "ne", :animal "horse"})
 ({:number-of-feet "4", :sound "howl", :animal "wolf"}
  {:number-of-feet "4", :sound "oink", :animal "pig"}))

-- 
Mike Meyer  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: Data manipulation question

2010-03-05 Thread James Reeves
When thinking about things functionally, it's useful to start from a
basic case, and then work upward.

For instance, we could start off by only transforming one key:

  (defn expand-map-key [m k]
(for [v (.split (m k) " ")]
  {k v}))

So:

  user=> (expand-map-key m :animal)
  ({:animal "dog"} {:animal "cat"} {:animal "bird"})

The problem now becomes: how can we apply expand-map-key to each
value, and then combine the results?

First apply the function to each value:

  (for [k (keys m)]
(expand-map-key m k))

This gets us something like:

  (({:animal "dog"} {:animal "cat"} {:animal "bird"})
   ({:sound "woof"} {:sound "meow} {:sound "chirp"})
   ...)

Next we need to merge the first entries into one map, the second
entries into another map, and so forth. This is usually known as
zipping. We can use apply and map for this:

  (apply map merge m)

So in total, your function will look like:

  (apply map merge
(for [k (keys m)]
  (expand-map key m k)))

Or perhaps we don't even need expand-map-key to be a separate
function:

  (apply map merge
(for [k (keys m)]
  (for [v (.split (m k) " ")]
{k v}

One word of warning: I don't currently have access to a Clojure
interpreter, so the above may be not be quite right. If it isn't
right, I hope the line of though of how I got there is of some use.

- James

On Mar 5, 7:07 pm, Base  wrote:
> Hi all -
>
> I am trying to transofrm a data structure and am kind of stuck.
>
> I currently have a list of maps
>
> ( {:animal "dog cat bird" :sound "woof meow chirp" :number-of-feet "4
> 4 2"}
>   {:animal "horse" :sound "ne" :number-of-feet "4"}
>   {:animal "wolf pig" :sound "howl oink":number-of-feet "4 4"} )
>
> and want to trasform it to:
>
> (
>   ({:animal "dog" :sound "woof" :number-of-feet "4" }
>    {:animal "cat" :sound "meow" :number-of-feet "4"}
>    {:animal "bird" :sound "chirp" :number-of-feet "2"})
>
>   ({:animal "horse":sound "n" :number-of-feet "4"})
>
>   ({:animal "wolf" :sound "howl" :number-of-feet "4"}
>    {:animal "pig" :sound "oink" :number-of-feet "4"})
> )
>
> *spacing added for clarity*
>
> I have tried a few goofy attempts at this that were somewhat
> successful. but what I don't like is that most of my attempts (which i
> am kind of embarrassed to post) end up looking very un-clojuresque,
> and much more imperative looking...and we all know there is a better,
> more idiomatic way...
>
> any help is (as always) most appreciated.
>
> thanks
>
> base

-- 
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: Data manipulation question

2010-03-05 Thread Tayssir John Gabbour
Hi Base,

Perhaps something like the following:

(defn normalize-creatures [creatures]
  (letfn [(split [str] (seq (.split str "\\s")))]
(for [{:keys [animal sound number-of-feet]} creatures]
  (map (fn [a s n]
 {:animal a :sound s :number-of-feet n})
   (split animal) (split sound) (split number-of-feet)


;; *foo* is the test data you mentioned
(normalize-creatures *foo*)
=> (({:animal "dog"   :sound "woof"   :number-of-feet "4"}
 {:animal "cat"   :sound "meow"   :number-of-feet "4"}
 {:animal "bird"  :sound "chirp"  :number-of-feet "2"})
({:animal "horse" :sound "ne" :number-of-feet "4"})
({:animal "wolf"  :sound "howl"   :number-of-feet "4"}
 {:animal "pig"   :sound "oink"   :number-of-feet "4"}))


All the best,
Tayssir




On Mar 6, 1:07 am, Base  wrote:
> Hi all -
>
> I am trying to transofrm a data structure and am kind of stuck.
>
> I currently have a list of maps
>
> ( {:animal "dog cat bird" :sound "woof meow chirp" :number-of-feet "4
> 4 2"}
>   {:animal "horse" :sound "ne" :number-of-feet "4"}
>   {:animal "wolf pig" :sound "howl oink":number-of-feet "4 4"} )
>
> and want to trasform it to:
>
> (
>   ({:animal "dog" :sound "woof" :number-of-feet "4" }
>{:animal "cat" :sound "meow" :number-of-feet "4"}
>{:animal "bird" :sound "chirp" :number-of-feet "2"})
>
>   ({:animal "horse":sound "n" :number-of-feet "4"})
>
>   ({:animal "wolf" :sound "howl" :number-of-feet "4"}
>{:animal "pig" :sound "oink" :number-of-feet "4"})
> )
>
> *spacing added for clarity*
>
> I have tried a few goofy attempts at this that were somewhat
> successful. but what I don't like is that most of my attempts (which i
> am kind of embarrassed to post) end up looking very un-clojuresque,
> and much more imperative looking...and we all know there is a better,
> more idiomatic way...
>
> any help is (as always) most appreciated.
>
> thanks
>
> base

-- 
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: Writing a put-if-absent operation a la Java's ConcurrentMap

2010-03-05 Thread Steven E. Harris
Stuart Halloway  writes:

> It is mort important to focus on the semantics (commutative or last-
> one-wins) than the implementation details.

That's a tough pill to swallow. I understand the benefits of specifying
behavior to allow flexibility in an implementation, but here I think the
behavior is still underspecified. Or maybe it's just hasn't been
described well with enough comparative examples to allow it to sink
in. It feels like some of our discussion is still operating on
superstition.

> If you care about ordering, stick to alter. If you aren't sure, stick
> to alter.

Got it.

> I find a counter to be a useful example. If the purpose of the counter
> is to keep a total count of something that happened, then you can use
> commute.

This is true because even if commute runs once and increments the
counter, but then runs into a conflict, the commute operation will be
run again on a fresher value until it finally succeeds in committing
without conflict. This is similar to a manually-written atomic increment
operation using CAS in a spinning loop:

  for (int cur = val.get();
   !val.compareAndSet(cur, cur + 1);
   cur = val.get())
;

Or:

  int cur;
  do
  {
cur = val.get()
  }
  while (!val.compareAndSet(cur, cur + 1));

> But if the counter is used as an id generator within the transaction,
> then order matters and you have to use alter.

The key there is "within the transaction", because if you used commute,
the commuted operation could be repeated upon conflict at the end of the
transaction and wind up succeeding, albeit with a different resulting
value than the one observed within the transaction, right?

-- 
Steven E. Harris

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


Data manipulation question

2010-03-05 Thread Base

Hi all -

I am trying to transofrm a data structure and am kind of stuck.

I currently have a list of maps

( {:animal "dog cat bird" :sound "woof meow chirp" :number-of-feet "4
4 2"}
  {:animal "horse" :sound "ne" :number-of-feet "4"}
  {:animal "wolf pig" :sound "howl oink":number-of-feet "4 4"} )

and want to trasform it to:

(
  ({:animal "dog" :sound "woof" :number-of-feet "4" }
   {:animal "cat" :sound "meow" :number-of-feet "4"}
   {:animal "bird" :sound "chirp" :number-of-feet "2"})

  ({:animal "horse":sound "n" :number-of-feet "4"})

  ({:animal "wolf" :sound "howl" :number-of-feet "4"}
   {:animal "pig" :sound "oink" :number-of-feet "4"})
)

*spacing added for clarity*

I have tried a few goofy attempts at this that were somewhat
successful. but what I don't like is that most of my attempts (which i
am kind of embarrassed to post) end up looking very un-clojuresque,
and much more imperative looking...and we all know there is a better,
more idiomatic way...

any help is (as always) most appreciated.

thanks

base

-- 
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: Leiningen, Clojure and libraries: what am I missing?

2010-03-05 Thread Brian Schlining
>
>
> As I'm one of the people that's requested this feature... I'll add my
> reason too:
>
> (3) Managing proprietary libraries and API's that you are developing
> or using...  Yes you can throw these into your own maven repo, but
> then you also need to manage, configure and secure a server (when
> working in a team).
>

Actually, you can create a project local directory (e.g. myproject/lib or
the more maven-ish myproject/src/lib) that acts as a maven repository and
stick your dependencies in that directory. Then you can check it in to
source control with your project. See
http://stubbisms.wordpress.com/2008/08/28/maven-is-to-ant-as-a-nail-gun-is-to-hammer-and-nails-you-need-to-move-on/
 and
http://techdiary.peterbecker.de/2009/03/letting-maven-use-local-libraries.html
for
more details.

Cheers

-- 
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Brian Schlining
bschlin...@gmail.com

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

Re: Some basic guidance to designing functional vs. state parts of app

2010-03-05 Thread Rick Moynihan
On 5 March 2010 17:56, Mark Engelberg  wrote:
>
> On Wed, Mar 3, 2010 at 5:20 PM, Rick Moynihan 
> wrote:
>>
>> If you have a single value representing the whole world, then it seems
>> that protecting it with an atom would be the simplest and most
>> idiomatic solution.
>
>> For a single value there seems to be little reason to adopt refs, ...
>
> I disagree.  The problem with atoms is that updating an atom is a
> side-effect that cannot (typically) participate safely in a transaction.  It
> might be retried, so if for example, you want to increment the contents of
> an atom, it might get incremented multiple times which is generally not okay
> (if you're storing something in a cache, then a retry might be okay).
>
> If you make a design decision to use an atom, you are effectively committing
> to never, ever being able to update that atom within a transaction.

This is a good point, one that I hadn't considered and arguably also
non-obvious!  Though all is not necessarily lost when state you don't
control is held in an atom, as you can wrap it inside an agent which
will be co-ordinated with the STM, ensuring safe modification in the
event of retries.

> refs can do everything atoms can do and more.  They are slightly slower, 
> perhaps, but much safer.  So
> unless you have an explicit performance reason to use atoms and have thought 
> through the
> implications, the simplest design choice is to prefer refs.

My simple (uncontended) tests seem to indicate that atoms are about 4x
faster than refs (though I'd love to see a more comprehensive
benchmark).  Regardless I'll certainly be more cautious about using
atoms in the future, as refs are without doubt more composable.

R.

-- 
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: Leiningen, Clojure and libraries: what am I missing?

2010-03-05 Thread Rick Moynihan
On 5 March 2010 18:49, Stuart Halloway  wrote:
>>> (2) Improve the project structure imposed by lein, if it is broken in
>>> some
>>> specific way. (Maybe add a well-known config file for adding elements to
>>> the
>>> classpath?)
>>
>> People have asked for this, but I have yet to hear a good use case for
>> it. Mostly it's been requested by people who don't realize how easy it
>> is to push their own jars to clojars. But if someone wants to
>> implement it I will not refuse the patch.
>
> I agree that lein+clojars is good enough for lib dependencies. My two use
> cases so far are places where the classpath needs to point to something
> other than outside libs:
>
> (1) getting ./config on the classpath so I can keep properties files, json
> config, whatever, separate from code and lib
>
> (2) having more than one kind of tests, in different dirs (e.g. specs,
> features) and having their classpaths work through lein.

As I'm one of the people that's requested this feature... I'll add my
reason too:

(3) Managing proprietary libraries and API's that you are developing
or using...  Yes you can throw these into your own maven repo, but
then you also need to manage, configure and secure a server (when
working in a team).

R.

-- 
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: Some basic guidance to designing functional vs. state parts of app

2010-03-05 Thread Mark Engelberg
When you increment the contents of an atom, for example, it happens
immediately.  If it is inside a transaction, and the transaction retries,
the contents will be incremented multiple times.  Refs, on the other hand,
retry from the initial state at the beginning of the transaction, so as long
as there are no external side effects, you get the illusion that it only
happened once.  Essentially, changing an atom is like other side effects
(e.g., display or file output), and therefore cannot be safely used inside a
transaction.

On Fri, Mar 5, 2010 at 1:08 PM, eyeris  wrote:

> I don't follow your logic. Modifications of refs within a transaction
> retry too.
>
>

-- 
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: Some basic guidance to designing functional vs. state parts of app

2010-03-05 Thread David Nolen
On Fri, Mar 5, 2010 at 4:08 PM, eyeris  wrote:

> I don't follow your logic. Modifications of refs within a transaction
> retry too.
>

He's saying that atoms don't participate in the STM. If an atom depends on
the value of some refs, your program might be put into an inconsistent state
if the transaction is retried and you're changing the value of the atom in
the transaction.

In general using an atom means you're sure that you'll never want to perform
an atomic change of both it and some other mutable reference in your
program.

That's my understanding of it anyway.

David

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

Re: Some basic guidance to designing functional vs. state parts of app

2010-03-05 Thread eyeris
I don't follow your logic. Modifications of refs within a transaction
retry too.


On Mar 5, 11:56 am, Mark Engelberg  wrote:
> On Wed, Mar 3, 2010 at 5:20 PM, Rick Moynihan wrote:
>
>
>
> > If you have a single value representing the whole world, then it seems
> > that protecting it with an atom would be the simplest and most
> > idiomatic solution.
>
> ...
>
> > For a single value
> > there seems to be little reason to adopt refs, ...
>
> I disagree.  The problem with atoms is that updating an atom is a
> side-effect that cannot (typically) participate safely in a transaction.  It
> might be retried, so if for example, you want to increment the contents of
> an atom, it might get incremented multiple times which is generally not okay
> (if you're storing something in a cache, then a retry might be okay).
>
> If you make a design decision to use an atom, you are effectively committing
> to never, ever being able to update that atom within a transaction.
>
> In my opinion, this has major implications and is a decision that should not
> be taken lightly.  In a language like Clojure, we should strive to write
> things that are as side-effect free as possible, so they can participate in
> transactions.  Using atoms runs the risk of creating headaches later, so
> unless you're 100% sure the semantics of your program won't change if they
> are retried, or if you're 100% sure you'll never want to change the contents
> of the atom as part of a sequence of logic involving setting other refs,
> don't use atoms.
>
> refs can do everything atoms can do and more.  They are slightly slower,
> perhaps, but much safer.  So unless you have an explicit performance reason
> to use atoms and have thought through the implications, the simplest design
> choice is to prefer refs.

-- 
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: Leiningen, Clojure and libraries: what am I missing?

2010-03-05 Thread Neill Alexander
I'll add my 2 cents worth. I've come from a Java development
background to Clojure. A couple of years ago our company migrated from
Ant to Maven. At first I really really hated it. I found it difficult
to make it do what I wanted it to do. Nowadays, though, it is my build
tool of choice.

The turning point was when I realized that the key to using Maven is
understanding the Maven model - understanding how Maven wants to
build. You don't tell Maven what to do. You just put the files in the
places Maven expects, and Maven then _knows_ what to do. My rule of
thumb is: if I'm spending a lot of time tweaking configuration and
overriding defaults in the pom file then I'm probably doing it wrong.

When I started programming in Clojure I immediately looked for a Maven
plugin to build Clojure projects. The first project I worked on I did
using the plugin. For my next Clojure project I decided to give
Leiningen a spin. Initially I was very impressed. It was easy to get a
project up and running, easy to build, easy to run tests, easy to run
a swank server etc. For a couple of weeks I was very happy. But.

I finally hit a point where Leiningen was no longer working for me. My
current project has a Swing GUI, built using Matisse (the Netbeans GUI
builder). I couldn't find a way to build the Swing portion and the
Clojure portion together using Leiningen. I also couldn't find a way
to divide my project up into different sub-modules with one build
(maybe I'm guilty of trying to use Leiningen like I use Maven). In any
case, I ended up converting the project to use Maven.

Maven has a steep learning curve, but once you get it, it's incredibly
powerful.

"The philosophy of Tai Chi Chuan is that if one uses hardness to
resist violent force, then both sides are certain to be injured at
least to some degree. Such injury, according to tai chi theory, is a
natural consequence of meeting brute force with brute force. Instead,
students are taught not to directly fight or resist an incoming force,
but to meet it in softness and follow its motion while remaining in
physical contact until the incoming force of attack exhausts itself or
can be safely redirected, meeting yang with yin." (http://
en.wikipedia.org/wiki/Tai_chi_chuan)

If you fight with Maven, you will lose. If you meet it in softness and
follow its motion you will attain build enlightenment...

;-)

FInally, I agree with Stuart that polyglot Maven could / should be the
way forward. I don't really wrestle with pom files much manually
anyway since Netbeans does a very good job of automatically updating
them. But Leiningen has given me a taste of writing build files in
Clojure, so I will definitely be investigating the polyglot option
soon.

To learn more about Maven I would recommend
http://www.sonatype.com/books/mvnref-book/reference/public-book.html
and http://www.sonatype.com/books/mvnex-book/reference/public-book.html

On Mar 5, 6:01 pm, James Reeves  wrote:
> On Mar 5, 11:17 am, Stuart Sierra  wrote:
>
> > Maven supports a wide range of development/deployment models already.
> > Whatever you want to do (including compile/test/run Clojure code)
> > there's a plugin for that.  Why recreate all this functionality in
> > Leiningen?
>
> Most of the time, I won't need the wide range of functionality that
> Maven supports. For the most common tasks, such as compiling and
> packaging, Leiningen is the better build tool. It's conceptually
> simpler, more understandable, and easier to extend. I'd rather use a
> build tool that covers 80% of tasks well, than a tool that covers 95%
> poorly.
>
> - James

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


Re: Leiningen, Clojure and libraries: what am I missing?

2010-03-05 Thread Stuart Halloway
(2) Improve the project structure imposed by lein, if it is broken  
in some
specific way. (Maybe add a well-known config file for adding  
elements to the

classpath?)


People have asked for this, but I have yet to hear a good use case for
it. Mostly it's been requested by people who don't realize how easy it
is to push their own jars to clojars. But if someone wants to
implement it I will not refuse the patch.


I agree that lein+clojars is good enough for lib dependencies. My two  
use cases so far are places where the classpath needs to point to  
something other than outside libs:


(1) getting ./config on the classpath so I can keep properties files,  
json config, whatever, separate from code and lib


(2) having more than one kind of tests, in different dirs (e.g. specs,  
features) and having their classpaths work through lein.


Stu

--
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: Leiningen, Clojure and libraries: what am I missing?

2010-03-05 Thread Phil Hagelberg
On Thu, Mar 4, 2010 at 5:52 AM, Stuart Halloway
 wrote:
> Some needs I see:
> (0) More point releases of key libs (or some other solution to the snapshots
> problem)

Agreed.

> (1) Unify around the project structure imposed by lein, and/or

Yes, but it should be noted this isn't really the "leiningen" project
structure; it has been the conventional Clojure layout in the
community from long before leiningen was released.

> (2) Improve the project structure imposed by lein, if it is broken in some
> specific way. (Maybe add a well-known config file for adding elements to the
> classpath?)

People have asked for this, but I have yet to hear a good use case for
it. Mostly it's been requested by people who don't realize how easy it
is to push their own jars to clojars. But if someone wants to
implement it I will not refuse the patch.

> (3) "lein deps" (or some other task) to clean up old jars. Right now I am
> deleting them by hand from the lib directory. (Is this already solved?)

Should be able to "lein clean". =)

-Phil

-- 
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: Leiningen, Clojure and libraries: what am I missing?

2010-03-05 Thread James Reeves
On Mar 5, 11:17 am, Stuart Sierra  wrote:
> Maven supports a wide range of development/deployment models already.
> Whatever you want to do (including compile/test/run Clojure code)
> there's a plugin for that.  Why recreate all this functionality in
> Leiningen?

Most of the time, I won't need the wide range of functionality that
Maven supports. For the most common tasks, such as compiling and
packaging, Leiningen is the better build tool. It's conceptually
simpler, more understandable, and easier to extend. I'd rather use a
build tool that covers 80% of tasks well, than a tool that covers 95%
poorly.

- James

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


Re: Some basic guidance to designing functional vs. state parts of app

2010-03-05 Thread Mark Engelberg
On Wed, Mar 3, 2010 at 5:20 PM, Rick Moynihan wrote:

>
> If you have a single value representing the whole world, then it seems
> that protecting it with an atom would be the simplest and most
> idiomatic solution.

...

> For a single value
> there seems to be little reason to adopt refs, ...


I disagree.  The problem with atoms is that updating an atom is a
side-effect that cannot (typically) participate safely in a transaction.  It
might be retried, so if for example, you want to increment the contents of
an atom, it might get incremented multiple times which is generally not okay
(if you're storing something in a cache, then a retry might be okay).

If you make a design decision to use an atom, you are effectively committing
to never, ever being able to update that atom within a transaction.

In my opinion, this has major implications and is a decision that should not
be taken lightly.  In a language like Clojure, we should strive to write
things that are as side-effect free as possible, so they can participate in
transactions.  Using atoms runs the risk of creating headaches later, so
unless you're 100% sure the semantics of your program won't change if they
are retried, or if you're 100% sure you'll never want to change the contents
of the atom as part of a sequence of logic involving setting other refs,
don't use atoms.

refs can do everything atoms can do and more.  They are slightly slower,
perhaps, but much safer.  So unless you have an explicit performance reason
to use atoms and have thought through the implications, the simplest design
choice is to prefer refs.

-- 
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: map not working in loop

2010-03-05 Thread Richard Lyman
On Fri, Mar 5, 2010 at 7:31 AM, Glen Rubin  wrote:

> The problem was that coll was being called as a fcn as others pointed
> out.  You say the function being supplied as my second parameter does
> not modify my third parameter?
>
> (defn pyt [coll]
>  (loop [b (rest coll)]
>   (map  #(* % %) b)))
>
> I am taking the third parameter and squaring it.  Isn't that a
> modification?
>
> thx everybody for the help!
>
> On Mar 5, 7:15 am, Richard Lyman  wrote:
> > On Fri, Mar 5, 2010 at 7:05 AM, Glen Rubin  wrote:
> > > The following code does not work, when using (range 1 5) as coll
> > > input:
> >
> > > (defn pyt [coll]
> > >  (loop [b (rest (coll))]
> >
> > >(map  #(* % %) b)))
> >
> > > The real code was more complicated, but I refined it to its simplest
> > > form while still producing the error.   (map f coll)  looks correct to
> > > me??  :(
> >
> > I'm not sure what effect you're looking for, but...
> >
> > Don't forget, map is lazy and the function you've supplied as the second
> > parameter doesn't modify b.
> >
> > Depending on what outcome you're looking for, you might want to wrap the
> > call to map in a call to doall, or modify b and your second parameter so
> > that b is changed.
> >
> > -Rich
>

Sorry for the miscommunication.

Clojure 1.0.0-
user=> (def b '(1 2 3))
#'user/b
user=> b
(1 2 3)
user=> (map #(* % %) b)
(1 4 9)
user=> b
(1 2 3)
user=>

I didn't know if "the real code" used b inside the let after the call to map
and had expected it to be different.

-Rich

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

assembla: How to be able to comment on tickets?

2010-03-05 Thread jpraher
Hi all,

I am a watcher on space Clojure and able to create tickets.
Unfortunately I am not able to add a comment to a ticket or try to
promote my role in this space.

What should I do?
Googling for this did not do the trick for me.

Thanks in advance.
Jakob

-- 
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: Leiningen, Clojure and libraries: what am I missing?

2010-03-05 Thread Ramakrishnan Muthukrishnan
On Fri, Mar 5, 2010 at 9:47 PM, Stuart Sierra
 wrote:
>
> Yes, the Maven configuration model isn't pretty, but if you follow the
> conventions it works.  Polyglot Maven will obviate the need to write

I didn't know about Polyglot. Thanks. Looks like a very nice tool.

  

-- 
  Ramakrishnan

-- 
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: Leiningen, Clojure and libraries: what am I missing?

2010-03-05 Thread Stuart Sierra
On Mar 4, 1:59 pm, David Nolen  wrote:
> If Lein evolves to to handle dependencies of dependencies and intelligently
> generates the classpath based on these dependencies (instead of copying
> files around) what advantage does Maven really have?

Maven supports a wide range of development/deployment models already.
Whatever you want to do (including compile/test/run Clojure code)
there's a plugin for that.  Why recreate all this functionality in
Leiningen?

Yes, the Maven configuration model isn't pretty, but if you follow the
conventions it works.  Polyglot Maven will obviate the need to write
XML.  But frankly, I don't mind a little XML if it gets the job done.

Basically, I'm skeptical that any tool developed exclusively by/for
the Clojure community could ever achieve the scope and utility of a
tool used by thousands of people and companies.  We're a small
community, we can't do it all alone.

-SS

-- 
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: map not working in loop

2010-03-05 Thread Glen Rubin
The problem was that coll was being called as a fcn as others pointed
out.  You say the function being supplied as my second parameter does
not modify my third parameter?

(defn pyt [coll]
 (loop [b (rest coll)]
   (map  #(* % %) b)))

I am taking the third parameter and squaring it.  Isn't that a
modification?

thx everybody for the help!

On Mar 5, 7:15 am, Richard Lyman  wrote:
> On Fri, Mar 5, 2010 at 7:05 AM, Glen Rubin  wrote:
> > The following code does not work, when using (range 1 5) as coll
> > input:
>
> > (defn pyt [coll]
> >  (loop [b (rest (coll))]
>
> >    (map  #(* % %) b)))
>
> > The real code was more complicated, but I refined it to its simplest
> > form while still producing the error.   (map f coll)  looks correct to
> > me??  :(
>
> I'm not sure what effect you're looking for, but...
>
> Don't forget, map is lazy and the function you've supplied as the second
> parameter doesn't modify b.
>
> Depending on what outcome you're looking for, you might want to wrap the
> call to map in a call to doall, or modify b and your second parameter so
> that b is changed.
>
> -Rich

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


Re: map not working in loop

2010-03-05 Thread Krešimir Šojat
Hi,

On Mar 5, 3:05 pm, Glen Rubin  wrote:
> The following code does not work, when using (range 1 5) as coll
> input:

Remove the extra () around the coll in (rest (coll)) expression.

--
Krešimir Šojat

-- 
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: map not working in loop

2010-03-05 Thread Richard Lyman
On Fri, Mar 5, 2010 at 7:05 AM, Glen Rubin  wrote:

> The following code does not work, when using (range 1 5) as coll
> input:
>
>
> (defn pyt [coll]
>  (loop [b (rest (coll))]
>
>(map  #(* % %) b)))
>
>
> The real code was more complicated, but I refined it to its simplest
> form while still producing the error.   (map f coll)  looks correct to
> me??  :(
>

I'm not sure what effect you're looking for, but...

Don't forget, map is lazy and the function you've supplied as the second
parameter doesn't modify b.

Depending on what outcome you're looking for, you might want to wrap the
call to map in a call to doall, or modify b and your second parameter so
that b is changed.

-Rich

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

Re: map not working in loop

2010-03-05 Thread Edmund Jackson
I think you're calling coll as a function. Try this.

(defn pyt [coll]
 (loop [b (rest coll)]
   (map  #(* % %) b)))

Edmund

On 5 Mar 2010, at 14:13, Meikel Brandmeyer wrote:

> Hi,
> 
> On Mar 5, 3:05 pm, Glen Rubin  wrote:
> 
>> The following code does not work, when using (range 1 5) as coll
>> input:
>> 
>> (defn pyt [coll]
>>   (loop [b (rest (coll))]
>> 
>> (map  #(* % %) b)))
>> 
>> The real code was more complicated, but I refined it to its simplest
>> form while still producing the error.   (map f coll)  looks correct to
>> me??  :(
> 
> "Does not work" is quite vague. I'd say the code snippet does not
> work, because you call coll like a function, which wont work because
> it is a sequence. Try (rest coll). (Note: no parens around coll)
> 
> What is the exact error you get?
> 
> 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

  Edmund

"Do it with love, l-o-v-e"
MJ




-- 
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: map not working in loop

2010-03-05 Thread Meikel Brandmeyer
Hi,

On Mar 5, 3:05 pm, Glen Rubin  wrote:

> The following code does not work, when using (range 1 5) as coll
> input:
>
> (defn pyt [coll]
>   (loop [b (rest (coll))]
>
>     (map  #(* % %) b)))
>
> The real code was more complicated, but I refined it to its simplest
> form while still producing the error.   (map f coll)  looks correct to
> me??  :(

"Does not work" is quite vague. I'd say the code snippet does not
work, because you call coll like a function, which wont work because
it is a sequence. Try (rest coll). (Note: no parens around coll)

What is the exact error you get?

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


map not working in loop

2010-03-05 Thread Glen Rubin
The following code does not work, when using (range 1 5) as coll
input:


(defn pyt [coll]
  (loop [b (rest (coll))]

(map  #(* % %) b)))


The real code was more complicated, but I refined it to its simplest
form while still producing the error.   (map f coll)  looks correct to
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: Some basic guidance to designing functional vs. state parts of app

2010-03-05 Thread Stuart Halloway
Someone could (and hopefully will) write a multi-hundred-page book  
exclusively on Clojure's approach to state. I simply didn't have  
enough space while overviewing the whole language.


If you want an identity that is isolated from whatever else is (or  
might in the future) happen in your app, prefer atoms. However, if it  
does (or will) coordinate with other identities, use refs.


I guess switching between these should be a feature of the Clojure  
Refactoring IDE. :-)


Stu


For a single value
there seems to be little reason to adopt refs, though I've often
wondered why Stuart Halloway's book gives an example updating a  
single

ref of messages for a chat application.


I seem to recall atoms being the last reference type to be  
introduced. They might not have existed when Stuart was writing.


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


clojure.contrib.sql : how not to use a transaction ?

2010-03-05 Thread rdunklau
Hello.

I'm trying to use clojure.contrib.sql to set up my database (on
postgresql)
However, i'm running into some problems : I did not find a way to
execute a (prepared) statement outside a transaction WITHOUT returning
the results.

What I tried so far:

(def mystatement "CREATE DATABASE mydb WITH TEMPLATE = template0
ENCODING = 'UTF8' LC_COLLATE = 'fr_FR.utf8' LC_CTYPE = 'fr_FR.utf8';")

(do-commands mystatement)

--> PSQLException:
 Message: ERROR: CREATE DATABASE cannot run inside a transaction block


(with-query-results rs mystatement)

-->org.postgresql.util.PSQLException: No results were returned by the
query.

So, is there any function which exposes the
PreparedStatement.executeUpdate() method directly ?

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


Re: Leiningen, Clojure and libraries: what am I missing?

2010-03-05 Thread Laurent PETIT
2010/3/5 Meikel Brandmeyer :
> Hi,
>
> On Mar 5, 1:03 am, Felix Breuer  wrote:
>
>> I agree that Windows is a second class citizen as far as clojure
>> tools go.
>
> Oh please stop that. I have a stable setup of Gradle + Clojuresque +
> VimClojure on Windows.

Furthermore, all java tools play well on windows, so using ant, maven,
will work just as well on windows and on linux, mac, etc.

And you also have the Eclipse plugin for Clojure, the netbeans plugin
for clojure, the IntelliJ IDEA plugin for clojure, which work on
windows too !

> Granted setting up VimClojure on Windows is
> tricky due to Vim and Windows specifics, but it's doable. However the
> Gradle + Clojuresque part is as easy and trivial as it can get. And
> this setup survived already a few updates of the different components
> without blowing up a single time. I type "gradle runServer" in the
> morning and get a running Jetty/Nailgun combination for dynamic
> development with VimClojure - without thinking a single time about the
> classpath. Which actually consists of several checked out other
> projects (enlive, ring, fleetdb, ...). They were modified non-
> intrusively to use clojuresque instead of maven/ant/lein/whatever as
> build system. It checks the interdependencies and rebuilds the
> required jars if necessary. A change in a dependency is immediately
> picked up. If necessary, I can fix a known-to-work version in my local
> repository with a few commands.
>
> All without virtualbox, VMWare or whatever. So if one tool doesn't
> fill your need, then choose another.
>
> I apologise for sounding a little harsh.
>
> 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

-- 
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: Leiningen, Clojure and libraries: what am I missing?

2010-03-05 Thread Martin DeMello
On Fri, Mar 5, 2010 at 12:34 PM, Meikel Brandmeyer  wrote:
> Hi,
>
> On Mar 5, 7:47 am, Martin DeMello  wrote:
>
>> One huge drawback I've found with clojure (which it doubtless
>> inherited from Java) is that you need an actual jarfile in your
>> classpath, not just the directory containing the jarfile.
>
> With newer Java versions you can specify wildcards. java -cp lib/
> \* ... will pick up everything in lib for the classpath.

Neat! Never knew that. So now it *is* possible to have a standard
clojure lib directory the way ruby has its gems directory or python
its site-libs.

martin

-- 
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: mutable half-edge data structures to immutable languages

2010-03-05 Thread Konrad Hinsen

On 5 Mar 2010, at 00:54, strattonbrazil wrote:


I think I can generalize the question into a graph question.  I have
three kinds structures that link together as I described.  How could a
delete and add new connections efficiently and intuitively?


You might find this article helpful:

http://www.cs.ucl.ac.uk/teaching/3C11/graph.pdf

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