Hi,
I am not an expert :)
I haven't heard of this repo or even understand what the exercises are.
Nonetheless, based on what you wrote, some simple changes (to possibly make
it more idiomatic?),
(< x 0)
use (neg? x)
(if (= (mod n divisor)0)
> true
> false))
use (= (mod n divisor) 0) ... `=` returns a boolean value.
(defn abs [x]
I don't understand what the point of this function is. If one can use a
built-in function `mod` to test divisibility, why can't one use the Java
function `Math/abs` to implement `abs`?
(not (teen? age ))
`((complement teen?) age)` ... I personally find `complement` forms easier
to read than `not`. And its better than doing `((comp not teen?) age)`
(divides? 5 n )
Maybe it's just me, but it reads like I am checking whether 5 is divisible
by n. I rather prefer `(divisible? n d)`. Creating a standalone
`divisible-by-5` function is just as easy. Anyway,
(defn leap-year? [year]
> (cond
> (not(divides? 4 year )) false
> (not(divides? 100 year)) true
> (not(divides? 400 year)) false
> :else true
> ))
It took me a while to mentally verify the logic. I feel the code becomes
easier to grok, if you invert the predicates, ie instead of checking for
negation of a condition, just check for the condition.
(defn leap-year? [x] (cond (divisible? x 400) true (divisible? x 100) false
(divisible? x 4) true :else false))
or
(defn leap-year?
[x]
(cond (divisible? x 400) true
(and (divisible? x 4)
((complement divisible?) x 100)) true
:else false))
Can a year be negative or zero? If not, then maybe a pre-condition check
for positive numbers?
(defn generic-doublificate [x] ...
Without understanding what this function is supposed to do, I can't comment
on it. As such, one rarely needs to check if an argument is a list or a
vector. In this case maybe a better check would be `sequential?`. Maybe,
you were supposed to implement it using multi methods. One method for
`number?`, one for `coll?` and a default implementation. The `coll?`
implementation handles the cases for empty collection, sequential
collection and any other case. That said, what does this method have to do
with booleans?
On Monday, 31 August 2015 23:59:21 UTC+5:30, r/ Wobben wrote:
> Hello,
>
> I did solve the boolean chapter of the ilovehorses git repo.
> My solutions can be found here:
> https://github.com/rwobben/i-am-a-horse-in-the-land-of-booleans/blob/master/src/i_am_a_horse_in_the_land_of_booleans.clj
>
> Any experts who can give me feedback about the solutions so I can learn
> from it.
>
> Roelof
>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.