Primarily technical blog on Lisp, .NET, C# development.

Wednesday, January 20, 2010

Installing SBCL + SLIME on Ubuntu 9.10

Today I tried to upgrade my lisp environment that is using clbuild to keep track of the packages just to be annoyed by its failure. I was just trying to check how hard it would be to do that in my everyday environment. Because of the failure I decided to try other alternatives. This time I tried Lispy which is is defined as (from their website) http://common-lisp.net/project/lispy/:

"Lispy is a library manager for Common Lisp, written in Common Lisp. All of its dependencies except for GPG (with which signed maps and releases are verified) are written in portable Common Lisp. With this approach you should only need a Lisp implementation installed to get started. The Lispy project has two goals:
  1. Implement an easy to use, portable library manager.
  2. Provide a wealth of ready to install libraries."
 Ok. I liked the concept. I followed their guide and was able to have it working on my sbcl 1.0.29 version alrady installed on the machine. I only had one issue because it couldn't find the gpg key. I had to serach for it using a different server:

$ gpg --keyserver subkeys.pgp.net --search-key 0x7CF49723

All was well but I decided to also get the latest from sbcl (1.0.34) and slime as well.

Installing sbcl was very straight forward and I had no issues. Installing slime however was a pain. I got it from the cvs and I set it up just like the getting started page suggested but I could not get to the slime-repl buffer. So after searching the page for known issue I found this:
 
The REPL moved to a contrib. Instead of (slime-setup), place
(slime-setup '(slime-fancy slime-asdf)) into your ~/.emacs.
 
So I ended up with a different .emacs file then before:
 
(add-to-list 'load-path "your-path-to-slime")
(require 'slime)
(add-hook 'lisp-mode-hook (lambda () (slime-mode t)))
(add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t)))
(setq inferior-lisp-program "sbcl")
(slime-setup '(slime-fancy slime-asdf))
 
Next post I will tell my journey to get a web site running on the good old hunchentoot. 

Wednesday, January 6, 2010

Connecting to a database from Lisp

This is another reminder to myself on how to connect to a database on Lisp using cl-sql through odbcunix.

(use-package :cl-sql)
(connect '("dsn" "user" "password") :database-type :odbc)
(query "select * from table_a")

Friday, December 11, 2009

Ubuntu and FreeTDS

One of the things I have in mind is to be able to connect to a MS SQL database from Lisp in one of my projects. After spending a couple hours searching for a way to get freeTDS and odbcunix to work together, I found this blog in portuguese with a good step by step process.

I have to point out I didn't have to build freeTDS from the source. I got from the repository. I didn't use the tsql tool. Instead I used the isql one. Other than that everything is according to how I proceeded.

How to setup Freetds using Ubuntu

Friday, October 30, 2009

Installing LISP with CLBuild on Ubuntu


http://club-ubuntu.org/blogs/em/getting-started-with-lisp-in-ubuntu

then with your clbuild already installed:

./clbuild update sbcl
./clbuild compile-implementation sbcl
./clbuild install --main-projects
./clbuild install weblocks
./clbuild install cl-prevalence

Monday, October 19, 2009

clbuild and lispbuilder-sdl - update

I retested the latest version of lispbuilder-sdl, updating and recompiling from cl-build and I am glad to say it is working fine, as expected, now.

Always good to spread good news, isn't it?

Friday, August 21, 2009

clbuild and lispbuilder-sdl

On my earlier version of the alarm clock I used the cl-sdl library. I was testing clbuild the other day and I tried to use its version of the sdl: lispbuilder-sdl. Unfortunately on my machine I was getting an error everytime the app was about to close the window due to a call to SDL-glue-SDL-Close-Audio method on the cffi part of the lispbuilder-sdl library:


I suppressed this message by calling a method I knew was working and it worked fine so far.

So if you want to try the same thing, look for the glue.lisp file on the clbuild/source
/lispbuilder-sdl/cffi and change this part to the following code:

#+lispbuilder-sdl-audio

(cffi:defcfun ("SDL_CloseAudio"
SDL-glue-SDL-Close-Audio) :void)

So instead of calling the original method I am using the SDL_CloseAudio and it is working fine so far.

Tuesday, August 18, 2009

Little Alarm Clock in LISP

I wrote this code one of these days because I left the food heating a little too long. I actually burned the pan itself. Anyway it was a little fun project. You give set the time you want it to play a song from your hard drive. Using SDL I was able to play the song and also display a little window to notify about the alarm. You need cl-sdl and cl-sdl-mixer to play the alarm song. If you use ubuntu just install them from the repository using the synaptic package manager.

Here goes the code:

;; Timer

;; Function to return the current time hour and minute in a list
(defun get-time()
(multiple-value-bind (x y z) (get-decoded-time)
(values (list z y) x)))

;; Function to compare if two times are the same
(defun check-time (time-value)
(if (equalp time-value (get-time)) t nil))

;; Function to check if time1 is before time2
(defun before-time-p (time1 time2)
(if (or (< (first time1) (first time2))
(and (equal (first time1) (first time2))
(< (second time1) (second time2))))
nil t))

;; Function to play the alarm song and display the window
(defun play-alarm (song-path)
(sdl:init (logior sdl:+init-audio+ sdl:+init-video+))
(sdl:set-video-mode 320 240 16 sdl:+resizable+)
(sdl:wm-set-caption "Alarm ON!" nil)
(sdl-mix:open-audio 44100 sdl:+audio-s16lsb+ 2 2048)
(let ((music (sdl-mix:load-mus song-path)))
(sdl-mix:play-music music 0)
(sdl:event-loop
(:key-down (key)
(when (= key (char-code #\q))
(progn
(sdl-mix:halt-music)
(sdl-mix:close-audio)
(sdl:quit)
(return))))
(:quit ()
(progn
(sdl-mix:halt-music)
(sdl-mix:close-audio)
(sdl:quit)
(return))))))

;; Function to start the alarm
(defun start-alarm (time-value song-path)
(if (not (before-time-p time-value (get-time)))
nil
(progn
(loop for x from 1
until (check-time time-value)
do (progn (print (get-time)) (sleep 10)))
(format t "~%buzzzzzz... it's ~a:~a~%"
(first time-value)
(second time-value))
(play-alarm song-path))))


; sample usage
;(asdf:oos 'asdf:load-op 'sdl-mix)
;(check-time '(9 38))
;(before-time-p '(12 7) '(12 12))
;(play-alarm "alarm.mp3")
;(start-alarm '(12 15) "alarm.mp3")