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

Showing posts with label lisp. Show all posts
Showing posts with label lisp. Show all posts

Thursday, May 13, 2010

Lisp style

Consider the following snippets of code:


(let ((probed-path)
(not-found t))
(dolist (registry-expression asdf:*central-registry*)
(when not-found
(setf probed-path (eval registry-expression)))
(when (probe-file (merge-pathnames "asd-library.asd" probed-path))
(setf not-found nil)))
probed-path)

(first (remove-if #'null
(mapcar #'(lambda (x)
(when (probe-file
(merge-pathnames "asd-library.asd" (eval x)))
(eval x)))
asdf:*central-registry*)))

Both codes perform the same task. The first one is more like a procedural/imperative code in style than the more functional second one.

By the way, they return the path for a registered library. It is not very useful since ADSF provides the same thing easily with a single function call:

(asdf:system-relative-pathname :asd-library "")

But I like to get back to it as a reference of lisp styles.

Tuesday, May 19, 2009

Outside-in

I am trying to read OnLisp by Paul Graham again and I really liked the turn your imperative code outside-in in chapter 3.

This is almost a reminder to myself.

Let's say I have an imperative function:
(defun imp-fn (x)
(let ((a 2) result)
(setf result (+ x a))
result)

I have seen a lot of code like that.

Turning it outside-in:
1) It returns result what is result?
we can replace it by the expression: (+ x a)
2) what is a?
we can replace it by its expression: (+ x 2)
3) then the result is:
(defun not-so-imp (x)
(+ x 2))

This is a very simple example but the idea remains the same. The OnLisp book has another example which is better than this one, but this one is good enough to show off the idea.

Thursday, May 8, 2008

Books on LISP

Getting back to the subject of what books should I read if I want to learn LISP. Now I have a better improved list I feel it will make the transition from anywhere to LISP easier.

In the order I would suggest a friend to start:

1) A funny warm up of how fun it is to LISP.
2) The beginning of the beginnings (even if not a programmer):
3) Still on beginning but a day after:
4) Getting practical:
5) Getting deep:

Good reading!

Tuesday, March 25, 2008

Weblocks first impressions

On a previous post I was commenting on how easy it was to prototype a domain model in lisp. This happens primarily due to its REPL (read-eval-print-loop) way of programming.

A few days ago I started playing with weblocks which is, as it is referred on its website, "A continuations-based common lisp web framework". The shift of paradigm from page-centric development to something different at first sounded just like something interesting to learn about. Because of that, I tried it a couple of months ago, without much success, trying to replace a league management system I built using only hunchentoot by itself.

Today, with a little bit more experience in lisp I could manage to build a simple prototype with some of the entities of a domain model I was working on. The results were really impressive, primarily due to the straight forward approach to get the presentation done.

At first, the whole composite widget centric approach seems overwhelming but at some point it sinks in and we can see how easy it is to "compose" the web user interface for an application using weblocks without having to think about pages and getting data back and forth from the web session.

Despite the fact that it is still a work in progress, I really liked the feeling of working on a web application and not having to deal with html or ajax to get a nice presentation in minutes. (In my case, one hour, because I had no clue how to use it...)

Anyway, personally I really like building software without having to work on the UI manually. Auto-generation based on the model or on view definitions seems to be the more productive approach to deliver enterprise based applications. I wish one day we could have weblocks and cells-gtk, for example working against the same view abstraction and being able to generate desktop and web user interfaces in a seamless way.

Monday, February 25, 2008

Lisp project template with Emacs

In my first post I was describing the environment I had to use Lisp. After a few issues, usually related to the fact that Eclipse is really a memory hungry application. I moved back to the Emacs + Slime combination. The only difference from what I used to do prior using cusp is that now I work with a "project" file, just the way eclipse + cusp does. I like the idea of working with an asd file to define the files and dependencies in my project and it is very effective to load and compile all lisp files from my project and start being productive right away.

In order to get there I created this symbolic link on my .sbcl/system folder to point to my asd file.

By doing this you are able to load your project using asdf.

Saturday, November 3, 2007

What tools I use to LISP

I started to study LISP a while ago and after all this months I am no more than a real beginner, however every time I use LISP I enjoy every piece of code written.

If you want to be easily up and running using LISP and are used to an IDE like I was. I recommend using CUSP with Eclipse. It is very good in terms of productivity and easy to install. Check out this link that teaches step by step how to install it on your system.

How to Install and use CUSP on Eclipse

By the way I use Ubuntu Linux 7.04 hopefully upgrading by the end of the month to the new 7.10.

The LISP implementation I use is SBCL. Make sure you have a link to its manual

I started studying the book Practical Lisp, but couldn't finish the book. The examples at the end weren't appealing to me so I switched to On Lisp which is too deep to me as a beginner and finally to Successful Lisp. In my opinion they are all good books, Successful Lisp and Practical Lisp being the best beginner's books. I hope I will be able to get back to On Lisp when I get more experienced.