Re: JDBC Timezone Issue

2012-08-09 Thread Jestine Paul
 Given that the patch just 
 provides a way for users to tell the library these columns are 
 special, it seems like you might just as well map a column adjustment 
 function over the result set yourself? It feels very clunky. 

The JDBC library requires us to treat these columns special. If we don't 
call the right getter function, then it will return the wrong Date 
instance. It is very clunky to use Date instances created in the wrong 
timezone.

 It also looks like it can reorder columns.

These special columns will only get inserted into the regular map at the 
end, but after all, it's a regular map and this will only happen if we make 
these columns special by passing in the optional parameter. The patch is 
fully backward compatible.  

 Overall, I still think this problem arises because you're not 
 following best practices for managing timezones which is to have all 
 your servers operating on the same timezone and using NTP to sync 
 times

What if I am using the JDBC library in a client software instead of being 
in the server?


On Tuesday, 31 July 2012 12:22:23 UTC+8, Sean Corfield wrote:

 On Fri, Jul 27, 2012 at 10:42 AM, Jestine Paul 
 jestin...@gmail.comjavascript: 
 wrote: 
  I have raised a JIRA issue (JDBC-35) regarding the timezones returned 
 from 
  the ResultSet getter method. 
  http://dev.clojure.org/jira/browse/JDBC-35 

 I'm a bit surprised no one has responded to this. Maybe no one else is 
 having this issue? I'd love to see some feedback on this. 

  I have also attached a patch to this issue. 
  
 http://dev.clojure.org/jira/secure/attachment/11394/resultset-timezone.diff 

 I hope there are better solutions suggested. Given that the patch just 
 provides a way for users to tell the library these columns are 
 special, it seems like you might just as well map a column adjustment 
 function over the result set yourself? It feels very clunky. 

 It also looks like it can reorder columns. java.jdbc used to use 
 structmap to preserve column order but now uses regular maps - 
 although small maps use an array map which does in fact preserve 
 column ordering for reasonable numbers of columns. That didn't seem to 
 be particularly important for users at the time but gratuitous 
 partitioning of columns seems unnecessary... 

 Overall, I still think this problem arises because you're not 
 following best practices for managing timezones which is to have all 
 your servers operating on the same timezone and using NTP to sync 
 times - but I really do want to hear some feedback from other 
 java.jdbc users (which is why I haven't just closed the ticket). 
 -- 
 Sean A Corfield -- (904) 302-SEAN 
 An Architect's View -- http://corfield.org/ 
 World Singles, LLC. -- http://worldsingles.com/ 

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


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

Re: ANN lein-expectations 0.0.7

2012-08-09 Thread Jay Fields
If you like Midje you should probably stick with it. The two libraries were
designed with very different goals in mind. Midje is much more polished and
targeted adoption early on. expectations was created for testing the
application I was working on, made available on github, but never really
promoted. If it suits your testing style, you should love it. If not,
you'll likely hate it - it's very opinionated.

Check out the github page and look at the success examples that are linked.
That will cost you less than 5 minutes, and should give you all the
information you need to decide which you prefer.

Cheers, Jay

Sent from my iPhone

On Aug 8, 2012, at 9:28 PM, keeds akee...@gmail.com wrote:

Silly question but how is Expectations better or different from Midje?
I'm just starting out with Midje and was just wondering?

Thanks,
Andrew

On Monday, 6 August 2012 19:43:18 UTC+1, Sean Corfield wrote:

 lein-expectations - the plugin for running Jay Fields' awesome
 Expectations testing library - has been updated for Leiningen 2.0.

 If you are using Leiningen 1.x, continue to use lein-expectations 0.0.5.

 If you are on Leiningen 2.x, you should use lein-expectations 0.0.7 so
 that exit on test failure is handled correctly.

 0.0.6 added a partial fix for exit codes in Leiningen 2.0 but it
 didn't work properly with with-profile. After discussions with Phil
 H about exit status codes, the logic was changed / simplified for the
 0.0.7 release.
 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/
 World Singles, LLC. -- http://worldsingles.com/

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

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

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To 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

drawing a chess-board with seesaw ...

2012-08-09 Thread Jim - FooBar();

Hey all,

Spent most of yesterday trying to draw a chessboard on a paintable 
canvas, however I'm stuck after drawing the lines of the grid...I mean 
the grid is there but its all one colour (the background colour of the 
panel)! The fn that draws the lines is simply this:


(defn draw-grid [c g]
  (let [w (width c)
h (height c)]
(doseq [x (range 0 w 50)]
  (.drawLine g x 0 x h))
(doseq [y (range 0 h 50)]
(.drawLine g 0 y w y

Does anyone have any suggestions as to how to do the black-white 
alteration on the grid? I know how to do it imperatively using loop(s) 
and a couple of flags but I'm really struggling to tweak the 'draw-grid' 
accordingly to paint the colours as well...


Any seesaw gurus? - please help...

cheers,
Jim

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


Re: drawing a chess-board with seesaw ...

2012-08-09 Thread Stathis Sideris
How about drawing all the rectangles with 
.fillRect()http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#fillRect%28int,%20int,%20int,%20int%29and
 before each call alternate between black and white by calling 
.setColor()http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#setColor%28java.awt.Color%29.
 
You can alternate between the colours by taking the first of the following 
seq every time you set the color:

(cycle [java.awt.Color.black java.awt.Color.white])

Stathis

On Thursday, 9 August 2012 09:37:48 UTC+1, Jim foo.bar wrote:

 Hey all, 

 Spent most of yesterday trying to draw a chessboard on a paintable 
 canvas, however I'm stuck after drawing the lines of the grid...I mean 
 the grid is there but its all one colour (the background colour of the 
 panel)! The fn that draws the lines is simply this: 

 (defn draw-grid [c g] 
(let [w (width c) 
  h (height c)] 
  (doseq [x (range 0 w 50)] 
(.drawLine g x 0 x h)) 
  (doseq [y (range 0 h 50)] 
  (.drawLine g 0 y w y 

 Does anyone have any suggestions as to how to do the black-white 
 alteration on the grid? I know how to do it imperatively using loop(s) 
 and a couple of flags but I'm really struggling to tweak the 'draw-grid' 
 accordingly to paint the colours as well... 

 Any seesaw gurus? - please help... 

 cheers, 
 Jim 


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

Re: drawing a chess-board with seesaw ...

2012-08-09 Thread Jim - FooBar();

On 09/08/12 10:08, Stathis Sideris wrote:
How about drawing all the rectangles with .fillRect() 
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#fillRect%28int,%20int,%20int,%20int%29 
and before each call alternate between black and white by calling 
.setColor() 
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#setColor%28java.awt.Color%29. 
You can alternate between the colours by taking the first of the 
following seq every time you set the color:


(cycle [java.awt.Color.black java.awt.Color.white])

Stathis


Geia sou Stathi,

If I understood correctly, you propose filling rectangles instead of 
drawing lines...that is a good idea but how would I alternate the colors 
using 'cycle'? 'cycle' returns a infinitely cycled lazy-seq of the 
provided collection. Whenever i call 'first' on it I get the same value 
back...they are not alternating! Have I misunderstood? thanks for 
bothering btw... :-)


Jim (Dimitris)

--
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: drawing a chess-board with seesaw ...

2012-08-09 Thread Jim - FooBar();

On 09/08/12 11:17, Jim - FooBar(); wrote:

On 09/08/12 10:08, Stathis Sideris wrote:
How about drawing all the rectangles with .fillRect() 
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#fillRect%28int,%20int,%20int,%20int%29 
and before each call alternate between black and white by calling 
.setColor() 
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#setColor%28java.awt.Color%29. 
You can alternate between the colours by taking the first of the 
following seq every time you set the color:


(cycle [java.awt.Color.black java.awt.Color.white])

Stathis


Geia sou Stathi,

If I understood correctly, you propose filling rectangles instead of 
drawing lines...that is a good idea but how would I alternate the 
colors using 'cycle'? 'cycle' returns a infinitely cycled lazy-seq of 
the provided collection. Whenever i call 'first' on it I get the same 
value back...they are not alternating! Have I misunderstood? thanks 
for bothering btw... :-)


Jim (Dimitris)



aaa ok sorry...you mean having it as doseq binding...that makes sense! I 
apologise for rushing...


Jim

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

Re: drawing a chess-board with seesaw ...

2012-08-09 Thread Jim - FooBar();

On 09/08/12 11:23, Jim - FooBar(); wrote:
aaa ok sorry...you mean having it as doseq binding...that makes sense! 
I apologise for rushing...


Jim



No I can't put 'cycle' inside a doseq cos its trying to consume it!

Jim

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


Re: drawing a chess-board with seesaw ...

2012-08-09 Thread David Powell
You can try using the multi-input version of map to knit your data
together with some other, potentially infinite, sequence:

  (map vector items (cycle [black white]))

It returns something like this:

  ([item1 black] [item2 white] [item3 black] [item4 white])

Then you can use doseq over that, using destructuring to pick apart
the items and colours and do something appropriate with each of them.

-- 
Dave


On Thu, Aug 9, 2012 at 11:53 AM, Jim - FooBar(); jimpil1...@gmail.com wrote:
 On 09/08/12 11:23, Jim - FooBar(); wrote:

 aaa ok sorry...you mean having it as doseq binding...that makes sense! I
 apologise for rushing...

 Jim



 No I can't put 'cycle' inside a doseq cos its trying to consume it!


 Jim

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

-- 
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: drawing a chess-board with seesaw ...

2012-08-09 Thread Jim - FooBar();

On 09/08/12 12:00, David Powell wrote:

You can try using the multi-input version of map to knit your data
together with some other, potentially infinite, sequence:

   (map vector items (cycle [black white]))

It returns something like this:

   ([item1 black] [item2 white] [item3 black] [item4 white])

Then you can use doseq over that, using destructuring to pick apart
the items and colours and do something appropriate with each of them.



Thanks Dave that is pretty clever and looks very idiomatic! I managed to 
get what I by using your suggestion:


(defn draw-grid2 [d g]
  (let [w (width d)
h (height d)
tiles (map vector (for [x (range 0 w 50)
y (range 0 h 50)] [x y])
  (cycle [java.awt.Color/WHITE
  java.awt.Color/BLACK]))]
(doseq [[[x y] c] tiles]
   (.setColor g c)
   (.fillRect g x y 50 50)) ))


Thanks a lot! It looked impossible to achieve without mutation, indices 
and counting pixels!!!


Jim

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


Re: Attractive examples of function-generating functions

2012-08-09 Thread Chris Ford
I use quite a few of these in my Overtone rendering of
Bachhttp://skillsmatter.com/podcast/home/functional-composition
:

; Defining a scale function from intervals

(defn sum-n [series n] (reduce + (take n series)))

(defn scale [intervals]
  (fn [degree]
(if-not (neg? degree)
  (sum-n (cycle intervals) degree)
  ((comp - (scale (reverse intervals)) -) degree

(def major (scale [2 2 1 2 2 2 1]))

(major 2)


; Defining a time function

(defn bpm [beats] (fn [beat] (- beat (/ beats) (* 60) (* 1000

((bpm 90) 3)


; Defining a simple canon (like row, row, row your boat)

(defn canon [f] (fn [notes] (concat notes (f notes

(defn shift [point] (fn [notes] (map #(- % (map + point) vec) notes)))
(defn simple [wait] (shift [wait 0]))

(canon (simple 4))

Code's on 
githubhttps://github.com/ctford/goldberg/blob/SkillsMatter-2012/src/goldberg/variations/canone_alla_quarta.clj
.

Cheers,

Chris

On 9 August 2012 05:44, Ben Mabey b...@benmabey.com wrote:

 On 8/8/12 10:48 AM, Brian Marick wrote:

 I'm looking for medium-scale examples of using function-generating
 functions. I'm doing it because examples like this:

 (def make-incrementer
   (fn [increment]
 (fn [x] (+ increment x

 ... or this:

 (def incish (partial map + [100 200 300]))

 ... show the mechanics, but I'm looking for examples that would resonate
 more with an object-oriented programmer. Such examples might be ones that
 close over a number of values (which looks more like an object), or
 generate multiple functions that all close over a shared value (which looks
 more like an object), or use closures to avoid the need to have some
 particular argument passed from function to function (which looks like the
 `this` in an instance method).

 Note: please put the flamethrower down. I'm not saying that looking like
 objects is the point of higher-order functions.

 I'll give full credit.


 Oh, I have the perfect one that I actually had to write the other day.
  (The funny thing was that I wrote the exact same functionality in Ruby
 several years ago.. I like the clojure version much better).  I'll let the
 code and midje facts speak for themselves:

 ;; some context: 
 http://en.wikipedia.org/wiki/**Urn_problemhttp://en.wikipedia.org/wiki/Urn_problem
 (defn urn
   Takes a coll of pairs representing a distribution with keys being the
 probability of the corresponding values.

 Returns a function that when called will return a random value based on
 that distribution.

 Example:

  (def multimnomial-urn (urn [[0.3 :red] [0.5 :black] [0.2 :green]]))

  (take 5 (repeatedly multimnomial-urn)) = [:red :black :black :red :green]
 
   [dist]
   {:pre [(= 1.0 (reduce + (map first dist)))]}
   (let [range-dist (last (reduce (fn [[total pseudo-cdf] [percent val]]
(let [new-total (+ percent total)]
  [new-total (assoc pseudo-cdf
 new-total val)]))
  [0.0 (sorted-map)]
  dist))]
 (fn []
   ;; TODO: use a better PRNG
   (let [rn (rand)]
 (val (find-first #( rn  (key %)) range-dist))

 ;;; test code
 (ns foo.core-test
   (:use midje.sweet
 foo.core
 [useful.map :only [map-vals]]))

 (defn ratios [m]
   (let [freqs (frequencies m)
 total (reduce + (vals freqs))]
 (map-vals freqs #(/ % total

 (defn percentages [m]
   (- m ratios (map-vals double)))

 (facts '#urn
   (let [rand-key (urn [[0.3 :foo] [0.7 :bar]])]
 (percentages (repeatedly 100 rand-key)) = (just {:foo (roughly 0.3
 0.1)
   :bar (roughly 0.7
 0.1)})))


 ;;; end code


 Hopefully I understood the question and this helps some.  For an example
 in a book you could make it a bit simpler where the urn could only contain
 two potential values (binomial urn).


 -Ben


 --
 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+unsubscribe@**googlegroups.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/**group/clojure?hl=enhttp://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

Is this expected of seesaw ?

2012-08-09 Thread Jim - FooBar();

Hi again,

I'm having a couple of issues with seesaw and I'd like to see the 
community's experience with it...


1. First of all, my lein repl hangs each time I reload a namespace that
   uses seesaw.core. Not when I first load it (load-file
   blah...blah), but when I reload it after some changes...this is
   really a problem as I need to kill/restart leiningen after every
   change in the code! This completely defeats the purpose of dynamic
   compilation...
2. Secondly, whenever I was designing UIs in clojure I quite liked the
   ability to change the frame (e.g. resizing) dynamically from the
   repl while changes are immediately shown on screen...That saves a
   lot of time when experimenting. Now, the 'frame' function of seesaw
   does not exactly return a JFrame but a proxied version on to which,
   apparently, I cannot call (.setSize f 500 500) directly...I am
   suspecting  there must be some easy way to get around that yes?


Just so we're clear, question #1 is the important one...

Thanks in advance,

Jim


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

Re: Is this expected of seesaw ?

2012-08-09 Thread Meikel Brandmeyer (kotarak)
Hi,

Am Donnerstag, 9. August 2012 14:10:55 UTC+2 schrieb Jim foo.bar:

  

1. First of all, my lein repl hangs each time I reload a namespace 
that uses seesaw.core. Not when I first load it (load-file blah...blah), 
but when I reload it after some changes...this is really a problem as I 
need to kill/restart leiningen after every change in the code! This 
completely defeats the purpose of dynamic compilation...

 Never had any problem here. At least not with seesaw. I don't know lein.
 


1. Secondly, whenever I was designing UIs in clojure I quite liked the 
ability to change the frame (e.g. resizing) dynamically from the repl 
 while 
changes are immediately shown on screen...That saves a lot of time when 
experimenting. Now, the 'frame' function of seesaw does not exactly return 
a JFrame but a proxied version on to which, apparently, I cannot call 
(.setSize f 500 500) directly...I am suspecting  there must be some easy 
way to get around that yes?

 (config! your-frame :size [x :by y])

Seems to work for me from the repl. (Maybe with some (invoke-later ...)?)

Kind regards
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: drawing a chess-board with seesaw ...

2012-08-09 Thread Stathis Sideris
Yeah, sorry Dimitri, I wasn't very clear :-) I meant that if you were going 
to do it recursively you would be using the first element of the seq, and 
you would be passing the (rest) of the seq to the subsequent recursive 
call. Very elegant solution!

On Thursday, 9 August 2012 12:29:12 UTC+1, Jim foo.bar wrote:

 On 09/08/12 12:00, David Powell wrote: 
  You can try using the multi-input version of map to knit your data 
  together with some other, potentially infinite, sequence: 
  
 (map vector items (cycle [black white])) 
  
  It returns something like this: 
  
 ([item1 black] [item2 white] [item3 black] [item4 white]) 
  
  Then you can use doseq over that, using destructuring to pick apart 
  the items and colours and do something appropriate with each of them. 
  

 Thanks Dave that is pretty clever and looks very idiomatic! I managed to 
 get what I by using your suggestion: 

 (defn draw-grid2 [d g] 
(let [w (width d) 
  h (height d) 
  tiles (map vector (for [x (range 0 w 50) 
  y (range 0 h 50)] [x y]) 
(cycle [java.awt.Color/WHITE 
java.awt.Color/BLACK]))] 
  (doseq [[[x y] c] tiles] 
 (.setColor g c) 
 (.fillRect g x y 50 50)) )) 


 Thanks a lot! It looked impossible to achieve without mutation, indices 
 and counting pixels!!! 

 Jim 


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

Re: Is this expected of seesaw ?

2012-08-09 Thread Jim - FooBar();

On 09/08/12 13:39, Meikel Brandmeyer (kotarak) wrote:

(config! your-frame :size [x :by y])


yep! that does the trick... thanks a lot Meikel!

are you 'using' or 'requiring' seesaw.core in your projects?

the same thing happens (repl hangs) when i cose my frame and try to open 
up a new one! this is weird yes?


Jim

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


Why does (conj (transient {}) {}) fail with CCE?

2012-08-09 Thread Jacek Laskowski
Hi,

I've been digging into the sources of Clojure and found frequencies.
There's the transient function and I thought I'd use it with a map and
conj. Why does this fail?

user= (conj {} {:y 1})
{:y 1}
user= (conj (transient {}) {:y 1})
ClassCastException   [trace missing]

I ran into the issue before and got a more comprehensible exception.

ClassCastException clojure.lang.PersistentArrayMap$TransientArrayMap
cannot be cast to clojure.lang.IPersistentCollection
clojure.core/conj (core.clj:83)

I can't explain why the exception is reported in two different versions.

Should the exception be thrown? What's the rationale behind
TransientArrayMap *not* being a IPersistentCollection?

Jacek

-- 
Jacek Laskowski
Functional languages (Clojure), Java EE, and IBM WebSphere -
http://blog.japila.pl
Never discourage anyone who continually makes progress, no matter how
slow. Plato

-- 
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: Why does (conj (transient {}) {}) fail with CCE?

2012-08-09 Thread dennis zhuang
you must use conj! instead of conj.
在 2012-8-9 PM8:49,Jacek Laskowski ja...@japila.pl写道:

 Hi,

 I've been digging into the sources of Clojure and found frequencies.
 There's the transient function and I thought I'd use it with a map and
 conj. Why does this fail?

 user= (conj {} {:y 1})
 {:y 1}
 user= (conj (transient {}) {:y 1})
 ClassCastException   [trace missing]

 I ran into the issue before and got a more comprehensible exception.

 ClassCastException clojure.lang.PersistentArrayMap$TransientArrayMap
 cannot be cast to clojure.lang.IPersistentCollection
 clojure.core/conj (core.clj:83)

 I can't explain why the exception is reported in two different versions.

 Should the exception be thrown? What's the rationale behind
 TransientArrayMap *not* being a IPersistentCollection?

 Jacek

 --
 Jacek Laskowski
 Functional languages (Clojure), Java EE, and IBM WebSphere -
 http://blog.japila.pl
 Never discourage anyone who continually makes progress, no matter how
 slow. Plato

 --
 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: Why does (conj (transient {}) {}) fail with CCE?

2012-08-09 Thread Baishampayan Ghose
On Thu, Aug 9, 2012 at 6:19 PM, Jacek Laskowski ja...@japila.pl wrote:
 What's the rationale behind
 TransientArrayMap *not* being a IPersistentCollection?

A transient map can't be a persistent map at the same time. You
need to use the transient version of conj, called conj! to conjoin
something into a transient map and then use persistent! to get a
persistent version back.

Please read the documentation for more background http://clojure.org/Transients

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at 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


New to Clojure, need some help

2012-08-09 Thread Jason Long
I am trying to remove every occurrence of a given element from a vector.  I 
can use (filter #(== % a) v) where 'a' is the value to be removed and 'v' 
is the vector, but this returns 'a' and 'a' is the value i want to remove. 
So, how can i do this? I tried replacing 'filter' with 'remove' but it 
didn't like that. Also, can anyone tell me why != is not included for 
equality testing, that would make this problem easy.

Thanks, Jason.

P.S. I also need to be able replicate the problem, but instead of removing 
a single item from the vector, I need to remove a list of items from the 
vector. I know I'm going to have to do some looping or recursing, but any 
help would be appreciated. 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: New to Clojure, need some help

2012-08-09 Thread Baishampayan Ghose
Hi,

Does this work for you?

(remove #{:a} [:a :b :a :c :d :e])

Also, if you have a list of items you can have all of them in the same
set/predicate like so -

(remove #{:a :z :x} [:a :b :a :c :d :e :z :b :d :e :x :z])

Hope this helps.

Regards,
BG

On Thu, Aug 9, 2012 at 10:11 AM, Jason Long jsnl...@gmail.com wrote:
 I am trying to remove every occurrence of a given element from a vector.  I
 can use (filter #(== % a) v) where 'a' is the value to be removed and 'v' is
 the vector, but this returns 'a' and 'a' is the value i want to remove. So,
 how can i do this? I tried replacing 'filter' with 'remove' but it didn't
 like that. Also, can anyone tell me why != is not included for equality
 testing, that would make this problem easy.

 Thanks, Jason.

 P.S. I also need to be able replicate the problem, but instead of removing a
 single item from the vector, I need to remove a list of items from the
 vector. I know I'm going to have to do some looping or recursing, but any
 help would be appreciated. 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



-- 
Baishampayan Ghose
b.ghose at 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: New to Clojure, need some help

2012-08-09 Thread Timothy Baldridge
To clarify  Baishampayan's code, hash-sets in Clojure are functions:

= (#{1} 1)
1
= (#{1} 2)
nil

Nil and false in Clojure are the same thing,

So Baishampayan's example:

(remove #{:a :z :x} [:a :b :a :c :d :e :z :b :d :e :x :z])

#{:a :z : x} will return nil if the value is not in the vector, nil is
considered false, and so the not found value is removed from the seq.

Timothy

-- 
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: New to Clojure, need some help

2012-08-09 Thread Baishampayan Ghose
On Thu, Aug 9, 2012 at 10:11 AM, Jason Long jsnl...@gmail.com wrote:
 Also, can anyone tell me why != is not included for equality testing, that
 would make this problem easy.

To answer your other question, != in Clojure is called not=

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at 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: Is this expected of seesaw ?

2012-08-09 Thread Meikel Brandmeyer (kotarak)
Hi,

Am Donnerstag, 9. August 2012 14:43:57 UTC+2 schrieb Jim foo.bar:

 are you 'using' or 'requiring' seesaw.core in your projects? 


I usually do (require '[seesaw.core :as swing]).
 

 the same thing happens (repl hangs) when i cose my frame and try to open 
 up a new one! this is weird yes? 


Never had any problems. But you have to pay attention to the event dispatch 
thread. Maybe threre is some conflict there. (Just a guess. Cargo cult.)

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: Clojure group in DFW area

2012-08-09 Thread Alex Robbins
The group hasn't met in a long time, but we were actually talking
about some kind of a relaunch last week. We were hoping some Clojure
interest had increased in the DFW area since we tried last time.
Anyone else in the DFW area interested in getting together?

Alex

On Tue, Aug 7, 2012 at 11:09 AM, VishK svko...@gmail.com wrote:
 Hello,

 Is this group still meeting? (When?)
 Would be interested in attending the next one if possible to meet
 like-minded folks.

 Regards
 Vish
 (https://github.com/vishk)

 On Wednesday, June 15, 2011 11:02:10 AM UTC-5, ch...@rubedoinc.com wrote:

 Everyone, sorry for late notice but are meeting tonight is cancelled
 due to some scheduling conflicts. We have another meeting set for

 Tuesday June 28th 630PM - 900PM @

 Rubedo, inc.
 14580 Beltwood Pkwy E Suite 103
 Farmers Branch, TX 75244

 See you then !

 On Jun 3, 9:46 am, ch...@rubedoinc.com ch...@rubedoinc.com wrote:
  Meeting is growing strong!  We will be looking at some group projects
  to take on that we can use to stretch our clojure skills.  Make the
  next meeting to be a part of it!
 
  Wednesday June 15th 630PM - 900PM @
 
  Rubedo, inc.
  14580 Beltwood Pkwy E Suite 103
  Farmers Branch, TX 75244
 
  (wifi available)
 
  On May 20, 11:08 am, ch...@rubedoinc.com ch...@rubedoinc.com
  wrote:
 
 
 
 
 
 
 
   Thanks everyone for attending.  Our next meeting is scheduled for
 
   Our next meeting is scheduled for May 31th 630PM - 900PM @
 
   Rubedo, inc.
   14580 Beltwood Pkwy E Suite 103
   Farmers Branch, TX 75244
   (wifi available)
 
   there will be pizza and sodas, so bring yourclojurequestions and
   your appetite.  Reply in this thread if you will be attending so that
   I can get a head count for pizza.
 
   On May 16, 12:41 pm, ch...@rubedoinc.com ch...@rubedoinc.com
   wrote:
 
Meeting tonight, see you there !
 
Our next meeting is scheduled for May 16th 630PM - 900PM @
 
Rubedo, inc.
14580 Beltwood Pkwy E Suite 103
Farmers Branch, TX 75244
(wifi available)
 
On May 4, 11:20 am, ch...@rubedoinc.com ch...@rubedoinc.com
wrote:
 
 Thanks everyone for attending the first meeting.  It was great to
 talk
clojurewith some like minded people who are excited by the
 possibilities !
 
 Our next meeting is scheduled for May 16th 630PM - 900PM @
 
 Rubedo, inc.
 14580 Beltwood Pkwy E Suite 103
 Farmers Branch, TX 75244
 (wifi available)
 
 Right now, we will try for two meetings each month. In the
 beginning,
 these will be mostly hack nights. As the group matures, we will
 look
 at doing presentations / talks onClojure.
 As most of the group is relatively new toClojure, we decided to
 start
 with thehttp://projecteuler.net/problemsasaway to get familiar
 with the language and have some common solutions to discuss.
 
 At our next meeting, we will bring our solutions for problems 1-10
 and
 discuss how we went about solving them.
 
 All are welcome !
 
 On Apr 25, 9:08 pm, Christopher Redinger ch...@clojure.com
 wrote:
 
  ch...@rubedoinc.com wrote:
   Rubedo, inc.
   14580 Beltwood Pkwy E Suite 103
   Farmers Branch, TX 75244
 
   When: 630PM Monday May 2nd
   What:ClojureInterest Group
   Topic: 1st meeting, what our goals are, and how to take over
   the world
   withClojure
 
  Hi Chris! Thanks for offering to host the group. I've added a
  link to
  this thread on theClojureUser Groups
  page:http://dev.clojure.org/display/community/Clojure+User+Groups.
  Hopefully to help people who might be looking. We can update the
  link
  to something with a little more information if you get a page
  set up
  somewhere.
 
  Also, if you choose to go through Meetup, they have provided us
  with a
  code that gives a discount toClojuregroups. See the above page
  for
  more information.
 
  Thanks again, and let me know if there's anythingClojure/core
  can
  help you out with!
 
  Thanks,
  Chris

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


reduce-kv doesn't reduce a sorted-map in order

2012-08-09 Thread Baishampayan Ghose
Hi,

It seems reduce-kv doesn't reduce a sorted-map in the correct order.

Example -

user (def *sm (into (sorted-map) {:aa 1 :zz 2 :bb 3 :yy 4 :cc 5 :xx 6}))
;= #'user/*sm

user *sm
;= {:aa 1, :bb 3, :cc 5, :xx 6, :yy 4, :zz 2}

;; plain reduce
user (reduce (fn [ret e] (conj ret e)) [] *sm)
;= [[:aa 1] [:bb 3] [:cc 5] [:xx 6] [:yy 4] [:zz 2]] ; correct

;; reduce-kv
user (reduce-kv (fn [ret k v] (conj ret [k v])) [] *sm)
;= [[:cc 5] [:bb 3] [:aa 1] [:yy 4] [:xx 6] [:zz 2]] ; incorrect

Is this a bug?

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at 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: Why does (conj (transient {}) {}) fail with CCE?

2012-08-09 Thread Jacek Laskowski
On Thu, Aug 9, 2012 at 2:54 PM, Baishampayan Ghose b.gh...@gmail.com wrote:

 A transient map can't be a persistent map at the same time. You
 need to use the transient version of conj, called conj! to conjoin
 something into a transient map and then use persistent! to get a
 persistent version back.

 Please read the documentation for more background 
 http://clojure.org/Transients

Thanks! It's so much clearer now.

Jacek

-- 
Jacek Laskowski
Functional languages (Clojure), Java EE, and IBM WebSphere -
http://blog.japila.pl
Never discourage anyone who continually makes progress, no matter how
slow. Plato

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


Ideas for interactive tasks

2012-08-09 Thread Nikita Beloglazov
Hello
I'm going to organize little clojure course at my university this year. For 
this I want to implement set of tasks that hopefully will help to practise 
clojure. 
Tasks will be animated so students can see how their solutions work. E.g. 
one of the tasks is to hit plane by missile: there is a plane that flies 
from left to the right with fixed speed. Player launches missile to hit the 
plane. Task is to write a function that takes coordinates of plane and 
player and returns angle for launching missile. Plane's and missile's 
speeds are constant and known. This task requires math and basic clojure 
knowledge (only perform math operations, use let, if, Math/* functions). 
Another example is to implement a bot for snake. Bot is implemented as a 
function that takes snakes position (sequence of cells, each cell is vector 
of 2 values) and apple position (vector of 2 values). Function must return 
what direction to move. This task requires using of clojure seq functions.
Can somebody propose ideas for this kind of tasks? I'm particularly 
interested in tasks that require different fields of clojure, e.g. I don't 
know what to implement for learning atoms, refs and agends. 

Examples of tasks (artillery and snake) can be found here: 
https://github.com/nbeloglazov/clojure-interactive-tasks. I use quil 
https://github.com/quil/quilfor animation. Animation is primitive in the 
tasks (I'm not particularly good at it).

Thank you,
Nikita Beloglazov

-- 
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: Ideas for interactive tasks

2012-08-09 Thread Jim - FooBar();

On 09/08/12 16:21, Nikita Beloglazov wrote:

I'm going to organize little clojure course at my university this year.


this is amazing! seriously, bravo! what university is this?

Jim

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


Re: Ideas for interactive tasks

2012-08-09 Thread Nikita Beloglazov
Thank you, Jim. This is Belarusian State University.

On Thu, Aug 9, 2012 at 6:23 PM, Jim - FooBar(); jimpil1...@gmail.comwrote:

 On 09/08/12 16:21, Nikita Beloglazov wrote:

 I'm going to organize little clojure course at my university this year.


 this is amazing! seriously, bravo! what university is this?

 Jim


 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscribe@**googlegroups.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/**group/clojure?hl=enhttp://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: Clojure group in DFW area

2012-08-09 Thread James Ashley
I just moved to the DFW area, and I'm curious about these meetings as well. 
Is anything going on with them?

On Tuesday, August 7, 2012 11:09:05 AM UTC-5, VishK wrote:

 Hello,

 Is this group still meeting? (When?)
 Would be interested in attending the next one if possible to meet 
 like-minded folks.

 Regards
 Vish 
 (https://github.com/vishk)

 On Wednesday, June 15, 2011 11:02:10 AM UTC-5, ch...@rubedoinc.com wrote:

 Everyone, sorry for late notice but are meeting tonight is cancelled 
 due to some scheduling conflicts. We have another meeting set for 

 Tuesday June 28th 630PM - 900PM @ 

 Rubedo, inc. 
 14580 Beltwood Pkwy E Suite 103 
 Farmers Branch, TX 75244 

 See you then ! 

 On Jun 3, 9:46 am, ch...@rubedoinc.com ch...@rubedoinc.com wrote: 
  Meeting is growing strong!  We will be looking at some group projects 
  to take on that we can use to stretch our clojure skills.  Make the 
  next meeting to be a part of it! 
  
  Wednesday June 15th 630PM - 900PM @ 
  
  Rubedo, inc. 
  14580 Beltwood Pkwy E Suite 103 
  Farmers Branch, TX 75244 
  
  (wifi available) 
  
  On May 20, 11:08 am, ch...@rubedoinc.com ch...@rubedoinc.com 
  wrote: 
  
  
  
  
  
  
  
   Thanks everyone for attending.  Our next meeting is scheduled for 
  
   Our next meeting is scheduled for May 31th 630PM - 900PM @ 
  
   Rubedo, inc. 
   14580 Beltwood Pkwy E Suite 103 
   Farmers Branch, TX 75244 
   (wifi available) 
  
   there will be pizza and sodas, so bring yourclojurequestions and 
   your appetite.  Reply in this thread if you will be attending so that 
   I can get a head count for pizza. 
  
   On May 16, 12:41 pm, ch...@rubedoinc.com ch...@rubedoinc.com 
   wrote: 
  
Meeting tonight, see you there ! 
  
Our next meeting is scheduled for May 16th 630PM - 900PM @ 
  
Rubedo, inc. 
14580 Beltwood Pkwy E Suite 103 
Farmers Branch, TX 75244 
(wifi available) 
  
On May 4, 11:20 am, ch...@rubedoinc.com ch...@rubedoinc.com 
 wrote: 
  
 Thanks everyone for attending the first meeting.  It was great to 
 talk 
clojurewith some like minded people who are excited by the 
 possibilities ! 
  
 Our next meeting is scheduled for May 16th 630PM - 900PM @ 
  
 Rubedo, inc. 
 14580 Beltwood Pkwy E Suite 103 
 Farmers Branch, TX 75244 
 (wifi available) 
  
 Right now, we will try for two meetings each month. In the 
 beginning, 
 these will be mostly hack nights. As the group matures, we will 
 look 
 at doing presentations / talks onClojure. 
 As most of the group is relatively new toClojure, we decided to 
 start 
 with thehttp://projecteuler.net/problemsasaway to get familiar 
 with the language and have some common solutions to discuss. 
  
 At our next meeting, we will bring our solutions for problems 
 1-10 and 
 discuss how we went about solving them. 
  
 All are welcome ! 
  
 On Apr 25, 9:08 pm, Christopher Redinger ch...@clojure.com 
 wrote: 
  
  ch...@rubedoinc.com wrote: 
   Rubedo, inc. 
   14580 Beltwood Pkwy E Suite 103 
   Farmers Branch, TX 75244 
  
   When: 630PM Monday May 2nd 
   What:ClojureInterest Group 
   Topic: 1st meeting, what our goals are, and how to take over 
 the world 
   withClojure 
  
  Hi Chris! Thanks for offering to host the group. I've added a 
 link to 
  this thread on theClojureUser Groups page:
 http://dev.clojure.org/display/community/Clojure+User+Groups. 
  Hopefully to help people who might be looking. We can update 
 the link 
  to something with a little more information if you get a page 
 set up 
  somewhere. 
  
  Also, if you choose to go through Meetup, they have provided us 
 with a 
  code that gives a discount toClojuregroups. See the above page 
 for 
  more information. 
  
  Thanks again, and let me know if there's anythingClojure/core 
 can 
  help you out with! 
  
  Thanks, 
  Chris



-- 
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: basic question , clojure io

2012-08-09 Thread Stuart Sierra
No, there is no language-level distinction between pure functions and 
functions which perform side effects. In practice, it is a good idea to 
keep them separate.
-S


On Tuesday, August 7, 2012 9:37:31 AM UTC-4, centaurian_slug wrote:

 does clojure have a strict split between side-effects and pure functions 
 like haskell;
 I guess what i have in my head is a rigorous split between effectfull 
 'procedures' and pure 'functions',the latter cannot call the former; 
 although i know thats' implemented through the more general mechanism of 
 monads in haskell.




-- 
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: Attractive examples of function-generating functions

2012-08-09 Thread hyPiRion

On Wednesday, August 8, 2012 6:48:23 PM UTC+2, Brian Marick wrote:

 ... show the mechanics, but I'm looking for examples that would resonate 
 more with an object-oriented programmer. Such examples might be ones that 
 close over a number of values (which looks more like an object), or 
 generate multiple functions that all close over a shared value (which looks 
 more like an object), or use closures to avoid the need to have some 
 particular argument passed from function to function (which looks like the 
 `this` in an instance method). 


You can make objects with its state hidden in a closure. E.g. if we want to 
make a stack where people cannot look at any other element than the first 
one, we can do that like this:

(letfn [(stack-fns [stack]
  {:push (fn [elt] (stack-fns (conj stack elt)))
   :pop (fn [] (stack-fns (pop stack)))
   :peek (fn [] (peek stack))
   :empty? (fn [] (empty? stack))})]
  (defn new-stack []
(stack-fns [])))

Usage would be like this:

(let [stack (reduce
 #((%1 :push) %2)
 (new-stack)
 (range 1 10))] ; To fill it with data
  (loop [stack stack]
(if ((stack :empty?))
  nil
  (let [h ((stack :peek))
t ((stack :pop))]
(prn h)
(recur t)

And this will print the numbers 9 to 1, before returning nil.

The Joy of Clojure looks at this from p. 138 to 141, so I take no credit 
for the idea - give that to the authors.

-- 
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: Attractive examples of function-generating functions

2012-08-09 Thread Jonah Benton
You've probably seen these, but if not, Doug Crockford's video series
on javascript walks through a number of interesting information
sharing examples like the ones you're looking for using
fn-generating-fns-

http://yuiblog.com/crockford/

They're all great but act 3 - function the ultimate is especially juicy.

The motivation for his examples is a little different than it would be
for clojure, because that pattern is basically javascript's only
abstraction trick. And certainly the semantics are different too.

But if for whatever reason you haven't seen these videos, they're
terrific and will probably spur some ideas.


On Wed, Aug 8, 2012 at 12:48 PM, Brian Marick mar...@exampler.com wrote:
 I'm looking for medium-scale examples of using function-generating functions. 
 I'm doing it because examples like this:

 (def make-incrementer
  (fn [increment]
(fn [x] (+ increment x

 ... or this:

 (def incish (partial map + [100 200 300]))

 ... show the mechanics, but I'm looking for examples that would resonate more 
 with an object-oriented programmer. Such examples might be ones that close 
 over a number of values (which looks more like an object), or generate 
 multiple functions that all close over a shared value (which looks more like 
 an object), or use closures to avoid the need to have some particular 
 argument passed from function to function (which looks like the `this` in an 
 instance method).

 Note: please put the flamethrower down. I'm not saying that looking like 
 objects is the point of higher-order functions.

 I'll give full credit.

 -
 Brian Marick, Artisanal Labrador
 Contract programming in Ruby and Clojure
 Occasional consulting on Agile


 --
 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: DAG (Direct Acyclic Graph) and Bayesian Network help

2012-08-09 Thread Alexsandro Soares
Hi Simone,

You can look at the code made ​​by Cory Giles at
https://github.com/gilesc/factor-graph

Good luck.
Alexsandro

2012/7/14 Simone Mosciatti mweb@gmail.com

 Hi guys,
 I'm trying to develop a Bayesian Network just for fun XD

 My first problem is to understand how represent the graph necessary a DAG.

 I come out with something : https://gist.github.com/3111539
 (Very very first stage I just finish to write this code)

 But I have some question to how represent properly the DAG.

 I need to map every child of every node, or I just need to know the
 (non-)descendants of every node ? Why ?

 Do you have any useful link that I can use ?

 Thank you guys anyway.

 PS: This is still me
 http://stackoverflow.com/questions/11482474/clojure-dag-bayesian-network#comment15165499_11482474

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




-- 
Alexsandro Santos Soares, Prof. Dr.
Faculdade de Computação
Universidade Federal de Uberlândia - UFU - Sala 1B123
+55 (0xx34) 3239-4478

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