You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After presenting the function can-move?, you wrote this:
Second, you use comp to compose this function with not-empty. This function is self-descriptive; it returns true if the given collection is empty and false otherwise.
But it seems that it is wrong, because from official Clojure's docs, the function not-empty return nil if the collection is empty, and collection otherwise.
For reference, this is the function that I am talking about:
(defncan-move?"Do any of the pegged positions have valid moves?"
[board]
(some (comp not-empty (partial valid-moves board))
(map first (filter #(get (second %) :pegged) board))))
Also, I wanted to say thank you for writing this great book. I am really enjoying it and learning a lot!
The text was updated successfully, but these errors were encountered:
Funny enough, due to the implementation of valid-moves, if a position doesn't have a valid move, the result is nil, not an empty collection. So as far as I can see, composing not-empty is doing nothing.
Odder yet some is a function that returns the first truthy value in a collection, meaning the return type of can-move? will not be boolean, but a truthy value (in this case, the first position found that can still be moved to) or nil. I'm new to Clojure, but I thought functions ending in ? are generally supposed to either return true or false. Again, I could be wrong, but it just seems inconsistent.
Hi Daniel,
After presenting the function can-move?, you wrote this:
But it seems that it is wrong, because from official Clojure's docs, the function not-empty return nil if the collection is empty, and collection otherwise.
For reference, this is the function that I am talking about:
Also, I wanted to say thank you for writing this great book. I am really enjoying it and learning a lot!
The text was updated successfully, but these errors were encountered: