Beginning LISP Programming in Ubuntu

For any reason, you may wanted to start learning Lisp Programming. However, you may wondering where to start. So here again, I'm going to share with you. How to begin Lisp Programming, "the programmable programming language".




As, I'm using Ubuntu here, this example is shown step by step on Ubuntu.



In order to start playing with Lisp on your ubuntu, you need to install CMUCL. CMUCL is a free implementation of Common Lisp which was originally developed at Carnegie Mellon University. To install CMUCL package, just run this command on your Ubuntu terminal:





$ sudo apt-get install cmucl                                                   

Next, we are going to feel the environment. Open up your terminal and type:





$ lisp                                                                       

You will be greeted by CMU Common Lisp with it version and loaded subsystem. In my case, I see like this.





dakc@dakc-ubuntu:~$ lisp 
                                                                                          
CMU Common Lisp CVS release-19a 19a-release-20040728 + minimal debian patc 
   
hes, running on dakc e-ubuntu  
                                                                                      
With core: /usr/lib/cmucl/lisp.core  
                                                                                
Dumped on: Fri, 2009-11-13 09:05:47+08:00 on dakc-ubuntu   
                                   
For support see http://www.cons.org/cmucl/support.html Send bug reports to
                
 the debian BTS.  
                                                                                                       
or to pvaneynd@debian.org  
                                                                                      
type (help) for help, (quit) to exit, and (demo) to see the demos     

                                                                                                                                                                                       
Loaded subsystems:    
                                                                                              
 Python 1.1, target Intel x86   
                                                                                   
 CLOS based on Gerd's PCL 2004/04/14 03:32:47                                                 
*                                                                                                                              

As you can see the loaded subsystem is Python 1.1. This is not the Python as in Python Programming. Don't get confused. It is a native code compiler named "Python". If Common Lisp source code has been written with appropriate declarations and is organized with speed in mind, the Python compiler generates code that is almost free from overhead compared to code compiled from languages like C++. Some inefficiencies such as function call interfaces and lack of pointer-free arrays of user-defined data types are dictated by the Common Lisp standard and still need to be worked around (e.g. by inlining more and using macros to build constructs that look like user-defined structures but are actually accessing fields in preallocated specialized arrays). The Python compiler also features powerful type inferences, helping the programmer in writing overhead-free code by either inferring types automatically or issuing hints about missed optimization opportunities.



Before doing anything else, you have to know how to exit from this environment. To exit from this lisp terminal, you can simply type (quit) and press enter.





dakc@dakc-ubuntu:~$ lisp
CMU Common Lisp CVS release-19a 19a-release-20040728 + minimal debian patc
hes, running on dakc-ubuntu
With core: /usr/lib/cmucl/lisp.core
Dumped on: Fri, 2009-11-13 09:05:47+08:00 on dakc-ubuntu
For support see http://www.cons.org/cmucl/support.html Send bug reports to
 the debian BTS.
or to pvaneynd@debian.org
type (help) for help, (quit) to exit, and (demo) to see the demos

Loaded subsystems:
Python 1.1, target Intel x86
 CLOS based on Gerd's PCL 2004/04/14 03:32:47
* (quit)dakc@adakc-ubuntu:~$

Now you know how to start and end the CMU Common Lisp. We can start playing with codes. Here is some example:



1. Adding Numbers:





* (+ 200 800 300 700 19 10)
2029
*

Notice my code started with '(' and end with ')'.



2. Subtract Numbers:





* (* 12 2 3)
72



3. Or even Adding and Subtract:





* (+ (* 12 2 3) 1)
73



There you go. From here you can try more stuff by following these tutorials and manual:




•Lisp Tutorial: Basic Lisp Programming

•An Introduction and Tutorial for Common Lisp

•Practical Common Lisp

•Xah's Emacs Lisp Tutorial

CMUCL User's Manual

0 comments: