Patrick (patrickwonders) wrote,
Patrick
patrickwonders

  • Mood:

Debugging Woes...

I spent way too much time today debugging the difference between these two lines of code:

(defconstant +look-up+ #( '() '(:foo) '(:bar) '(:foo :bar) ))
(defconstant +look-up+ #(  ()  (:foo)  (:bar)  (:foo :bar) ))

Specifically, I was doing something like this:

(defun decode-flags ( flags )
   (elt +look-up+ flags))

(defun somewhere-else ( my-flags )
   (when (member :foo (decode-flags my-flags))
      (do-something-spectacular)))

I had written the first (defconstant ...) line. It didn't work at all. I thoroughly checked and rechecked all other aspects of my program. I thought I was thoroughly checking the results of decode also. It turns out though that unless you're very keen, you don't really think much of the extra quote mark in the output of the (decode-flags ...) routine.

Essentially though, rather than (decode-flags ...) returning a list that contains :foo for example, it returns a list which contains the symbol QUOTE and a sub-list which contains :foo. Oops.

Almost two years in, I am still getting used to when I have to quote things and when I don't. This is especially difficult when it comes to type-specifiers. *shrug*

Tags: lisp
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

  • 0 comments