Tuesday, July 06, 2010

Creating PDF files from Common Lisp

The CL-PDF library allows you to create PDF files directly from common lisp. The easiest way to use cl-pdf (or for that matter many other libraries) is to download and install LibCL. CL-PDF comes with LibCL and makes the installation a snap.

I have a hello world pdf program written.
Just run this and it will generate a PDF with a big Hello World!

Monday, July 05, 2010

SICP on the iPAD

SICP in ePub format

If you want to read SICP (and you should!), on the iPad, then you are in luck. The digital format is old school HTML pages generated from texinfo. While there is nothing wrong in that format per-se, it just doesn't allow you read this wonderful book on an iPad (or another other tablet for that matter).

iBooks uses ePub as the ebook format. Just download SICP in ePub format from here (Ian Eure's git tree), add it to your iTunes library and sync. That's it. 

The link shared above is a git tree on github and it's always nice to fork and fix any issues that you find. The actual download link is also present on the github project.

SICP on other devices

If you have a Kindle, then Jonathan Patt's sicp-kindle git tree on github is the place to go. I don't know much about Kindle (don't have one), and instructions are from http://irreal.org/blog/?p=274

PDF version

Finally, there is always the PDF version that you can download from http://sicpebook.files.wordpress.com/2012/11/sicp.pdf

Paperback Edition of the SICP

Of course, another option is to get the dead wood edition from MIT press directly - http://mitpress.mit.edu/books/structure-and-interpretation-computer-programs. Then again, having a paperback or hardcover is nice if you have a personal library shelf. I learnt that this can be a pain esp. when moving/changing houses because you will need to pack everything up and unpack them once you are in your new place.

Sunday, April 25, 2010

The smallest h264 encoder

Nice post on the smallest h264 encoder. Obviously it doesn't really do anything other than just add the right NAL header information.

Thursday, April 01, 2010

Cross compiling TCL for ARM

Refer http://objectmix.com/tcl/15449-how-cross-compile-tcl8-4-tk8-4-arm-linux.html

Also change the Makefile. Replace "./tclsh" with "tclsh". That way we run the build system's tclsh to install rather than the freshly built tclsh.

Sunday, January 31, 2010

Thinlisp

Came across Thinlisp today while browsing cliki. Sounds interesting - develop in CL and then deploy in C. Its similar to ECL in the way of using C as a bridge but in reality its completely different. ECL is a CL implementation that uses C as a compiler. Thereby you can generate very small and very efficient standalone executables.

Thinlisp on the other hand, is supposed to work on any CL implementation. It uses CL to generate C. It works with a subset of lisp and doesn't support any garbage collection. I had a look at it today, its pretty old. The code looks like its been abandoned by Gensym. Nevertheless, I decided to give a try. Will post results as I get going it with, but I do expect some amount of bit-rot. Vladimir Sedach seems to have hacked at it a few years back, and has posted tarball. That would be my starting point.

Saturday, January 16, 2010

functions in plists

Common Lisp Plists are easy. A plist is just a list with properties. Any element with ":" prefixed is a property. The next element to a property is its value. We can then manipulate the plist using functions such as getf and setf. We give the property name to getf/setf and they fetch/set the appropriate property.

Here's a simple plist
'(:name "sid" :language "lisp")

Now, if we want to put in a function in the plist as a value, then the quote will not work.
'(:name "hello" :function (lambda () (format t "Hello World~%"))) ; Bad

The correct way is to backquote the plist and comma-escape the lambda.
`(:name "hello" :function ,(lambda () (format t "Hello World~%"))) 


We can then extract the function using getf and then finally call it using funcall. If we want to use an existing function, then we need to not only comma-escape but also add a #' so that the reader knows that a function symbol follows.

In C the equivalent would be to have a struct with a function pointer. What makes Lisp cool is that
  1. You can define an anonymous function in the plist itself
  2. You can have functions with different arity, inputs etc.. all in a list of plists. Lisp won't complain, but in C, the function pointer needs to be function of a particular signature only.
  3. Lisp also allows you to define structs which are more powerful than just plists, but a plist is good enough for this example.

Thursday, January 14, 2010

SBCL - FASL files

One aspect of SBCL that you *will* run into if you upgrade, is that older FASL files will no longer load. SBCL ties the FASL format to a specific version. That means that you recompile all the files when you upgrade. The manual gives a convienent snippet if the files are using ASDF.