June 4, 2010

at Friday, June 04, 2010 Labels: , Posted by Billy 0 comments

Many people unfamiliar with Common Lisp believe it's a purely
functional language, but this is untrue. While you can shape your
Common Lisp programs in a functional way, Common Lisp also support
Object Oriented Programming via CLOS, the Common Lisp Object
System. It is truly a multi-paradigm language.

This books teaches all the aspects of CLOS, and although written
several years ago, the knowledge still applies today. After learning
about Object Oriented programming using languages like C++ and Java,
learning about CLOS really opened my eyes to what this style of
programming should feel like. All the other languages now seem to
constrained compared to the power and flexibility of CLOS.

In CLOS, classes only have member variables, called slots, and support
multiple inheritance. They do not define methods. Instead, methods are
defined for Generic Functions which specialize on the classes. While
most OO languages use single dispatch, meaning methods specialize on
only one class, CLOS uses multiple dispatch. It also supports
specializing on distinct object instances. In addition to primary
methods, CLOS has before, after and around methods. You can even
dictate the order in which CLOS calls all of the applicable methods.

I truly enjoyed this book as it expanding my understanding of object
oriented techniques. I hope the mainstream language designers can take
the time to read this and incorporate more of CLOS into today's
popular, but limited, object oriented systems.

May 31, 2010

;;; SICP Section 3.1

;;; 3.1
(defun make-accumulator (n)
  (lambda (x)
    (incf n x)))

;;; 3.2
(defun make-monitored (f)
  (let ((count 0))
    (lambda (x)
      (cond ((eq x 'how-many-calls?) count)
     ((eq x 'reset-count) (setf count 0))
     (t (incf count)
        (funcall f x))))))

;;; 3.3 and 3.4 - updated for 3.7
(defun make-account (balance password)
  (let ((consecutive-attempts 0))
    (labels ((withdraw (amount)
        (if (>= balance amount)
     (setf balance (- balance amount))
     "Insufficient funds"))
      (deposit (amount)
        (setf balance (+ balance amount)))
      (dispatch (pass m)
        (cond
   ;; Incorrect password?
   ((not (eq pass password))
    (lambda (x)
      (if (<= 7 (incf consecutive-attempts))
   "Calling cops"
   "Incorrect password")))
   ;; Withdrawing?
   ((eq m 'withdraw)
    (setf consecutive-attempts 0)
    #'withdraw)
   ;; Depositing?
   ((eq m 'deposit)
    (setf consecutive-attempts 0)
    #'deposit)
   ;; Creating joint account?
   ((eq m 'joint)
    (lambda (new-pass)
      (lambda (pass m)
        (if (eq pass new-pass)
     (funcall #'dispatch password m)
     (funcall #'dispatch nil m)))))
   (t (error "Unknown request -- MAKE-ACCOUNT")))))
      #'dispatch)))

(defun withdraw (acc pwd amt)
  (funcall (funcall acc pwd 'withdraw) amt))

(defun deposit (acc pwd amt)
  (funcall (funcall acc pwd 'deposit) amt))

;;; 3.5
(defun random-in-range (low high)
  (let ((range (- high low)))
    (+ low (random range))))

(defun monte-carlo (trials experiment)
  (labels ((iter (trials-remaining trials-passed)
      (cond ((= trials-remaining 0)
      (float (/ trials-passed trials)))
     ((funcall experiment)
      (iter (- trials-remaining 1) (+ trials-passed 1)))
     (t
      (iter (- trials-remaining 1) trials-passed)))))
    (iter trials 0)))

(defun in-circle-p ()
  (let ((x (random-in-range 0 1.0))
 (y (random-in-range 0 1.0)))
    (<= (+ (expt (- x 0.5) 2)
    (expt (- y 0.5) 2))
 (expt 0.5 2))))

(defun estimate-integral (p x1 x2 y1 y2 trials)
  (let ((area-of-rect (* (- x2 x1)
    (- y2 y1)))
 (frac-inside (monte-carlo trials p)))
    (* frac-inside area-of-rect)))

;;; 3.6
(let ((st (make-random-state)))
  (defun rnd (sym)
    (cond ((eq sym 'generate)
    (lambda (x)
      (random x st)))
   ((eq sym 'reset)
    (lambda (x)
      (setf st x)))
   (t "Unknown symbol"))))

;;; 3.7
(defun make-joint (acc pass new-pass)
  (funcall (funcall acc pass 'joint) new-pass))

;;; 3.8
(let ((num 1))
  (defun f (n)
    (setf num (* num n))))

May 25, 2010

at Tuesday, May 25, 2010 Labels: Posted by Billy 1 comments

I recently updated to Ubuntu Lucid and immediately noticed UI performance degradation after using it for a short while. The sluggish performance affected window switching and scrolling in Firefox/Chrome/Evince etc. Nothing on my system indicated a memory leak or chewed-up processor.

I searched Ubuntu's bug tracking system and came across this post, which indicated the using the latest kernel version fix the problem. After following the steps here to update my kernel, my system runs as fast as ever. Hopefully other users experience my situation will stumble across this post and find it helpful.

May 22, 2010

at Saturday, May 22, 2010 Labels: Posted by Billy 0 comments

The Selfish Gene does a marvelous job explaining the core concepts of
evolution for the lay person. It begins with the predominate theory of
how life began in the primordial soup. It then explains how the first
replicators became the genes that make up our DNA and how the natural
environment shapes evolution by pruning the most adaptive and
advantageous of those genes.

Genes are responsible for manufacturing organisms to help them
replicate. They affect not only its own organism, but the surrounding
environment and other organisms. The book explains how the genes
affect the organisms behavior, and how the behavior of a population of
species follows an Evolutionary Stable Strategy (ESS). The book's
title refers to the concept that genes are really looking after
themselves first, but it also explains how altruistic behavior can
arise from the gene's selfishness. The author adamantly proposes that
we are the first species that can defy our genes and oppose the
ruthless nature of natural selection to make the world a better,
friendlier place.

It worries me that many people are ignorant of evolution. Never once
did my high school offer a class on the topic. In my opinion, everyone
should be familiar with the concepts because I believe it's important
to know how we came to be. I recommend this book to everybody.

May 8, 2010

at Saturday, May 08, 2010 Labels: , Posted by Billy 0 comments

Practical Common Lisp has turned into the de facto standard for beginners who want to learn Common Lisp, and deservingly so. The opening chapters delve right into the development style of Common Lisp and show how it differs from more mainstream languages. It covers all the basics and more, eventually leading into chapters explaining how to parse MP3 files and create and create an MP3 Shoutcast server from scratch.

Common Lisp is my favorite language to develop in, but most people I talk to dismiss it as being too old and irrelevant for today's computer applications. I highly disagree. The fact that the language is old is actually one of it's strengths: every design decision seems so well thought out. I've had numerous moments where I commented to myself "you know, it would be nice if this function could do this," and then discovered that it could after reading the documentation. And the development environment is the best out there. The Slime/Emacs/Lisp combination is way ahead of Visual Studio in terms of interactivity, customization, jumping through source files and debugging.

I recommend this book to all developers out there, as learning Common Lisp helped me in my day job as well. At least read through the chapter on creating a unit test framework to get a feel of what software development should be like.

April 24, 2010

at Saturday, April 24, 2010 Labels: Posted by Billy 0 comments

I never have done much reading about psychology before so I thought this book would be a good change of pace for me. The book was easy to read and covered the general ideas about how evolution cause major deficiencies in our brains. Most people don't realize how imperfect we actually are, but just by learning about it we can avoid certain downfalls that all people are prone too.

It was a quick and enjoyable read, but I didn't learn a whole lot from it, probably because I read much about evolution before. Still, I recommend this book for all non-psychology students so they can better understand who they are.

April 11, 2010

at Sunday, April 11, 2010 Labels: Posted by Billy 0 comments

Set in the 1800s, the Piano Tuner is a well written novel about an ordinary man who journey's to the remote jungles of Burma on an odd mission from the British military. There he experiences sights and sounds that he had never seen before, met many interesting people and discovered a source of excitement that was missing from his bland life.

Without revealing any spoils, I found the ending of this book highly engaging, but it still served as a poor penance for the uneventful, unexciting story leading up to it. I found the main character lacking any charm or personality whatsoever. In a sense, I found him distasteful and selfish for leaving his wife behind while seeking adventure. And all through his journey, he did nothing to change his attitude, nothing to prove his worth as a character who deserved respect and admiration.

Though I dislike giving negative reviews, I cannot recommend this book to anyone, but I'm sure others will have different opinions.