To us, here and now, it appears thus.

rants, ramblings and other things that make life worth living…

Tiny Lisp course – Lisp in 10 bullets.

with 6 comments

With my final year project coming up and with my decision to use Common Lisp for the project for both the compiler and the virtual machine, I had to give my friend and project mate venky a simple introduction to get him to the proficiency of reading and understanding lisp code. So I devised this ” Lisp in 10 bullets” so that we can get him to start hacking around common lisp.

Since we are using both scheme and common lisp in the project, this 10 bullets had to be general to include both the popular dialects. Also, since he is not a complete newbie to programming (he’s a decent javascript/C/C++ programmer), I don’t have the need to explain things like what an ‘if’ does or what a list is. So here is the list.

  1. In Lisp everything thats written is called a s-expression, which are basically of 2 types. Atoms and Forms.
  2. Atoms are stuff like numbers (10, 234.56, etc..), characters , strings, boolean literals like T (true) and NIL (false) and variable names (called symbols in Lisp, which are associated with other values).
  3. Forms, the 2nd type of s-expressions are always enclosed within paranthesis.
  4. Lisp works by evaluating the s-expression and printing the output, which is the value of the s-expression. Each s-expression’s value depends on what it is (atom/form) and what type of an atom or a form it is. The process of finding the value of an s-expression is called evaluation.
  5. Literals (atoms like 12, #\a , “Hey”, etc.. basically numbers, chars and strings) evaluate to themselves, i.e 10 evaluates to the number 10. Atoms like symbols evaluate to the value that they are associated to.
  6. Forms are of two types – Functional application and Special forms. And they are always enclosed within paranthesis (this is just rule 3 again, but to drive home the point!)
  7. Special forms are written as (special-form-name arg1 arg2 arg3 arg4 … argN) and special forms dictates how and when (even wether) each of arg1 to argN is evaluated. Functional Application is simpler, even though written in the same manner as (function-name arg1 arg2… argN), it works by evaluating all the values from arg1 to argN first and then passing them to the function ‘function-name’.
  8. Functions in lisp are a bit different and there is a 2 step process to work with them. First the action of creating a function which is done using the lambda special form and then process of associating the function with a name. (i.e, its upto you to assign functions a name, you can leave it if you don’t need it).
  9. Lisp has a data structure called the list, whose written literal representation is indistinguishable from that of forms. Its enclosed within paranthesis and its elements seperated by whitespaces. So basically you can see any lisp program as a bunch of atoms (which are data anyway) and lists. This means that lisp code and lisp data are indistinguishable.
  10. Since code is indistinguishable from data, you can write programs to change/generate code because its basically working by modifying lists. Since Lisp provides you with an eval function you can evaluate your generated code at runtime, and Lispniks call this feature ‘Macros’.

Hmm, thats my simple 10 bullet guide to lisp, hope it was helpful to all those readers who are interested.

Update 1: As far as point 10 goes, thats not what Lispniks call macros, Macros are simply programs which change/generate code, but this happens during compile time. (however the point is still valid, you can evaluate your code at runtime using eval.)

Signing Off,
Vishnu Vyas

Advertisements

Written by vishnuvyas

October 16, 2005 at 10:41 pm

6 Responses

Subscribe to comments with RSS.

  1. Well, thanks for taking efforts in teaching me LISP in such a short time and inducing interest in LISP programming. It is good to see you share around your didactic skills to the blogging world.(Although, I’m not a decent javascript programmer!:)).

    I never felt like I was Joey and you were Phoebe while you were teaching LISP 😀 ….

    To Everyone: Must read for LISP starters.

    Cyz

    - Intercodes

    October 17, 2005 at 12:50 am

  2. Just a quibble with point 2. Symbols are not just variable names, and calling them such loses some of what makes lisp so unique and strange. It would be more accurate to say that symbols are just that, symbols, which can be bound to values.

    Anonymous

    February 18, 2006 at 6:29 pm

  3. Hello anonymous,

    Totally agreed.
    Yeah, i know they aren’t, but its easier for newbies who aren’t used to what symbols to first identify with variable names in the begining, this is just a small tutorial after all.

    vishnuvyas

    February 19, 2006 at 4:08 pm

  4. Suchi Yeukie like to post for you about bad credit repair mortgage loan fix repair credit bankruptcy foreclosure equity equifax experian transunion dispute May be you have bad credit. If do then try site today 🙂

    Suchi Yeukie

    May 7, 2006 at 12:38 am

  5. […] read more | digg story […]

  6. bad credits can happen at any point in your life so be prepared to always get some extra income -;”

    Migraine Relief

    November 22, 2010 at 2:49 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: