Every once in a while when I am about to take off, I promptly have my wings cut - these moments have helped shape a rather interesting college life IMO. So, this semester I happened to fall in Jeff Mark Siskind's class EE473 where we studied classical AI (stuff that was outdated by the 80s - I hope). Prof. Siskind insisted on using Scheme as the way to solve problems in his class - which was fine by me since I was rather eager to pick up functional programming and this would serve as ample motivation to do that.
Some salient features of Scheme code I've written so far (not features of scheme but shit "I" do with it):
- Aggressive use of map-reduce. I found this too sexy, I use it everywhere.
- If it compiles, it is most definitely correct (at least I've never had runtime fuck-ups happen to me - this is pretty nice since with some thinking I could accomplish quite a lot in scheme).
- I have very aggressively used lambdas.
Keeping these new habits in mind, I sat down to tackle a p-set yesterday and finished in no time. I then was unable to comprehend the reason why I was so slow compared to the demo of his own solution (I was implementing the arc-consistency heuristic to solve n-queens). Upon investigation, I saw rubbish like this in my code:
(if (null? foo-that-returns-array) (do-new-foo) (do-new-inv-foo))
Well foo-that-returns array was supposed to return a subset of values that satisfied a proposition (from an original finite domain). I totally carried over my rubbish habits from other prog languages ( is #f and [...] is #t so I will continue to use those) rather than doing:
(if (some predicate-function domain) (do-new-foo) (do-new-inv-foo))
This looks a lot better and it was a lot faster. My reasoning for this speed improvement is that I just obtained a rather large array, checked for emptiness and then threw it away causing the scheme GC to kick in. Using
some makes it look a lot more like a quantifier which is precisely how this procedure must be written. This summer, I really need to rock SICP and fix my shoddy half-knowledge situation with regards to functional programming.
Besides that, my research seemed to hit a roadblock close to the end of this semester when a sudden miracle (and a reddit-browsing approach to lit. search) led me to fix things so I can still declare victory. I will not post more about my work since I am applying the Mao approach (is it even Mao? I don't know) - "Keep your head low and rise to the top, then the world will take notice". I have a bad habit of gloating after I post stuff here, it is best if I only put materials here after I finish (and hopefully produce a sexy paper).
Anyway, more posts (better in quality than this) to follow.