Re: Perfect Functional Shuffle in Clojure

2014-03-21 Thread Peter Brachwitz
Thank you, Andy! Both for spotting my mistake  and for your comments on 
style. 

On Thursday, March 20, 2014 11:34:00 PM UTC+1, Andy Fingerhut wrote:
>
> I haven't read all of your code, but note that the Haskell algorithm says 
> it takes a sequence of random values where the first is in the range 
> [0,n-1], the second in the range [0,n-2], third in [0,n-3], etc.  Your 
> repeatedly call here:
>
> 
> https://github.com/pebrc/ninety-nine-clojure/blob/master/src/ninety_nine_clojure/lists.clj#L273
>
> Is generating a sequence of random values that are all in the range 
> [0,n-1].
>
> A couple of style comments on your function perfect-functional-shuffle:
>
> I find it easier to read when a let or loop has multiple bindings on one 
> line if it has commas between the symbol value pairs, e.g.:
>
> (loop [bst bst, rnds rnds, acc []]
>
> Clojure treats commas in source code as white space.
>
> The default case in a cond is most often written :else rather than 
> :otherwise, but both are clear in their meaning and have the same behavior 
> (i.e. any value there other than nil or false will be treated as true).
>
> I prefer to write two-branch cond statements using if rather than cond.
>
> Andy
>
>
> On Thu, Mar 20, 2014 at 1:59 PM, Peter Brachwitz 
> 
> > wrote:
>
>> I tried to implement perfect functional shuffle in Clojure as outlined in 
>> http://okmij.org/ftp/Haskell/perfect-shuffle.txt
>>
>> This is purely for educational purposes as I am learning Clojure (so 
>> please don't be too hard on me if I did something silly)
>>
>> The code:
>>
>> https://github.com/pebrc/ninety-nine-clojure/blob/master/src/ninety_nine_clojure/lists.clj#L267
>>
>> A related blog post:
>>
>> http://pbrc.blogspot.com/2014/03/99-clojure-problems-25-generate-random.html
>>
>> I would be very happy about any feedback/review. If you have a look at 
>> the blog post you will find a histogram that seems to indicate that my 
>> perfect functional shuffle is not quite perfect because it is not a uniform 
>> distribution. That is almost certainly a mistake on my part, again, I would 
>> be very grateful for any hints.
>>
>> Cheers,
>> Peter
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


Perfect Functional Shuffle in Clojure

2014-03-20 Thread Peter Brachwitz
I tried to implement perfect functional shuffle in Clojure as outlined in 
http://okmij.org/ftp/Haskell/perfect-shuffle.txt

This is purely for educational purposes as I am learning Clojure (so please 
don't be too hard on me if I did something silly)

The code:
https://github.com/pebrc/ninety-nine-clojure/blob/master/src/ninety_nine_clojure/lists.clj#L267

A related blog post:
http://pbrc.blogspot.com/2014/03/99-clojure-problems-25-generate-random.html

I would be very happy about any feedback/review. If you have a look at the 
blog post you will find a histogram that seems to indicate that my perfect 
functional shuffle is not quite perfect because it is not a uniform 
distribution. That is almost certainly a mistake on my part, again, I would 
be very grateful for any hints.

Cheers,
Peter

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