Common Lisp libraries for Yahoo! APIs

I was reading some essays about Common Lisp and came across a few interesting libraries for accessing some of Yahoo’s Web Services APIs:

In the case of cl-delicious, it was a little harder to install (into SBCL on my Ubuntu Edgy system), as the author’s site has a bzipped file instead of the gzipped file that ASDF-Install expects.

~/.sbcl/site$ wget http://jarrodkoehler.com/cl-delicious/cl-delicious-0.1.tar.bz2
~/.sbcl/site$ tar -xjf cl-delicious-0.1.tar.bz2
~/.sbcl/site$ cd ../systems
~/.sbcl/systems$ ln -s ~/.sbcl/site/cl-delicious/cl-delicious.asd .

Now, at this point, I was running the current SBCL version from the Ubuntu Edgy repository and this version of SBCL seems to have a slight problem with the cl-delicious.asd file so I had to do:

~/.sbcl/systems$ vim cl-delicious.asd .     # Remove the line with LICENSE

It seems that upgrading to the release version of SBCL from the SBCL web site (1.0.2 as of this writing) also solves the problem and is perhaps a preferable solution.

and then

~/.sbcl/systems$ sbcl

or if you prefer, fire up Emacs and SLIME.

and then

CL-USER> (asdf:operate 'asdf:load-op 'cl-delicious) 
...(a bazillion messages about loading and registering)...

and now you’re ready to do stuff, as shown in the cl-delicious page:

CL-USER> (in-package :cl-delicious)
#<PACKAGE "CL-DELICIOUS">
CL-USER> (defparameter *du*                                                                                                    
           (make-instance 'delicious-user                                                                                      
                          :username "user"                                                                                     
                          :password "password"))
*DU*
CL-DELICIOUS> (recent-posts *du* :count "2")
(#S(POST
    :HREF "http://www.cs.indiana.edu/dfried_celebration.html"
    :DESCRIPTION "Daniel P Friedman: A Celebration"
    :EXTENDED NIL
    :HASH "9821f03f10279cad407aa8b2e5c2bef1"
    :OTHERS NIL
    :TAG "programming video"
    :TIME "2007-02-22T23:06:22Z")
 #S(POST
    :HREF "http://www.math.gatech.edu/~cain/textbooks/onlinebooks.html"
    :DESCRIPTION "Online texts"
    :EXTENDED NIL
    :HASH "79b0c74c3d2941dbd57ac922b471e781"
    :OTHERS NIL
    :TAG "math books"
    :TIME "2007-02-22T20:50:26Z"))

It was easier to install cl-yahoo.

CL-USER> (asdf-install:install 'cl-yahoo) 

However, I ran into problems getting Web search to work:

CL-USER> (asdf:oos 'asdf:load-op :cl-yahoo)                                                                                    
NIL                                                                                                                            
CL-USER> (use-package :cl-yahoo)                                                                                               
T                                                                                                                              
CL-USER> (ysearch :web :query "lisp" :type 'any :results 2)
                                               
XML parser encountered eof before end of entity.                                                                               
   [Condition of type S-XML:XML-PARSER-ERROR]                                                                                  
                                                                                                                               
Restarts:                                                                                                                      
 0: [ABORT] Return to SLIME's top level.                                                                                       
 1: [TERMINATE-THREAD] Terminate this thread (#)                                               
                                                                                                                               
Backtrace:                                                                                                                     
  0: (S-XML::RESOLVE-ENTITY                                                                                                    
      #<SB-SYS:FD-STREAM for "a constant string" {B477469}> >                                                                  
      "invalid value: uri - http://api.search.yahoo.com/WebSearchService/V1/webSearch?"                                        
      #<HASH-TABLE :TEST EQUAL :COUNT 6 {B47C031}>                                                                             
      "appid=cl-yahoo&query=lisp&type=any&results=2&start=3&adult_ok=1</Message>^M                                             
     ^M                                                                                                                
     <!-- ws02.search.scd.yahoo.com uncompressed Sat Mar  3 16:16:03 PST 2007 -->                                         > 
     ")                                                                                                                        
  1: (S-XML::PARSE-TEXT                                                                                                        
      #<SB-SYS:FD-STREAM for "a constant string" {B477469}>
...

I guess I’ll email the author about that.

Lisp: UnCommon Web framework now easily installable

A few months ago, while I was on a Lisp kick, I looked into installing and trying the UnCommon Web framework but I was put off on how difficult it was to install.

Well, it looks like some folks have worked to make it easy to install. At this nice page, they offer a UCW “boxset”, which you untar and it has everything you need to get going. I tried it and it worked like a charm with sbcl on Ubuntu. The same page offers a tutorial, which looks good, but I haven’t tried it yet.

Scsh: Scheme shell

If you are a fan of programming with Scheme, then you might like Scsh. Actually the name seems like a bit of a misnomer to me, since:

  • Scsh is not a comfortable interactive shell a la bash (though apparently some work is done on one called Commander S; no public release yet though).
  • Scsh has more power than shell script because there are functions for opening sockets and such, so it’s probably more comparable to Perl than to Bourne shell.

To give you the flavor of what it looks like, here’s a snippet of awk and the corresponding scsh, which I stole from here:

;;; Copy IN to OUT, prefixing each line with a timestamp,
;;; or, as we say in AWK,
;;; awk '{"date '"'"'+%b %e %T'"'"'" | getline d; 
;;;      close("date '"'"'+%b %e %T'"'"'"); print d, $0}'
;;;
;;; Quiz: why is the close() necessary?
;;;     -Olin 
;;;      May 1997

(define (add-date in out)
  (while (not (eof-object? (peek-char in)))
    (format out "~a ~a\n"
	    (format-date "~b ~d ~H:~M:~S" (date)) ; E.g., "Sep 3 22:43:11"
	    (read-line in))))

Of course the strength of Bourne shell is that it’s on every Unixy machine out there and Scsh is on, well, a few Scheme hackers’ machines.

links for 2006-10-17