7 Comments On This Entry

Nice. I don't know if you've realized it, but your example is fairly functional code. You're creating new instances of things rather than mutating them, and you're iterating through collections instead of using for loops and the like. I know you're interested in Clojure, so here is how I would implement this in Clojure:

I'm using clj-time which is a wrapper around joda-time. Unfortunately, clj-time doesn't wrap most of what I needed here, so I ended up calling out to the joda API directly, but that wasn't any trouble at all, as you can see. My implementation is very similar to yours. Note that in Clojure, 'for' isn't a for loop, but is a list comprehension. Wikipedia can be helpful if you don't know what that is.

If you just want a list of all the business days in the month (and not just the number of them), you can just remove the call to count in the code. If I were providing this function as part of an API, I'd do that, because it's more useful to have a list of all the days than to have the number of them, and it's easy to derive the number of them from the list (by calling count).

The 'd' is just an identifier I used. I could have named it 'cheese' or 'blue' or 'skyline'. What's happening is I'm iterating through each object in the collection Enumerable.Range() and referencing each item by the identifier 'd' inside of the Where clause ONLY.

0 user(s) viewing

0 Guests0 member(s)0 anonymous member(s)

About Me

Bienvenidos! I'm a USA ex-pat living in Bolivia for the past 10 years. Web development is my forte with a heavy lean for usability and optimization. I'm fluent in both English and Spanish. I guest write for the popular Python website Python Central. Visit my website.