Read it Later – Make your browsing a breeze

December 11, 2008

This is a must have. Creating a list of the links to review later instead of opening tabs.

Read It Later

And Behind Door Number 2 Is . . . A Leaky Abstraction

December 11, 2008

Liskov Substitution  Principle (LSP):

Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T.

My Bogus was an attempt to abstract a method by which I could get access to a variable using a syntatic-sugar idiom. The abstraction leaks. Here is how it leaks:

       (with-property (value 24)
         (value :is (incf (value))))
       (assert-equal 25 (value)))

‘incf’ is a destructive operation.

Read the rest of this entry »

Abstraction of an encapsulted property in Lisp

December 9, 2008

Abstraction (computer science): is a mechanism and practice to reduce and factor out details so that one can focus on a few concepts at a time.

If you read Lisp Trick #1, hopefully, you saw a pretty good abstraction. What it was doing was abstracting out the setting and getting a value from a variable. As a bonus, because of the way &key parameter keyword can be used, we were able to differentiate whether you were getting the value or setting the variable. Another bonus is that the variable we are getting and setting is encapsulated.

Usually an abstraction is created with the use of macros. Now I’ve made an even larger abstraction of the setter/getter abstraction.

Read the rest of this entry »

Recursive Tree Rabbit Holes

December 8, 2008
  1. WHY? When using my own home grown object system, I found out that it could not handle keyword parameters.
  2. Problem. Take a parameter list and remove keyword parameters.
  3. Solution. Parse the argument list to the functions, remove and if needed replace keyword.
  4. Example. Need to remove &key and replace with keyword and variable.
    • (a b) => (a b)
    • (a (b)) => (a (b))
    • (&key a) => (:a a)
    • (&key a b) => (:a a :b b)
    • (a &key b) => (a :b b)
    • (a (&key b)) => (a (:b b))

Read the rest of this entry »

Lisp Programming Trick #1

December 7, 2008


How many times have you created two function for setting a specific value and then getting the value?

(let ((value ""))
  (defun property (&key is)
      (is (setf value is))
      (t value)))
  ;;; here is getter and setter functions
  (defun get-property ()
  (defun set-property (data)
    (setf value data)))

(define-test get_set-property
  (assert-equal "" (get-property))
  (assert-equal "property" (set-property "property"))
  (assert-equal "property" (get-property))
  (assert-equal "" (set-property "")))

(define-test property
  (assert-equal "" (property))
  (assert-equal "property" (property :is "property"))
  (assert-equal "property" (property))
  (assert-equal "" (property :is ""))

Using a &key keyword parameter adds syntatic sugar to setting properties. It also means less typing.

It is done with a conditional. Another benefit is that behavior for the property is located in only one function instead of two functions.

New Use Case

(Zach Beane’s Request)

Need to be able to set the property to nil. Added the test to my unit tests. It failed. Modified the code and now it passes.

You just need to add a supplied-p parameter.

(let ((value ""))
  (defun property (&key (is nil is-p))
      (is-p (setf value is))
      (t value))))

(define-test property
  (assert-equal "" (property))
  (assert-equal "property" (property :is "property"))
  (assert-equal "property" (property))
  (assert-equal "" (property :is ""))
  (assert-equal nil (property :is nil)))

Happy Lisp Cargo-Culting!

Genetic Algorithms – Lisp Style

December 5, 2008

I ran across this post, Prototyping Genetic Algorithms in Lisp.

Check it out. It looks to be more along the lines of Genetic Programming than Genetic Algorithms.

His code looks really good. Very readable! The methods are small, a sign of well factored code.

Event Driven Architecture Programming in Lisp Part 2

December 4, 2008

References for our discussion:

Requirements for our EDA:

  • Storage of events to be executed when events triggered.
  • Events.
  • Push/Pull Model.
  • Broadcast of events. One trigger can execute more than one handler.
    • Ex. When User Clicks Save Button, data is saved and the event is logged as executed.

Read the rest of this entry »