Skip to content

unCLog

These are the stories that have been posted to the unCLog blog.

How have I used advice?


Published to unCLog by Gary King December 14, 2007 17:51

People have often told me I could use some advice. I say “but I use it all the time”. Ba da bing.

Humor aside, the Common Lisp Advice Facility lets you wrap (and unwrap) new code around old code dynamically even if you don’t have the source for the old code. This is an incredible feature for doing all kinds of useful things. (It’s also an amazing feature for tying yourself up in a maze of little passages, all alike. In other words, “with great power comes great power, so be careful.”

It can be nice to know how many times a function has been called, that’s why profilers usually allow you to get call counts! Sometimes, however, going through the trouble of messing with a profiler and getting its information back out in a useful fashion is more trouble that seems necessary. Enter with-call-counts. The complete code is below (though it relies on Franz’s (excellent) fwrapper machinery, the idea is the same).

;; a bizarre hack in search of a dream
;; It's a lot of machinery to count a single functions calls... but it's cool!
(defvar *call-counter* (make-hash-table))

(excl:def-fwrapper call-counter (&rest args)
  (declare (ignorable args)
       (dynamic-extent args))
  (%count-call (%find-call-counting-spot excl::primary-function))
  (excl:call-next-fwrapper))

(defun start-call-counting (function &optional (reset? nil))
  (bind ((spot (%find-call-counting-spot function)))
    (setf (second spot) t)
    (when reset? (reset-call-counting function))
    (excl:fwrap function :call-counter 'call-counter)))

(defun reset-call-counting (function)
  (setf (first (%find-call-counting-spot function)) 0))

(defun stop-call-counting (function)
  (setf (second (%find-call-counting-spot function)) nil)
  (excl:funwrap function :call-counter))

(defun call-counts (function)
  (values-list (%find-call-counting-spot function)))

(defun %find-call-counting-spot (function)
  (setf function (coerce function 'function))
  (bind (((values spot found?) (gethash function *call-counter*)))
    (if found? 
    spot
    (setf (gethash function *call-counter*) (list 0 nil)))))

(defun %count-call (spot)
  (incf (car spot)))

(defmacro with-call-count ((function &key (resetp t)) &body body)
  (with-gensyms (gfunction gresetp)
    `(let ((,gfunction ,function)
       (,gresetp ,resetp))
       (unwind-protect
        (progn
          (start-call-counting ,gfunction ,gresetp)
          (progn ,@body)
          (list (intern ,gfunction :keyword) (call-counts ,gfunction)))
     (stop-call-counting ,gfunction)))))

(defmacro with-call-counts (((&rest functions) &key (resetp t)) &body body)
  (with-gensyms (gresetp)
    (cond ((null functions) `(list :result (progn ,@body)))
      (t `(let ((,gresetp ,resetp)
            (this nil)
            (rest nil))
        (setf this
              (with-call-count (,(first functions) :resetp ,gresetp)
            (setf rest 
                  (with-call-counts (,(rest functions) 
                          :resetp ,gresetp)
                ,@body))))
        (nconc this rest))))))

The with-call-count macro is the heart of the above. Like most macros of this sort, it expands into an unwind-protect and some function calls to turn call counting on and off. The start-call-counting function adds an fwrapper and stop-call-counting removes it. The wrapper itself (created with the excl:def-fwrapper) is simple: it run before the wrapped function and just increments a counter. Finally, the with-call-counts macro expands into multiple applications of with-call-count.

I’m not completely happen with the syntax of the machinery above but I’m happy enough that I’ve used it many times in debugging and testing. It’s nice to be able to:

  • ensure that a cache is actually working by counting the number of calls to some inner function with the cache off and on.
  • check that some function isn’t being called or that it is!
  • check that a binary search is really calling its comparison function the expected number of times.

Because advice makes writing macros like the above easy and because macro like the above make it easy to measure whats happening in your code (without, notice, modifying your code), it’s a big win!

ick - airblasting brain tissue…


Published to unCLog by Gary King December 14, 2007 18:24

From Harper’s Index

eleven slaughterhouse employees in Austin, Minnesota, were diagnosed with chronic inflammatory demyelinating polyneuropathy, a rare neurological disorder that they appear to have contracted as part of their work airblasting brain tissue from pig heads in order to get at the meat.

Is Lisp hard? (I don’t think so…)


Published to unCLog by Gary King December 14, 2007 16:37

I was reading Justin James TechRepublic weblog and came across this statement:

… a few rock stars might be able to blast out some insanely awesome system in three months using Lisp, but it will typically take a dozen average programmers 18 months to trudge through it in Java, VB.NET, or C#.

This feels like a familiar sentiment to me (I’ve been out of the “trenches” for a while but that was certainly the sort of thing I used to hear bruited about). It’s part of the “we’d like to do it in Lisp (or Scala or whatever) but we need to be sure that we can hire people…” meme.

But really, is Lisp hard? Is it harder than doing OO right? (Interestingly, James has another blog post complaining that most people are doing OO wrong). Lisp does require different skills than Java or C#. At least it does if you want to take advantage of what makes Lisp Lisp and use macros to their fullest. It’s also true that the lack of tools and libraries can be problematic (yes, there are libraries but nothing like what you can find in some other languages (and yes, many of those other libraries are junk but … that’s not my point so I’m going to ignore it) — at least I’m honest :) ).

I think the “Lisp is hard” idea is general bunk. It’s different and looks funny (but, hey, if you can stomach C++, what can’t you take!) but getting started in Lisp is no harder that any other language. In fact, its easier to get started in Lisp than it is in programs that require a separate compilation step.

> (defun hi-there () (print "hello world"))
==> #<function hi-there>
> (hi-there)
"hello world"
==> "hello world"

Still, it’s going to take a lot of work of some sort to start convincing people otherwise. Perhaps part of the problem is that Lispers like hearing the meme because we can pat ourselves on the back and say “that’s right, I Lisp, I smart. Me super-coder.”

Announce: moptilities 0.3.8, asdf-binary-locations 0.2.5


Published to unCLog by Gary King December 14, 2007 00:16

Thanks to KrewinK for sending in a patch to let moptilities’s copy-template function correctly handle class allocation slots. Thanks to the patch and a few fixes in the actual tests, moptilities now passes all of its tests!

I’ve also updated ASDF-Binary-Locations to version 0.2.5. The only code change is that I’m exporting implementation-specific-directory-name. I’ve also added a user’s guide.

More of the voices I’m hearing in my head…


Published to unCLog by Gary King December 14, 2007 01:23

IT Conversations and the Conversations Network keep my brain happy…

  • Moira Gunn talks with Sandra Blakeslee about her book the Body Has a Mind of Its Own: How Body Maps in Your Brain Help You Do (Almost) Everything Better. It’s a wonderful conversations about neuroscience and cognitive maps. Blakeslee (a science writer) does a wonderful job conveying the excitement and joy of discovery. Recommended.

  • Moira Gunn also has a nice conversation with John Thackera, a designer and writer. His most recent book, In the Bubble, discusses how we can try to break out of our self-imposed design limitations and see a bigger picture. I’m reading the book now and its a fun read with a very European slant on tools and technology. Its inspiring to hear of the many things that people are doing right (there and here in my somewhat benighted USofA). Aside from an occasionally too informal riff, Thackera’s prose flows nicely with a excellent mix of insight, quotations, examples and analysis. Both the interview and the book are recommended.

  • I also recently heard a far less interesting interview with Morgan Gillis, the executive director of the LiMo Foundation. I guess the excitement of Mobile Linux and a new cell phone platform just goes through my head…

  • Finally, I heard a wonderful interview between Tom Parish (the host) and Jake McKee. McKee used to work at Lego and has gone on to focus on social media and customer interaction: the creation of community in support of selling product. He has some great points to make about how to do this honestly and with integrity — indeed, you can’t succeed in this sort of endeavor unless you loads of both! He comes to the table with great background and experience and really makes his points well. Recommended.

Finally Leopard


Published to unCLog by Gary King November 28, 2007 03:42

I finally upgraded to Leopard last night… everything is snazzy and nice. I’m happy! (Though I wise I had a Core Duo 2 for 64-bit goodness).

Interview with Peter Higgs


Published to unCLog by Gary King November 27, 2007 17:54

The Guardian has a nice interview / story about Peter Higgs, nuclear physics and the search for the Higgs boson.

Announce: meta! updates


Published to unCLog by Gary King November 25, 2007 20:10

There isn’t anything exciting below but minor tweaks are good for the soul.

  • metabang-bind goes to 0.6.2

    • Found and fixed a glitch in the destructuring code (don’t call package-name unless you’re sure you have a symbol :)).
  • CL-Markdown goes to 0.9.2

    • Improved docstring printing in the HTML
    • Added a bit more documentation
  • Cl-Graph goes to 0.8.4

    • Brought files up to whatever my current sense of stylistic conventions is
    • Added a few more tests (there are still some that fail).

IT Conversations to the rescue


Published to unCLog by Gary King November 24, 2007 02:04

Here’s what I listened to last week while doing a lot of driving…

  • Technometria: Exploiting Online Games - Gary McGraw (co-author of Exploiting Software) talks about MMORPGs, cheating, social situations, etc. Fun and intriguing; not too deep.

  • The Singularity: A Period Not An Event - Rod Brooks (of iRobot — did you know that they make a gutter cleaning robot now…) speaks sensibly about the putative singularity. Finally.

  • David Heinemeier Hansson gives the Rails Keynote - As a Lisper, I find the success of things like Ruby and Ruby on Rails really maddening (smile). They’ve done a great job tuning nice ideas into successful tools and getting those tools out into the world. From where I stand, Lisp continues to do wonderfully at building successful tools but we’re far less skilled (as a community) in getting these out into the world!

Happy hearing.

Is the semantic web social?


Published to unCLog by Gary King November 23, 2007 19:05

Tim Berners Lee talks about the Giant Global Graph (a term that I hope doesn’t have lets… GGG, ugh!).

TBL gets a nice comeback from Anne Zelenka on GigaOM (which sounds like some sort of massive meditation site :)):

The semantic web has always been about computers taking on more processing for us, not about computers allowing us to be more human, which is where the social graph might more naturally aim.

But just like social intelligence is not a subset of academic intelligence, social knowledge and understanding isn’t a subset of the semantic meaning that semantic web technologies like RDF and SPARQL are aimed at representing.

The Semantic Web is a good step towards representing more of what we need to know to help computers help us, but it’s only a step.