Re: Unseemingly Eager Clojure Apprentice Seeking FizzBuzz Feeback

2012-12-31 Thread Thomas
Just to bring this one back to topic; here is another FizzBuzz, this time 
no cond/if statement:

(def three (cycle [nil nil "fizz"]))

(def five (cycle [nil nil nil nil "buzz"]))

(map vector (range 1 16) three five )

;([1 nil nil] [2 nil nil] [3 "fizz" nil] ...


Thomas

-- 
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: Unseemingly Eager Clojure Apprentice Seeking FizzBuzz Feeback

2012-12-30 Thread Ben Wolfson
If-let would be confusing if it handled multiple bindings, since you wouldn't 
know how much had succeeded when you executed the else branch. That doesn't 
apply to when-let; fortunately it's quite simple to write one that does do 
multiple bindings in terms of the existing when-let, and it would be very 
similar to the maybe monad. It still would not be the maybe monad for the same 
reason that the existing "maybe-m" in the monads library isn't actually the 
maybe monad: without a Just-like wrapper meaning "success", it's impossible to 
successfully return nil.

Sent from my iPhone

On Dec 30, 2012, at 11:56 AM, Mark Engelberg  wrote:

> On Sun, Dec 30, 2012 at 4:32 AM, Meikel Brandmeyer  wrote:
> (when-let [s (seq coll)]
>   (do-stuff-with s))
> 
> I would find when-let a lot more useful if it worked with multiple bindings, 
> e.g.,
> (when-let [x blah1
>y blah2
>z blah3]
> (+ x y z))
> should shortcut return nil if any of x, y, z evaluate to falsey.
> 
> Actually, I usually use Christophe Grand's version of when-let and if-let 
> which handle this.  I find it to be more useful that way.
> 
> Any idea why core's when-let/if-let don't behave this way?  I've been looking 
> through the monad material lately, and it seems like let is the identity 
> monad, for is the sequence monad, and when-let wants to be the maybe monad, 
> but isn't quite because it only handles one binding.  Doesn't it seem most 
> natural to let it handle multiple bindings?  What am I missing?
> -- 
> 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: Unseemingly Eager Clojure Apprentice Seeking FizzBuzz Feeback

2012-12-30 Thread Mark Engelberg
On Sun, Dec 30, 2012 at 4:32 AM, Meikel Brandmeyer  wrote:

> (when-let [s (seq coll)]
>   (do-stuff-with s))
>

I would find when-let a lot more useful if it worked with multiple
bindings, e.g.,
(when-let [x blah1
   y blah2
   z blah3]
(+ x y z))
should shortcut return nil if any of x, y, z evaluate to falsey.

Actually, I usually use Christophe Grand's version of when-let and if-let
which handle this.  I find it to be more useful that way.

Any idea why core's when-let/if-let don't behave this way?  I've been
looking through the monad material lately, and it seems like let is the
identity monad, for is the sequence monad, and when-let wants to be the
maybe monad, but isn't quite because it only handles one binding.  Doesn't
it seem most natural to let it handle multiple bindings?  What am I missing?

-- 
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: Unseemingly Eager Clojure Apprentice Seeking FizzBuzz Feeback

2012-12-30 Thread Meikel Brandmeyer
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,

Am 30.12.12 07:14, schrieb Laurent PETIT:
>> `when` provides an implicit `do`, so I generally try to only use
>> it when I want side-effects. (Other side-effecty forms include
>> `do`, `doseq`, `dotimes` and `when-not`.)
> 
> On the other end, using when allows you to be explicit in your
> code that there's no "else" clause

And it's quite useful when working with sequences:

(when-let [s (seq coll)]
  (do-stuff-with s))

Meikel


-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.18 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with undefined - http://www.enigmail.net/

iQIcBAEBAgAGBQJQ4DRBAAoJEM2sO9pIirXjPioP/jpvmSpSBm7wlsNXTgTORTXG
JhOw0ri1CUlw3Gg/zuXFuIXZBsga2kjF7LNk1TyDc5whNlU6WwVYGiVjqL/lCI2i
j372h63/pzKfw6BSnLr9pOcRM+hu70JrvDTdk+qddJlQ68v/Uex2QvxwfGQlwDc2
ogGE2xglqzSRKWJ3g3AB5ctFhbNGn6nRNcoxvSmUOL+2KkVDn5mjP/zMsG3V/anC
9yJDZf+qJk8kWzBB0YPJIAnqgmzyWFfzsqlgiafpxWG5R+Xu9+JEDFmumPgBz2jr
MLZHRSaimffiXIgW6mudLy88qoRn94tUrR9GZx/Nwx//IqqoBQn6FO+R+63BKDNK
x1oR42iG87SjQM9a6h20R+VnhD7efV2/WqZC/0ZYBW5SHh1iU9Gzip1XwrPJvi8E
8WJgEPXlj3jnyEq7PHuRsQvznPuSmULqzgtAUdl3XbkxcWvJDbCupZKChzsABu8I
JG0xVlokLhDn0lqnq74URV8tTe2P5096jgLQ6jiA940o+EUwozTn2nv+tmCN+pe8
LQF4VvCw07aizInR+qaAM1LOBMLjbA5Vjqi2b0rHwCVrGOl2tAqAAZNL610zb3Tz
nwTG1ycs8MO+eOxCWPs677jB4QesfilaQASZ50u8ZV0pRlnhDol5rH102N1pSClg
lFh4F7RhSLIDhKgZymCR
=DUpD
-END PGP SIGNATURE-

-- 
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: Unseemingly Eager Clojure Apprentice Seeking FizzBuzz Feeback

2012-12-29 Thread Laurent PETIT
2012/12/30 John Gabriele :
> On Saturday, December 29, 2012 5:15:49 PM UTC-5, Sean Chalmers wrote:
>>
>> ... but changing it to more pure function would probably deal with that.
>
>
> Another benefit of pure functions is that they're easier to test.
>
>>
>> I'll have a play with 'when' as well, hadn't tried that one yet.
>
>
> `when` provides an implicit `do`, so I generally try to only use it when I
> want side-effects. (Other side-effecty forms include `do`, `doseq`,
> `dotimes` and `when-not`.)

On the other end, using when allows you to be explicit in your code
that there's no "else" clause

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

-- 
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: Unseemingly Eager Clojure Apprentice Seeking FizzBuzz Feeback

2012-12-29 Thread John Gabriele
On Saturday, December 29, 2012 5:15:49 PM UTC-5, Sean Chalmers wrote:
>
> ... but changing it to more pure function would probably deal with that.


Another benefit of pure functions is that they're easier to test.
 

> I'll have a play with 'when' as well, hadn't tried that one yet. 


`when` provides an implicit `do`, so I generally try to only use it when I 
want side-effects. (Other side-effecty forms include `do`, `doseq`, 
`dotimes` and `when-not`.)

---John

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

Re: Unseemingly Eager Clojure Apprentice Seeking FizzBuzz Feeback

2012-12-29 Thread Sean Chalmers
Yay! Thanks for the feedback everyone. I originally had it as a 'cond' but 
because I was using 'println' directly in my fizzy function I was getting 
on 15 for example "fizzbuzz, buzz, fizz" but changing it to more pure 
function would probably deal with that. I'll have a play with 'when' as 
well, hadn't tried that one yet. 

Thanks again and I look forward to showing off some Clojure creations in 
the wild soon.

On Saturday, 29 December 2012 22:35:38 UTC+10, Sean Chalmers wrote:
>
> Greetings all!
>
> I'm just starting out in the so far wonderful world of Clojure and to help 
> me get started I had a crack at one of my favourites, the FizzBuzz program. 
> For anyone that isn't familiar with FizzBuzz, it is designed to count from 
> 1 to N and take the following actions when certain conditions are met:
>
>- When the remainder of i divided by 3 is 0 print "Fizz"
>- When the remainder of i divided by 5 is 0 print "Buzz"
>- When both the former are true of i print "FizzBuzz"
>
> I crafted the following as a solution and I would really appreciate some 
> more experienced Clojurians casting their eye over it and letting me know 
> if what I've done is in the style and spirit of Clojure. Also this is my 
> first functional language so any feedback on that would be awesome too. :)
>
> I'm aware it's only a tnsy piece of code so not terribly 
> indicative of the hilarity that might ensue on a larger project but all the 
> same. Enough of my blathering here is the meaty bit:
>
> (defn zero-remainder? [x y]
>   (zero? (rem x y)))
>
> (defn fizzy [x]
>   (let [fizz (zero-remainder? x 3) buzz (zero-remainder? x 5)]
> (if (and fizz buzz)
>   (println "FizzBuzz: " x)
>   (if buzz
> (println "Buzz: " x)
> (if fizz
>   (println "Fizz: " x))
>
> (doseq [x (range 1 25)]
>   (fizzy x))
>

-- 
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: Unseemingly Eager Clojure Apprentice Seeking FizzBuzz Feeback

2012-12-29 Thread Laurent PETIT
2012/12/29 Nikita Beloglazov 
>
> Hi
>
> I'd change your fizzy function so it returns a string instead of printing it. 
> This way it will be pure function and more functional-like. In doseq you'll 
> need (printlng (fuzzy x)) instead of
> (fuzzy x).
>
> Nikita Beloglazov
>
> On Saturday, December 29, 2012 3:35:38 PM UTC+3, Sean Chalmers wrote:
>>
>> Greetings all!
>>
>> I'm just starting out in the so far wonderful world of Clojure and to help 
>> me get started I had a crack at one of my favourites, the FizzBuzz program. 
>> For anyone that isn't familiar with FizzBuzz, it is designed to count from 1 
>> to N and take the following actions when certain conditions are met:
>>
>> When the remainder of i divided by 3 is 0 print "Fizz"
>> When the remainder of i divided by 5 is 0 print "Buzz"
>> When both the former are true of i print "FizzBuzz"
>>
>> I crafted the following as a solution and I would really appreciate some 
>> more experienced Clojurians casting their eye over it and letting me know if 
>> what I've done is in the style and spirit of Clojure. Also this is my first 
>> functional language so any feedback on that would be awesome too. :)
>>
>> I'm aware it's only a tnsy piece of code so not terribly indicative 
>> of the hilarity that might ensue on a larger project but all the same. 
>> Enough of my blathering here is the meaty bit:
>>
>> (defn zero-remainder? [x y]
>>   (zero? (rem x y)))
>>
>> (defn fizzy [x]
>>   (let [fizz (zero-remainder? x 3) buzz (zero-remainder? x 5)]
>> (if (and fizz buzz)
>>   (println "FizzBuzz: " x)
>>   (if buzz
>> (println "Buzz: " x)
>> (if fizz
>>   (println "Fizz: " x))


What about:

(defn fizz [x]
  (str
(when (zero-reminder? x 3) "Fizz")
(when (zero-reminder? x 5) "Buzz")
":" x))

Cheers,

-- 
Laurent

>>
>>
>> (doseq [x (range 1 25)]
>>   (fizzy x))
>
> --
> 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: Unseemingly Eager Clojure Apprentice Seeking FizzBuzz Feeback

2012-12-29 Thread Nikita Beloglazov
Hi

I'd change your fizzy function so it returns a string instead of printing 
it. This way it will be pure function and more functional-like. In doseq 
you'll need (printlng (fuzzy x)) instead of 
(fuzzy x).

Nikita Beloglazov
On Saturday, December 29, 2012 3:35:38 PM UTC+3, Sean Chalmers wrote:
>
> Greetings all!
>
> I'm just starting out in the so far wonderful world of Clojure and to help 
> me get started I had a crack at one of my favourites, the FizzBuzz program. 
> For anyone that isn't familiar with FizzBuzz, it is designed to count from 
> 1 to N and take the following actions when certain conditions are met:
>
>- When the remainder of i divided by 3 is 0 print "Fizz"
>- When the remainder of i divided by 5 is 0 print "Buzz"
>- When both the former are true of i print "FizzBuzz"
>
> I crafted the following as a solution and I would really appreciate some 
> more experienced Clojurians casting their eye over it and letting me know 
> if what I've done is in the style and spirit of Clojure. Also this is my 
> first functional language so any feedback on that would be awesome too. :)
>
> I'm aware it's only a tnsy piece of code so not terribly 
> indicative of the hilarity that might ensue on a larger project but all the 
> same. Enough of my blathering here is the meaty bit:
>
> (defn zero-remainder? [x y]
>   (zero? (rem x y)))
>
> (defn fizzy [x]
>   (let [fizz (zero-remainder? x 3) buzz (zero-remainder? x 5)]
> (if (and fizz buzz)
>   (println "FizzBuzz: " x)
>   (if buzz
> (println "Buzz: " x)
> (if fizz
>   (println "Fizz: " x))
>
> (doseq [x (range 1 25)]
>   (fizzy x))
>

-- 
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: Unseemingly Eager Clojure Apprentice Seeking FizzBuzz Feeback

2012-12-29 Thread Michael Drogalis
Use a cond rather than nesting ifs. Otherwise looks good.

On Saturday, December 29, 2012 7:35:38 AM UTC-5, Sean Chalmers wrote:
>
> Greetings all!
>
> I'm just starting out in the so far wonderful world of Clojure and to help 
> me get started I had a crack at one of my favourites, the FizzBuzz program. 
> For anyone that isn't familiar with FizzBuzz, it is designed to count from 
> 1 to N and take the following actions when certain conditions are met:
>
>- When the remainder of i divided by 3 is 0 print "Fizz"
>- When the remainder of i divided by 5 is 0 print "Buzz"
>- When both the former are true of i print "FizzBuzz"
>
> I crafted the following as a solution and I would really appreciate some 
> more experienced Clojurians casting their eye over it and letting me know 
> if what I've done is in the style and spirit of Clojure. Also this is my 
> first functional language so any feedback on that would be awesome too. :)
>
> I'm aware it's only a tnsy piece of code so not terribly 
> indicative of the hilarity that might ensue on a larger project but all the 
> same. Enough of my blathering here is the meaty bit:
>
> (defn zero-remainder? [x y]
>   (zero? (rem x y)))
>
> (defn fizzy [x]
>   (let [fizz (zero-remainder? x 3) buzz (zero-remainder? x 5)]
> (if (and fizz buzz)
>   (println "FizzBuzz: " x)
>   (if buzz
> (println "Buzz: " x)
> (if fizz
>   (println "Fizz: " x))
>
> (doseq [x (range 1 25)]
>   (fizzy x))
>

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